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

`snowflake_role_grants` updates state to incorrect

Open sadahry opened this issue 3 years ago • 2 comments

Provider Version

0.33.1

Terraform Version

v1.1.9

Describe the bug

When trying to change the name of snowflake_role, snowflake_role_grants updates the terraform state to incorrect.

After the update, we cannot change the state anymore.

Expected behavior

updates snowflake_role_grants with no errors.

Code samples and commands

step1. run terrafom apply as below at first.

resource "snowflake_role" "test" {
  name    = "GRANTS_TEST"
}

resource "snowflake_role_grants" "test" {
  role_name = snowflake_role.test.name
  roles     = [
    "ACCOUNTADMIN"
  ]
}

step2. change the name "GRANTS_TEST" -> "GRANTS_TEST_2"

resource "snowflake_role" "test" {
  name    = "GRANTS_TEST_2"
}

resource "snowflake_role_grants" "test" {
  role_name = snowflake_role.test.name
  roles     = [
    "ACCOUNTADMIN"
  ]
}

step3. run terraform apply, and output the error. (even with this error message, resources on snowflake were successfully updated)

terraform apply -auto-approve=false
snowflake_role_grants.test: Refreshing state... [id=GRANTS_TEST||||ACCOUNTADMIN|false]
snowflake_role.test: Refreshing state... [id=GRANTS_TEST2]
╷
│ Error: 002003 (02000): SQL compilation error:
│ Role 'GRANTS_TEST' does not exist or not authorized.
│ 
│   with snowflake_role_grants.test,
│   on role.tf line 5, in resource "snowflake_role_grants" "test":
│    5: resource "snowflake_role_grants" "test" {
│ 
╵

Workaround

step0. do Code samples and commands

step1. rm the grants state

terraform state rm snowflake_role_grants.test

step2. import the grants state from snowflake

terraform import snowflake_role_grants.test GRANTS_TEST_2

step3. run terraform apply

terraform apply

sadahry avatar Sep 07 '22 02:09 sadahry

Tried to use create_before_destroy, but no effect for this error.

Please let me know if there is a better solution for this error..

sadahry avatar Sep 07 '22 02:09 sadahry

@sadahry - We are also facing the same issue, Please let me know if u find any resolution

Dinesh-Rupchandani avatar Sep 08 '22 05:09 Dinesh-Rupchandani

We are closing this issue as part of a cleanup described in announcement. If you believe that the issue is still valid in v0.89.0, please open a new ticket.

sfc-gh-asawicki avatar Apr 30 '24 16:04 sfc-gh-asawicki