Snowflake-Labs / terraform-provider-snowflake

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

[Bug]: Not possible to rename stage - Running into a deadlock #2972

Open JESCHO99 opened 3 months ago

JESCHO99 commented 3 months ago

Terraform CLI Version

1.5.7

Terraform Provider Version

0.92.0

Terraform Configuration

provider "snowflake" {
  role  = "SYSADMIN"
}

terraform {
  required_version = "~> 1.5.0"
  required_providers {
    snowflake = {
      source  = "Snowflake-Labs/snowflake"
      version = "~> 0.92.0"
    }
  }
}

resource "snowflake_database" "this" {
  name = "LOCAL_TEST_DB"
}

resource "snowflake_schema" "this" {
  name     = "TESTING"
  database = snowflake_database.this.name
}

resource "snowflake_table" "table_v1" {
  database                    = snowflake_database.this.name
  schema                      = snowflake_schema.this.name
  name                        = "TEST_V1"
  change_tracking             = false

  column {
    name     = "ID"
    type     = "INTEGER"
  }

  column {
    name = "NAME"
    type = "VARCHAR(255)"
  }
}

resource "snowflake_table" "table_v2" {
  database                    = snowflake_database.this.name
  schema                      = snowflake_schema.this.name
  name                        = "TEST_V2"
  change_tracking             = false

  column {
    name     = "ID"
    type     = "INTEGER"
  }

  column {
    name = "NAME"
    type = "VARCHAR(255)"
  }
}

resource "snowflake_stage" "stage_v1" {
  name        = "TEST_V1"
  database    = snowflake_database.this.name
  schema      = snowflake_schema.this.name
}

resource "snowflake_stage" "stage_v2" {
  name        = "TEST_V2"
  database    = snowflake_database.this.name
  schema      = snowflake_schema.this.name
}

Category

category:resource

Object type(s)

resource:stage

Expected Behavior

When the provided terraform code is applied in Snowflake the Database, Schema, two tables and two named stages can be deployed successful. Everything is working as expected so far. Due to manual changes on Snowflake someone executed a rename command on one of the named stages: alter stage LOCAL_TEST_DB.TESTING.TEST_V1 rename to POST_TEST_V1;

When executing a terraform plan now in Terraform the expected behaviour would be that terraform recognizes that the defined stage no longer exists and will show a create stage in the produced plan. When this plan is executed terraform will create a new stage having the "old" name. In Snowflake there will be the renamed "old" stage and the newly created stage with the "old" name.

Actual Behavior

After a rename of an existing stage the provider runs into an error which does not longer allow for plan, apply or destroy commands. image image It seems that it is missing the behaviour that the provider can differ between a describe and a show objects like function. For example for tables the described process is working completely without errors.

Steps to Reproduce

  1. Terraform Apply with the provided code
  2. Manually Rename one of the stages inside of Snowflake with the rename command
  3. Try to execute terraform plan

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

No response

Would you like to implement a fix?

sfc-gh-asawicki commented 3 months ago

Hey @JESCHO99. Thanks for reaching out to us.

We plan to rework stages soon (https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/v1-preparations/ESSENTIAL_GA_OBJECTS.MD). However, this seems to be an easy fix, i.e. we have to handle this error conditionally like e.g. in the schemas (we are doing it for every resource we redesign).

I should be able to squeeze it in in next week's release (if I can prove that this is really the cause as expected).

sfc-gh-asawicki commented 2 months ago

Hey @JESCHO99. I have prepared a fix in https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/3020. It will be released as part of v0.95.0 today or tomorrow (we have to wrap a few other pull requests before making the release).

JESCHO99 commented 2 months ago

Hey @sfc-gh-asawicki, huge thanks for the quick fix!

sfc-gh-asawicki commented 2 months ago

Hey @JESCHO99, we had to postpone the v0.95.0 release to Monday, sorry for the inconvenience.

sfc-gh-asawicki commented 2 months ago

Hey @JESCHO99 . We have just released v0.95.0 of the provider. It contains a hotfix for this issue. Please check and let us know if it works for you.

sfc-gh-asawicki commented 3 weeks ago

Hey @JESCHO99. Did you check the fix? If so, can we close the issue?