Snowflake-Labs / terraform-provider-snowflake

Terraform provider for managing Snowflake accounts
https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest
MIT License
530 stars 413 forks source link

data_retention_time_in_days as snowflake_object_parameter #1561

Open vtseng-agillitics opened 1 year ago

vtseng-agillitics commented 1 year ago

Provider Version

v0.56.5

Terraform Version

1.3.9

Describe the bug

The documentation says that the data_retention_days argument is deprecated for Snowflake tables. When I use the data_retention_days argument under a table resource, Terraform tells me to use the snowflake_object_parameter resource instead. I used the snowflake_object_parameter resource, using "DATA_RETENTION_TIME_IN_DAYS" as the key. I set the value to 7. When I initially apply the table and object parameter, the data retention time for the table is correct. However, if I update the table on the next apply, the table's data retention time reverts back to 1 day, the default value for Snowflake time travel.

Expected behavior

When I initially apply the table and object parameter, the data retention time for the table is 7. If I update the table on future applies, the data retention time should stay 7 days, not revert back to 1 day.

Code samples and commands

https://github.com/AgilliticsLLC/Terraform_Bug

  1. terraform init
  2. terraform apply
  3. Change the DESCRIPTION column's type to be VARCHAR(10) on table_and_object_parameter.tf.
  4. terraform apply

Additional context

I opened an issue on Terraform's repo, and they redirected me to this repo. https://github.com/hashicorp/terraform/issues/32713

lepagea01 commented 1 year ago

Just to add to this ticket.

At first, the table data retention time in Snowflake will be as per the value set by the corresponding snowflake_object_parameter resource but the data_retention_days property of the snowflake_table resource will be set to 1 (in the state file), the default. At that point, subsequent executions of terraform apply, with or without changes in the configuration, will set the data retention time back to 1 in Snowflake since the snowflake_table resource is (now) configured as such. Obviously, the snowflake_object_parameter resource is then ignored (because respective entries in configuration and state file match?).

I suspect the same scenario repeats with other object parameters but I did not investigate any further.

james-welly commented 1 year ago

Can confirm I am also experiencing this same issue where tables are flip flopping between retention periods. Clear mismatch between the value set in the object parameter and what is listed against the table itself in the state file.

james-welly commented 1 year ago

I wonder if this to only do with objects that were in place at time of the change to object parameters. Looking at the state file pre upgrade the table objects had the retention period set to 30 days in the terraform code and this was reflected in the state file. When upgrading the plan showed the removal of the retention period on the table object and then the addition of the object parameter separately. When applied, the removal of the parameter on the table object occurred first and then after the addition of the object parameter resource.

I wondered at this point, the state file table object got the default value of 1 for the previously set retention period parameter meaning there is these ongoing mismatch between this value and the object parameter resource, in out cases set to 30. If this is the case I guess a fix is to remove this parameter in the state file for each snowflake table object effected.