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

Schema scan for snowflake views with same names in single database produce wrong state file and cyclic changes

Open JESCHO99 opened this issue 1 year ago • 4 comments

Terraform CLI and Provider Versions

Terraform CLI = 1.5.0 Snowflake Provider = 0.85.0

Terraform Configuration

resource "snowflake_database" "this" {
  name                        = "SCHEMA_ISSUE_TEST"
  data_retention_time_in_days = 1
}

resource "snowflake_schema" "test_az" {
  database = snowflake_database.this.name
  name     = "TEST_SCHEMA_AZ"
  data_retention_days = 1
}

resource "snowflake_schema" "test_bz" {
  database = snowflake_database.this.name
  name     = "TEST_SCHEMA_BZ"
  data_retention_days = 1
}

resource "snowflake_view" "a" {

  database = snowflake_database.this.name
  schema   = snowflake_schema.test_az.name
  name     = "TEST_TABLE"

  statement =  <<-SQL
    select 1 as A from dual
SQL

  or_replace = true
  is_secure  = false
}

resource "snowflake_view" "b" {

  database = snowflake_database.this.name
  schema   = snowflake_schema.test_bz.name
  name     = "TEST_TABLE"

  statement =  <<-SQL
    select 1 as A from dual
SQL

  or_replace = true
  is_secure  = false
}

Expected Behavior

Two views are created inside Snowflake and the next Plan will show no further applies. Schema references are handled correctly even if there are views with the same name in one database in different schemas.

Actual Behavior

image

Even if the correct schema is mentioned in the state file terraform thinks that the view "b" is in the a-schema because of a failure during the Snowflake Metadata Scan. I tested the same terraform code in version 0.84.1 and there the scan of the views is currently still correct. Here you can see the changes in the Snowflake Query History.

Correct version 0.84.1: MicrosoftTeams-image

Wrong version 0.85.0: MicrosoftTeams-image (1)

Steps to Reproduce

  1. terraform apply
  2. terraform apply

How much impact is this issue causing?

High

Logs

No response

Additional Information

Please provide a rough estimation when this behaviour will be changed because it makes the version 0.85.0 unusable for our envrionemnts.

JESCHO99 avatar Feb 15 '24 08:02 JESCHO99

Hey @JESCHO99. Thanks for reaching out to us.

We are aware that some resources behave this way and we have this fix planned for all affected resources in the upcoming weeks. I will solve the Views one now, so there's a high probability it will be released with today's release.

sfc-gh-asawicki avatar Feb 15 '24 09:02 sfc-gh-asawicki

@sfc-gh-asawicki thanks for your fast reply. But I wonder why we were not able to find this issue in the issue list of the GitHub Repo for the 0.85.0 version. If you are aware of this behaviour which has effect on basic ressources like views could you try to make this visible in the repository? Because the anaylsis of this issues when upgrading the versions of the provider took us quite some time. If you make this visible we would know where to pay attention.

JESCHO99 avatar Feb 15 '24 10:02 JESCHO99

@JESCHO99 Currently, the issues visible on GH are the issues created by the community only. We have a much longer internal backlog, that is not yet shared through GH. We are slowly progressing with improving the transparency and visibility; that's why we shared recently our high-level roadmap (https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#our-roadmap), state of the SDK rewrite in the README, etc.

I agree with you, though, that bigger known issues should be listed on the repository level (and in the official docs) and we have that as one of the items planned for the next weeks.

sfc-gh-asawicki avatar Feb 15 '24 11:02 sfc-gh-asawicki

@JESCHO99 we released the fix as part of 0.86.0 release. Could you please check if this solves the issue for you?

sfc-gh-asawicki avatar Feb 16 '24 07:02 sfc-gh-asawicki

Closing the issue. Please create a new one if the issue persists in the newest provider version.

sfc-gh-asawicki avatar Mar 13 '24 13:03 sfc-gh-asawicki