terraform-provider-snowflake icon indicating copy to clipboard operation
terraform-provider-snowflake copied to clipboard

Parsing error of cluster_by value containing an expression

Open buwi opened this issue 2 years ago • 4 comments

Provider Version

0.72.0

Terraform Version

v1.5.2

Describe the bug

I am using Terragrunt to manage state in AWS S3. It appears, the Snowflake provider is parsing the cluster_by value in the wrong place when it contains an expression.

For a table definition:

resource "snowflake_table" "sample-table" {
  database        = snowflake_schema.mydb-my_schema.database
  schema          = snowflake_schema.mydb-my_schema.name
  name              = local.sample-table_name
  cluster_by      = ["date_trunc('HOUR',TIMESTAMP_HR)","CLIENT_ID"]
  comment        = "..."
  change_tracking = false

  column {
    name     = "CLIENT_ID"
    type     = "VARCHAR(16777216)"
  }
  
  column {
    name     = "TIMESTAMP_HR"
    type     = "TIMESTAMP_TZ(9)"
  }
  
...

The initial run of terraform created the table successfully, with the correct cluster_by definition.

CLUSTERING_KEY: LINEAR(date_trunc('HOUR', TIMESTAMP_HR), CLIENT_ID)

But the state file contained the cluster_by as follows:

            "cluster_by": [
              "date_trunc('HOUR'",
              "TIMESTAMP_HR)",
              "CLIENT_ID"
            ],

On a subsequent run of Terraform, the cluster_by was identified as a change.

  
  Terraform will perform the following actions:

  # snowflake_table.sample-table will be updated in-place
  ~ resource "snowflake_table" "sample-table" {
      ~ cluster_by      = [
          - "date_trunc('HOUR'",
          - "TIMESTAMP_HR)",
          + "date_trunc('HOUR',TIMESTAMP_HR)",
            "CLIENT_ID",
        ]
        id              = "MYDB|MY_SCHEMA|MY_TABLE"
        name            = "MY_TABLE"
        # (6 unchanged attributes hidden)

        # (36 unchanged blocks hidden)
    }

Expected behavior

The state file should store the cluster_by definition as follows.

            "cluster_by": [
              "date_trunc('HOUR',TIMESTAMP_HR)",
              "CLIENT_ID"
            ],

Code samples and commands

Additional context

sample-table_name  ="MY_TABLE"

buwi avatar Oct 10 '23 18:10 buwi

same issue here, it seems ClusterStatementToList just splits on ',' - with this issue the table object is not usable

meinczinger avatar Oct 27 '23 12:10 meinczinger

Same here it misinterprets all values with a space inside:

 ~ cluster_by          = [
      - "left(data:session_id",
      - "4)",
      + "left(data:session_id, 4)",
    ]


  ~ cluster_by          = [
        "data:device_info:vehicle_id::varchar",
      - "date_trunc('month'",
      - "data:observed_at::timestamp_ltz(3))",
      + "date_trunc('month', data:observed_at::timestamp_ltz(3))",
    ]

WojtekWaga avatar Nov 28 '23 08:11 WojtekWaga

Related issue : https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2495

buwi avatar Feb 21 '24 15:02 buwi

Hey @buwi @meinczinger @WojtekWaga. We have released the fix as part of v0.87.0 release. Please follow the migration guide during the update. Please confirm that the issue is resolved in the newest version. Thanks!

sfc-gh-asawicki avatar Feb 28 '24 14:02 sfc-gh-asawicki

Closing as completed.

sfc-gh-asawicki avatar Apr 26 '24 13:04 sfc-gh-asawicki