Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive updates on table fields #2733

Closed
iwahbe opened this issue Apr 19, 2024 · 5 comments
Closed

False positive updates on table fields #2733

iwahbe opened this issue Apr 19, 2024 · 5 comments
Labels
bug Used to mark issues with provider's incorrect behavior resource:table Issue connected to the snowflake_table resource

Comments

@iwahbe
Copy link

iwahbe commented Apr 19, 2024

Terraform CLI and Provider Versions

Terraform v1.8.1
on darwin_arm64

  • provider registry.terraform.io/snowflake-labs/snowflake v0.89.0

Terraform Configuration

terraform {
  required_providers {
    snowflake = {
      source  = "Snowflake-Labs/snowflake"
      version = ">= 0.1"
    }
  }

  required_version = ">= 1.2.0"
}

provider "snowflake" {}

resource "snowflake_database" "simple" {
  name    = "testing"
  comment = "test comment"
}


resource "snowflake_schema" "schema" {
  database            = snowflake_database.simple.name
  name                = "schema"
  data_retention_days = 1
}

resource "snowflake_sequence" "sequence" {
  database = snowflake_schema.schema.database
  schema   = snowflake_schema.schema.name
  name     = "sequence"
}

resource "snowflake_table" "table" {
  database                    = snowflake_schema.schema.database
  schema                      = snowflake_schema.schema.name
  name                        = "table"
  comment                     = "A table."
  cluster_by                  = ["to_date(DATE)"]
  data_retention_time_in_days = snowflake_schema.schema.data_retention_days
  change_tracking             = false

  column {
    name     = "id"
    type     = "int"
    nullable = true

    default {
      sequence = snowflake_sequence.sequence.fully_qualified_name
    }
  }

  column {
    name = "identity"
    type = "int"
    # type  = "NUMBER(38,0)" # Should be equivalent
    nullable = true

    identity {
      start_num = 1
      step_num  = 3
    }
  }

  column {
    name = "MY_STRING"
    type = "VARCHAR(16777216)"
    # type = "STRING" # Should be equivalent
  }

  column {
    name = "DATE"
    type = "TIMESTAMP_NTZ"
    # type = "TIMESTAMP_NTZ(9)" # Should be equivalent
  }

  column {
    name = "DATE2"
    type = "DATETIME"
    # type = "TIMESTAMP_NTZ" # Equivalent to TIMESTAMP_NTZ
  }

  primary_key {
    name = "my_key"
    keys = ["data"]
  }
}

Expected Behavior

I expect that when I run terraform apply, type "yes" and then run terraform apply again, there are no diffs. I expect that when I change a type to a semantically equivalent type there will be no diff.

Actual Behavior

When I run terraform apply on a newly created DB, I get this:

