terraform-provider-snowflake
terraform-provider-snowflake copied to clipboard
Parsing error of cluster_by value containing an expression
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"
same issue here, it seems ClusterStatementToList just splits on ',' - with this issue the table object is not usable
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))",
]
Related issue : https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2495
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!
Closing as completed.