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

Avoid table replacement with the changing of schema name #1146

Open
andreqaugusto opened this issue Jul 19, 2022 · 0 comments
Open

Avoid table replacement with the changing of schema name #1146

andreqaugusto opened this issue Jul 19, 2022 · 0 comments
Labels
category:resource feature-request Used to mark issues with provider's missing functionalities resource:table Issue connected to the snowflake_table resource

Comments

@andreqaugusto
Copy link

andreqaugusto commented Jul 19, 2022

Minimal Example Code:

resource "snowflake_database" "my_db" {
  name = "my_db"
}

resource "snowflake_schema" "my_schema" {
  database = "my_db"
  name     = "FOO"
  comment  = "My FOO schema"
}

resource "snowflake_table" "my_table" {
  database =  "my_db"
  schema   = snowflake_schema.my_schema.name
  name     = "PEOPLE"
  comment  = "The people table"
  column {
    name    = "NAME"
    type    = "VARCHAR"
  }
}

Corresponding resources:

Sample Data

Changing the snowflake_schema.my_schema name from FOO to something else (e.g. BAR) will destroy the current table and create a new one (a forced replacement).

Changing the Schema name

And the table will lose all data:

Result after schema change

This is obviously not ideal, especially because Snowflake allows you to change a Schema name without losing the table data. In other words, if I wasn't tracking the PEOPLE table with terraform, I wouldn't lose any data and the table would gracefully live in the BAR schema as desired.

Note that you can actually bypass this issue with the following steps (that is what I did when faced with such scenario):

  1. use terraform state rm snowflake_table.my_table to remove the tracked my_table
  2. change the my_schema name to what you desire (e.g. from FOO to BAR)
  3. use terraform import snowflake_table.my_table MY_DB|BAR|PEOPLE to import the table with all of our data in the new schema.

Obviously the steps above are not ideal (since we are messing with the state, which is always not recommended). The solution I'd like involves doing the above behind the scenes. I don't know if that is possible, but I suspect to be so (since, like I said before, Snowflake allows you to change schema names without any table replacement).

@andreqaugusto andreqaugusto added the feature-request Used to mark issues with provider's missing functionalities label Jul 19, 2022
@andreqaugusto andreqaugusto changed the title Avoid table replacement with the changing of schema naming Avoid table replacement with the changing of schema name Jul 19, 2022
@sfc-gh-jcieslak sfc-gh-jcieslak added category:resource resource:table Issue connected to the snowflake_table resource labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:resource feature-request Used to mark issues with provider's missing functionalities resource:table Issue connected to the snowflake_table resource
Projects
None yet
Development

No branches or pull requests

2 participants