𝛌 terraform apply
snowflake_database.simple: Refreshing state... [id=testing]
snowflake_schema.schema: Refreshing state... [id=testing|schema]
snowflake_sequence.sequence: Refreshing state... [id=testing|schema|sequence]
snowflake_table.table: Refreshing state... [id=testing|schema|table]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # snowflake_table.table will be updated in-place
  ~ resource "snowflake_table" "table" {
        id                          = "testing|schema|table"
        name                        = "table"
        # (8 unchanged attributes hidden)

      ~ column {
            name           = "id"
          ~ type           = "NUMBER(38,0)" -> "int"
            # (4 unchanged attributes hidden)

            # (1 unchanged block hidden)
        }
      ~ column {
            name           = "identity"
          ~ type           = "NUMBER(38,0)" -> "int"
            # (4 unchanged attributes hidden)

            # (1 unchanged block hidden)
        }
      ~ column {
            name           = "DATE"
          ~ type           = "TIMESTAMP_NTZ(9)" -> "TIMESTAMP_NTZ"
            # (4 unchanged attributes hidden)
        }
      ~ column {
            name           = "DATE2"
          ~ type           = "TIMESTAMP_NTZ(9)" -> "DATETIME"
            # (4 unchanged attributes hidden)
        }

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
╷
│ Warning: Argument is deprecated
│ 
│   with provider["registry.terraform.io/snowflake-labs/snowflake"],
│   on main.tf line 21, in provider "snowflake":
│   21: provider "snowflake" {}
│ 
│ Specify the region as part of the account parameter
│ 
│ (and 2 more similar warnings elsewhere)
╵

Steps to Reproduce

  1. terraform apply
  2. terraform apply again to see the diff

How much impact is this issue causing?

Medium

Logs

https://gist.github.com/iwahbe/4a5feacb7be90ec0d827a44b54de4cf0

Additional Information

There is already some code to normalize these values: https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/a70d1afc607c5e9501762448a96a11c22efca3d4/pkg/resources/table.go#L64C2-L64C3

The bug was originally discovered in Pulumi as pulumi/pulumi-snowflake#572.

@iwahbe iwahbe added the bug Used to mark issues with provider's incorrect behavior label Apr 19, 2024
@sfc-gh-asawicki
Copy link
Collaborator

Hey @iwahbe. Thanks for reaching out to us.

I will try to reproduce it this week and I will get back to you.

sfc-gh-asawicki added a commit that referenced this issue May 6, 2024
It will be addressed in detail as part of table rework

References: #2733
@sfc-gh-asawicki
Copy link
Collaborator

Hey @iwahbe. I have added a diff suppression for data types. After merging it should be a part of the next release.

It will still be subject to change as part of table rework in https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#preparing-essential-ga-objects-for-the-provider-v1 but should work for the time being.

sfc-gh-asawicki added a commit that referenced this issue May 7, 2024
- Add missing parameters (References #2676)
- Temporary fix the warehouse resource behavior; it will be addressed
with the warehouse redesign because the existing conditional logic is
questionable and we plan to get rid of the defaults (SNOW-1348102)
(References #2763)
- Prove data type problem with functions; it will be addressed with
function redesign because it requires deeper refactor (SNOW-1348103)
(References #2735)
- Suppress the diff for synonym columns in table resource; it will be
addressed with table redesign because the collate test had to be skipped
(SNOW-1348114) (References #2733)
sfc-gh-jcieslak pushed a commit that referenced this issue May 8, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.90.0](v0.89.0...v0.90.0)
(2024-05-08)


### 🎉 **What's new:**

* Adjust owner_role_type and schema_evolution_record columns
([#2740](#2740))
([424e393](424e393))


### 🔧 **Misc**

* Add a guide on creating issues
([#2758](#2758))
([2b006aa](2b006aa))
* Add missing documentation
([#2781](#2781))
([cc0a6a7](cc0a6a7))
* Add scripts to close issues from Pre Snowflake bucket
([#2762](#2762))
([44c0c37](44c0c37))
* Add small adjustments
([#2783](#2783))
([e5b0b4b](e5b0b4b))
* Adjust issue templates
([#2748](#2748))
([64ab76d](64ab76d))
* Cleanup helpers part 3
([#2730](#2730))
([eb7bee4](eb7bee4))
* Cleanup helpers part 5
([#2744](#2744))
([1f165bf](1f165bf))
* Cleanup helpers part4
([#2741](#2741))
([9475e35](9475e35))
* Cleanup helpers part6
([#2745](#2745))
([eba3029](eba3029))
* Cleanup helpers poc
([#2724](#2724))
([70b99fb](70b99fb))
* Helpers cleanup continuation
([#2726](#2726))
([a70d1af](a70d1af))
* Prepare new roadmap entry
([#2773](#2773))
([b0bf28f](b0bf28f))
* Prepare parallel builds
([#2737](#2737))
([6974e25](6974e25))
* Update the contribution guidelines (and small fixes)
([#2753](#2753))
([aafdc72](aafdc72))


### 🐛 **Bug fixes:**

* Fix issue templates
([#2760](#2760))
([d0d5048](d0d5048))
* Fix setup for two tests
([#2757](#2757))
([df025b0](df025b0))
* Fix Test (wrong order of arguments)
([#2780](#2780))
([02f467e](02f467e))
* Fix/prove issues
[#2733](#2733)
[#2735](#2735)
[#2763](#2763)
[#2767](#2767)
([#2777](#2777))
([7b1c67e](7b1c67e))
* Prove problems with procedure resource data types
([#2782](#2782))
([68d0318](68d0318))
* read after create
([#2718](#2718))
([2e9b68f](2e9b68f))
* UNSET and empty SET in network policies
([#2759](#2759))
([3eacb0b](3eacb0b))
* unset network policy should not have single quotes
([#2584](#2584))
([8f2a363](8f2a363))
* Update failover group allowed integration types
([#2776](#2776))
([efde48d](efde48d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: snowflake-release-please[bot] <105954990+snowflake-release-please[bot]@users.noreply.github.com>
@iwahbe
Copy link
Author

iwahbe commented May 9, 2024

Thanks for getting to this @sfc-gh-asawicki! I appreciate it.

@sfc-gh-jcieslak
Copy link
Collaborator

Hey @iwahbe 👋
Could you confirm that the newly released version fixed your issue? If it did, please close the ticket. Thanks!

@iwahbe
Copy link
Author

iwahbe commented May 10, 2024

Looks fixed to me.

@iwahbe iwahbe closed this as completed May 10, 2024
@sfc-gh-asawicki sfc-gh-asawicki added the resource:table Issue connected to the snowflake_table resource label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior resource:table Issue connected to the snowflake_table resource
Projects
None yet
Development

No branches or pull requests

3 participants