-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: with_grant_option diff drift (#2608)
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
- Loading branch information
1 parent
918873d
commit f0018c6
Showing
4 changed files
with
365 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.