terraform-provider-snowflake: grant_privileges_to_role doesn't recognize changes to `with_grant_option` that were made outside of Terraform
Terraform CLI and Provider Versions
Terraform v1.6.2 on darwin_arm64
- provider registry.terraform.io/hashicorp/aws v5.33.0
- provider registry.terraform.io/snowflake-labs/snowflake v0.84.0
Terraform Configuration
resource "snowflake_grant_privileges_to_role" "grant_metrics_table_usage" {
privileges = ["SELECT", "INSERT", "UPDATE", "DELETE"]
role_name = snowflake_role.metrics_role.name
on_schema_object {
object_name = "\"${snowflake_database.metrics_db.name}\".\"PUBLIC\".\"METRICS\""
object_type = "TABLE"
}
with_grant_option = true
}
Expected Behavior
Those permissions, which currently have their grant_option set to false (as reported in show grants to role), should change to have their grants set to true.
Actual Behavior
terraform plan shows
~ privileges = [
+ "DELETE",
+ "INSERT",
+ "SELECT",
+ "UPDATE",
]
and terraform apply doesn’t actually change anything.
Steps to Reproduce
terraform apply or terraform plan
How much impact is this issue causing?
Low
Logs
No response
Additional Information
I took a gander at the code to see if there was anything I was doing obviously wrong, and it seems that the UpdateGrantPrivilegesToRole function never calls d.Get("with_grant_option").(bool) (the CreateGrantPrivilegesToRole function does), so I’m fairly certain this is just a bug in the provider. I don’t have the bandwidth to fix it but I do have the bandwidth to test a fix if someone else gets there.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 15
@chrisweis No, the
snowflakepackage is deprecated. Now, we use thesdkone. I’m going to work on this issue today and we’ll release it next week.Hey @sfc-gh-jcieslak and @joey-squid, I think I’m also seeing this permadiff in the same way, and it’s blocking one of my project’s deployments. My resource is:
Version:
I also tested it in 0.87.0, and the problem persists.
When I watch the Snowflake queries I see that it is repeatedly applying the grants on each
terraform apply:It doesn’t seem like the SQL is arriving with the
WITH GRANT OPTIONinto Snowflake:Oddly I’d noticed that it was occuring in my production (PRD) database but not my development (DEV) database, so I made this modification to that DEV environment… From:
privileges = ["USAGE","CREATE SCHEMA","MODIFY","MONITOR"]To:privileges = ["USAGE","CREATE SCHEMA","MODIFY"]Back to:privileges = ["USAGE","CREATE SCHEMA","MODIFY","MONITOR"]…and now the permadiff also exists in DEV. Weird!The query view of the DEV removal/addition of the “MONITOR” permission:
I tried an experiment of removing the
with_grant_option = trueand the permadiff goes away, so it seems related to that property.(Also, I tried hard-coding my environment variable value but it had no impact, still had a permadiff: From: account_role_name = “DBT_${var.ENV}_ROLE” To: account_role_name = “DBT_DEV_ROLE”)
One more clue, it looks like the MONITOR grant is never arriving in Snowflake:
If I manually add the grant (joey-squid’s workaround) then the permadiff goes away.