-
Notifications
You must be signed in to change notification settings - Fork 427
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
grant_privileges_to_role doesn't recognize changes to with_grant_option
that were made outside of Terraform
#2459
Comments
Hey @joey-squid 👋 |
Ah, I didn't realize |
So I tried your configuration and there was no sign of non-empty plans. Could you provide the exact steps to reproduce the issue? If so, then I could be able to help, because right now everything seems correct (tested against the 0.85.0 version with the same granting resource and privileges, and tried updating with_grant_option; |
|
I take back my previous comment. I was misclicking in the UI. |
OK, I think this is a full reproduction of the issue I'm seeing. It involves changing permissions out from under Terraform. This is my config:
I applied it, then went into a Snowflake worksheet and ran the following two statements:
(i.e., removed the grant option). Now
For completeness, I will run the same test with |
with_grant_option
with_grant_option
that were made outside of Terraform
(I should mention that |
I added |
Hey, Thank you for the detailed description. I'll try to reproduce the issue and find its cause as soon as I have some time. |
Much appreciated and thanks for all your support and patience so far. In the meantime I've worked around this issue by creating the correct permissions manually. |
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 It doesn't seem like the SQL is arriving with the
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... The query view of the DEV removal/addition of the "MONITOR" permission: I tried an experiment of removing the (Also, I tried hard-coding my environment variable value but it had no impact, still had a permadiff: One more clue, it looks like the MONITOR grant is never arriving in Snowflake: |
@sfc-gh-jcieslak could the issue possibly be related to this line in the Go code?
|
@chrisweis No, the |
@sfc-gh-jcieslak Please let me know if there's anything I can do to help with this issue - happy to help! Thanks! |
Fixes: #2459 The issue was related to the fact that the Read operation is only concerned about privileges (with_grant_option is also taken into consideration, but it's never set). Given this configuration: ```terraform resource "snowflake_grant_privileges_to_account_role" "test" { account_role_name = "TEST_ROLE" privileges = ["TRUNCATE"] on_schema_object { object_type = "TABLE" object_name = "TEST_DATABASE.TEST_SCHEMA.TEST_TABLE" } with_grant_option = true } ``` after apply we run the following commands by hand ```sql revoke truncate on table test_table from role test_role; grant truncate on table test_table to role test_role; -- notice we don't add "with grant option" which our resource should detect ``` Now, when we run `plan` or `apply` our resource is seeing a drift (the "TRUNCATE" privilege is not present, because `with_grant_option` is not matching) and tries to run the Update operation (unsuccessfully; 1. because of the "sdk.GrantPrivOptions" not set 2. because of the incorrect logic). When there're already existing grants there are two ways to update `with_grant_option` which depends on what is set in Snowflake. It's better to show it with SQLs, so: ```sql -- imagine this is ran by Snowflake Terraform Plugin (with_grant_option is set to true in the config) grant truncate on table test_table to role test_role with grant option; -- this is ran by hand in the worksheet revoke truncate on table test_table from role test_role; grant truncate on table test_table to role test_role; -- now update tries to run the following grant truncate on table test_table to role test_role with grant option; -- this will successfully update with_grant_option to 'true' ``` ```sql -- imagine this is ran by Snowflake Terraform Plugin (with_grant_option is set to false in the config) grant truncate on table test_table to role test_role; -- this is ran by hand in the worksheet revoke truncate on table test_table from role test_role; grant truncate on table test_table to role test_role with grant option; -- now update tries to run the following grant truncate on table test_table to role test_role; -- this won't update the with_grant_option to false because Snowflake is not updating the value when the option is already set to true (you have to revoke it first) ``` The fix I opted to is to: - when with_grant_option is set to true in the config - proceed as it was (but now set option struct correctly with with_grant_option set to true) - when with_grant_option is set to false in the config - firstly revoke privileges we would like to add (just in case this issue happens; it won't fail even if the grant does not exist) - then proceed as it was (grant privileges we would like to add) todo other grant privileges to database role ## Test Plan <!-- detail ways in which this PR has been tested or needs to be tested --> * [x] Acceptance tests that prove the issue has been fixed for every privilege-granting resource
Hey 👋 |
Terraform CLI and Provider Versions
Terraform v1.6.2
on darwin_arm64
Terraform Configuration
Expected Behavior
Those permissions, which currently have their
grant_option
set tofalse
(as reported inshow grants to role
), should change to have their grants set totrue
.Actual Behavior
terraform plan
showsand
terraform apply
doesn't actually change anything.Steps to Reproduce
terraform apply
orterraform 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 callsd.Get("with_grant_option").(bool)
(theCreateGrantPrivilegesToRole
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.The text was updated successfully, but these errors were encountered: