Skip to content
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

fix: snowflake_grant_privileges_to_role read #2424

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/resources/grant_privileges_to_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func readRoleGrantPrivileges(ctx context.Context, client *sdk.Client, grantedOn
if !slices.Contains(id.Privileges, grant.Privilege) {
continue
}
if grant.GrantOption == withGrantOption && grant.GranteeName.Name() == roleName {
if grant.GrantOption == withGrantOption && grant.GranteeName.Name() == sdk.NewAccountObjectIdentifier(roleName).Name() {
// future grants do not have grantedBy, only current grants do. If grantedby
// is an empty string it means the grant could not have been created by terraform
if !id.Future && grant.GrantedBy.Name() == "" {
Expand Down
15 changes: 10 additions & 5 deletions pkg/resources/grant_privileges_to_role_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func TestAcc_GrantPrivilegesToRole_onAccount(t *testing.T) {
// contains escaped identifier, it won't match in the comparison grant.GranteeName == role_name. This results in
// setting privileges to an empty array, which causes infinite plan.
func TestAcc_GrantPrivilegesToRole_OnSchema_InfinitePlan(t *testing.T) {
name := []byte(strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)))
name[3] = '.'
name[7] = '-'
databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand All @@ -67,25 +72,25 @@ func TestAcc_GrantPrivilegesToRole_OnSchema_InfinitePlan(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: `
Config: fmt.Sprintf(`
resource "snowflake_role" "r" {
name = "some.role-123"
name = "%s"
}

resource "snowflake_database" "db" {
name = "infinite_plan_grants_db"
name = "%s"
}

resource "snowflake_grant_privileges_to_role" "g" {
depends_on = [snowflake_role.r, snowflake_database.db]
privileges = ["CREATE SCHEMA"]
role_name = "\"some.role-123\""
role_name = "\"${snowflake_role.r.name}\""
on_account_object {
object_type = "DATABASE"
object_name = snowflake_database.db.name
}
}
`,
`, string(name), databaseName),
ConfigPlanChecks: resource.ConfigPlanChecks{
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectEmptyPlan(),
Expand Down
Loading