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

Snowflake objects created via terraform differs from "same" objects created via snowsight #2356

Closed
Petruspop opened this issue Jan 16, 2024 · 5 comments · Fixed by #2502
Closed
Assignees
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@Petruspop
Copy link

Terraform CLI and Provider Versions

Terraform 1.6.6
Snowflake-Labs/snowflake 0.83.1

Terraform Configuration

#Set the provider
terraform {
  required_providers {
    snowflake = {
      source = "Snowflake-Labs/snowflake"
      version = "0.83.1"
    }
  }
}

# Configure the Snowflake Provider
# pwd as env var, set snowflake_password=your-password-here
provider "snowflake" {
  account = "RUTERAS-CDPPETER"
  user = "TMPTF"
  role = "ACCOUNTADMIN"
}

# Create DB with data retention set
resource "snowflake_database" "database" {
  name = "data-retention-db"
  data_retention_time_in_days = 28
  comment = "Database created in tf with data retention 28"
}

# Create schema without paramater for data retention -> should inherit
resource "snowflake_schema" "schema" {
  database = snowflake_database.database.name
  name = "tfschema"
  comment = "Schema created in tf, no data retention parameter used/set"
}

# Create table without paramater for data retention -> should inherit
resource "snowflake_table" "table" {
  database = snowflake_database.database.name
  schema = snowflake_schema.schema.name
  name = "tftable"
  comment = "Table created in tf, no value for data retention parameter"
  column {
    name = "id"
    type = "int"
  }
  column {
    name = "textfield"
    type = "text"
  }
}

Expected Behavior

Data retention days on schema and table should be 28, as it should be inherited from database.

Actual Behavior

Data retention days is defaulted to 1, both for schema and table.

Steps to Reproduce

  1. terraform apply
  2. Check parameter on objects

How much impact is this issue causing?

High

Logs

No response

Additional Information

Marked this as High as you expect you have time travel for 28 days, but in fact only have 1 day. So you risk losing data which is really dangerous.

The following script can be used in Snowsight to verify the difference.

-- Verify TF defect
USE DATABASE "data-retention-db"; -- This was created in step 1 from tf provider

CREATE SCHEMA "uischema";

USE SCHEMA "uischema";

CREATE TABLE "uitable" (id int,textfield text) COMMENT ='Table created via snowsight, with no data retention parameter value';

SHOW PARAMETERS LIKE '%DATA_RETENTION%' IN DATABASE "data-retention-db";
--> 28 - as expected (from tf)

SHOW PARAMETERS LIKE '%DATA_RETENTION%' IN SCHEMA "uischema";
--> 28 - as expected, inherited from DB

SHOW PARAMETERS LIKE '%DATA_RETENTION%' IN SCHEMA "tfschema";
--> 1 - NOT as expected, should be the same as for the schema from Snowsight

SHOW PARAMETERS LIKE '%DATA_RETENTION%' IN TABLE "uitable";
--> 28 - as expected, inherited from DB->schema->table

USE SCHEMA "tfschema";
SHOW PARAMETERS LIKE '%DATA_RETENTION%' IN TABLE "tftable";
--> 1 - NOT as expected

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

Hey @Petruspop. Thanks for reporting the issue.

Based on the setup provided, the source of the error is probably using the default value from the resource schema. This should be a relatively easy fix; we will deliver it in a few days if my suspicions are confirmed.

@timgreni
Copy link

@sfc-gh-asawicki any update?

@sfc-gh-asawicki
Copy link
Collaborator

Hey @timgreni. No, the issue is still waiting on our end.

@sfc-gh-jcieslak sfc-gh-jcieslak self-assigned this Feb 9, 2024
@sfc-gh-jcieslak
Copy link
Collaborator

@Petruspop @timgreni working on the issue; should be fixed next week

sfc-gh-jcieslak added a commit that referenced this issue Feb 20, 2024
Fixes:
#2356
Database retention time won't be set in the Read operation every time to
avoid situations where Terraform expects the user to set it every time
(if it's not set then it will always produce a plan, because of the
Snowflake's data retention hierarchy).
It will only be set there only if:
- it's not set in config and schema data retention value != database
retention value
- it's set in the config

- acceptance tests added
@sfc-gh-jcieslak
Copy link
Collaborator

Hey @Petruspop @timgreni. 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!

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants