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

SQL compilation error on snowflake_role_grant if target role removed

Open plaisted opened this issue 4 years ago • 2 comments

These seems to be the same issue that #432 resolved but on role grants instead of database grant.

If a target role "role_name" for snowflake_role_grant gets removed, terraform plan fails due to the SQL error shown. This occurs even when the target role is managed by terraform and would be created on successful run.

TF resources:

// Terraform typescript CDK
const db_owner = new snow.Role(scope, `role-${dbName}-owner`, {
    name: "OWNER_" + db.name,
});
new snow.RoleGrants(scope, `grant_${dbName}_owner_to_sysadmin`, {
    roles: ["SYSADMIN"],
    roleName: db_owner.name,
});

Resulting error:

╷
│ Error: 002003 (02000): SQL compilation error:
│ Role 'OWNER_DEMO_DB' does not exist or not authorized.
│ 
│   with snowflake_role_grants.grant_OWNER_DEMO_DB_owner_to_sysadmin,
│   on snowflake-accounts.qa.tf.json line 266, in resource.snowflake_role_grants.grant_DEMO_DB_owner_to_sysadmin:
│  266:       },
│ 

plaisted avatar Oct 17 '21 17:10 plaisted

Same issue here. Refresh fails when the role has been deleted outside of terraform:

terraform apply -var-file account.tfvars 
snowflake_role.prod_jaffles_admin: Refreshing state... [id=PROD_JAFFLES_ADMIN]
snowflake_role_grants.prod_jaffles_admin: Refreshing state... [id=PROD_JAFFLES_ADMIN]
╷
│ Error: 002003 (02000): SQL compilation error:
│ Role 'PROD_JAFFLES_ADMIN' does not exist or not authorized.
│ 
│   with snowflake_role_grants.prod_jaffles_admin,
│   on prod-jaffles.tf line 26, in resource "snowflake_role_grants" "prod_jaffles_admin":
│   26: resource "snowflake_role_grants" "prod_jaffles_admin" {

I had to manually created the missing role to progress.

tekumara avatar Nov 03 '21 00:11 tekumara

Same issue here.

ricardobf avatar Apr 06 '22 11:04 ricardobf

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