Snowflake-Labs / terraform-provider-snowflake

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

`snowflake_object_parameter` conflicts with deprecated table `data_retention_days` #1457

Open jagoodhand opened 1 year ago

jagoodhand commented 1 year ago

Provider Version

0.54

Terraform Version

Terraform v1.3.7
on darwin_arm64
+ provider registry.terraform.io/snowflake-labs/snowflake v0.54.0

Describe the bug

snowflake_object_parameter conflicts with the deprecated table data_retention_days property.

  1. snowflake_object_parameter used to set the DATA_RETENTION_TIME_IN_DAYS property on a table to e.g. 31
  2. First 'apply' deployment deploys a table with a data retention time of 31 days
  3. Second 'apply' deployment changes the data retention time to the default of 1 days
  4. Third 'apply' deployment changes the data retention time to the value of 31 days

Flip-flopping between the two values then continues for each subsequent deployment.

Expected behavior

DATA_RETENTION_TIME_IN_DAYS provided by the snowflake_object_parameter resource sets the data retention time for the table to 31 days. No further updates on each 'apply' should occur.

Code samples and commands

Object definitions:

resource "snowflake_database" "play" {
    name = var.playground_db_name
}

resource "snowflake_schema" "administration" {
    depends_on = [
      snowflake_database.play
    ]

    database = "${snowflake_database.play.name}"
    name = var.playground_admin_schema_name

    is_transient = false
    is_managed = true
}

resource "snowflake_table" "log_table" {
    depends_on = [
        snowflake_view.object_tags
    ]

    database = "${snowflake_database.play.name}"
    schema = "${snowflake_schema.administration.name}"
    name = "LOG"

    change_tracking = true

    column {
        name = "event_time"
        type = "TIMESTAMP_TZ(9)"
        nullable = false
    }

    column {
        name = "record"
        type = "VARIANT"
    }
}

resource "snowflake_object_parameter" "log_table_data_retention" {
    depends_on = [
        snowflake_table.log_table
    ]

    object_identifier {
        database = "${snowflake_database.play.name}"
        schema = "${snowflake_schema.administration.name}"
        name = "${snowflake_table.log_table.name}"
    }

    key = "DATA_RETENTION_TIME_IN_DAYS"
    value = "31"
    object_type = "TABLE"
}

Run 2 - after initially deployment

  # snowflake_table.log_table will be updated in-place
  ~ resource "snowflake_table" "log_table" {
      ~ data_retention_days = 31 -> 1
        id                  = "PLAY|ADMINISTRATION|LOG"
        name                = "LOG"
        # (5 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

Run 3

  # snowflake_object_parameter.log_table_data_retention will be updated in-place
  ~ resource "snowflake_object_parameter" "log_table_data_retention" {
        id          = "DATA_RETENTION_TIME_IN_DAYS*TABLE*\"PLAY\".\"ADMINISTRATION\".\"LOG\""
      ~ value       = "1" -> "31"
        # (2 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Run 4

  # snowflake_table.log_table will be updated in-place
  ~ resource "snowflake_table" "log_table" {
      ~ data_retention_days = 31 -> 1
        id                  = "PLAY|ADMINISTRATION|LOG"
        name                = "LOG"
        # (5 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

Additional context

n/a

jagoodhand commented 1 year ago

There is a similar bug where Terraform keeps trying to update the 'Allowed Values' parameter of a tag with no restrictions on values to an empty list on each run.

rjoelnorgren commented 1 year ago

Also encountering this issue. Ooc, why does the provider not honor the database/schema level default? This is a somewhat confusing behavior.