-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Example of granting role to multiple objects (#3047)
- Add example of granting role to multiple objects - Fix setup for the integration tests when using just a single account
- Loading branch information
1 parent
5802dca
commit 86a7902
Showing
5 changed files
with
115 additions
and
14 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
18 changes: 18 additions & 0 deletions
18
pkg/resources/manual_tests/granting_role_to_multiple_users_or_roles/config.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
roles: | ||
"example_role1": | ||
grant_to: | ||
user: | ||
- "example_user1" | ||
role: | ||
"example_role2": | ||
grant_to: | ||
user: | ||
role: | ||
- "example_role3" | ||
"example_role3": | ||
grant_to: | ||
user: | ||
- "example_user1" | ||
- "example_user2" | ||
- "example_user3" | ||
role: |
79 changes: 79 additions & 0 deletions
79
pkg/resources/manual_tests/granting_role_to_multiple_users_or_roles/main.tf
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
terraform { | ||
required_version = ">= 1.3.6" | ||
required_providers { | ||
snowflake = { | ||
source = "snowflake-labs/snowflake" | ||
version = "0.94.1" | ||
} | ||
} | ||
} | ||
|
||
resource "snowflake_user" "user1" { | ||
name = "example_user1" | ||
} | ||
|
||
resource "snowflake_user" "user2" { | ||
name = "example_user2" | ||
} | ||
|
||
resource "snowflake_user" "user3" { | ||
name = "example_user3" | ||
} | ||
|
||
resource "snowflake_account_role" "role1" { | ||
name = "example_role1" | ||
} | ||
|
||
resource "snowflake_account_role" "role2" { | ||
name = "example_role2" | ||
} | ||
|
||
resource "snowflake_account_role" "role3" { | ||
name = "example_role3" | ||
} | ||
|
||
locals { | ||
yaml_roles = yamldecode(file("${path.module}/config.yaml")) | ||
grant_to_user = distinct(flatten([ | ||
for k, v in local.yaml_roles.roles : v.grant_to.user == null ? [] : [ | ||
for u in v.grant_to.user : { | ||
role = k | ||
to_user = u | ||
} | ||
]])) | ||
grant_to_role = distinct(flatten([ | ||
for k, v in local.yaml_roles.roles : v.grant_to.role == null ? [] : [ | ||
for r in v.grant_to.role : { | ||
role = k | ||
to_role = r | ||
} | ||
]])) | ||
} | ||
|
||
output "grant_to_user_output" { | ||
value = local.grant_to_user | ||
} | ||
|
||
output "grant_to_role_output" { | ||
value = local.grant_to_role | ||
} | ||
|
||
resource "snowflake_grant_account_role" "user_grants" { | ||
depends_on = [ | ||
snowflake_user.user1, snowflake_user.user2, snowflake_user.user3, snowflake_account_role.role1, | ||
snowflake_account_role.role2, snowflake_account_role.role3 | ||
] | ||
for_each = {for entry in local.grant_to_user : "${entry.role}.${entry.to_user}" => entry} | ||
role_name = each.value.role | ||
user_name = each.value.to_user | ||
} | ||
|
||
resource "snowflake_grant_account_role" "role_grants" { | ||
depends_on = [ | ||
snowflake_user.user1, snowflake_user.user2, snowflake_user.user3, snowflake_account_role.role1, | ||
snowflake_account_role.role2, snowflake_account_role.role3 | ||
] | ||
for_each = {for entry in local.grant_to_role : "${entry.role}.${entry.to_role}" => entry} | ||
role_name = each.value.role | ||
parent_role_name = each.value.to_role | ||
} |
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