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: Granting database roles #2511

Merged
merged 1 commit into from
Feb 16, 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
4 changes: 4 additions & 0 deletions pkg/resources/grant_database_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func ReadGrantDatabaseRole(d *schema.ResourceData, meta interface{}) error {
parts = strings.Split(s, "\".")
if len(parts) < 2 {
parts = strings.Split(s, ".\"")
if len(parts) < 2 {
s = strings.Trim(s, "\"")
parts = strings.Split(s, ".")
}
}
}
s = sdk.NewDatabaseObjectIdentifier(parts[0], parts[1]).FullyQualifiedName()
Expand Down
33 changes: 33 additions & 0 deletions pkg/resources/grant_database_role_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,39 @@ func TestAcc_GrantDatabaseRole_databaseRole(t *testing.T) {
})
}

func TestAcc_GrantDatabaseRole_issue2402(t *testing.T) {
databaseName := "DB_TEST_DB_DEV"
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
databaseRoleName := "TEST_DATABASE_ROLE_02"
parentDatabaseRoleName := "TEST_DATABASE_ROLE_01"
resourceName := "snowflake_grant_database_role.g"
m := func() map[string]config.Variable {
return map[string]config.Variable{
"database": config.StringVariable(databaseName),
"database_role_name": config.StringVariable(databaseRoleName),
"parent_database_role_name": config.StringVariable(parentDatabaseRoleName),
}
}
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: testAccCheckGrantDatabaseRoleDestroy,
Steps: []resource.TestStep{
{
ConfigDirectory: acc.ConfigurationDirectory("TestAcc_GrantDatabaseRole/issue2402"),
ConfigVariables: m(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "database_role_name", fmt.Sprintf(`"%v"."%v"`, databaseName, databaseRoleName)),
resource.TestCheckResourceAttr(resourceName, "parent_database_role_name", fmt.Sprintf(`"%v"."%v"`, databaseName, parentDatabaseRoleName)),
resource.TestCheckResourceAttr(resourceName, "id", fmt.Sprintf(`"%v"."%v"|DATABASE ROLE|"%v"."%v"`, databaseName, databaseRoleName, databaseName, parentDatabaseRoleName)),
),
},
},
})
}

func TestAcc_GrantDatabaseRole_accountRole(t *testing.T) {
databaseRoleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
parentRoleName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
Expand Down
18 changes: 18 additions & 0 deletions pkg/resources/testdata/TestAcc_GrantDatabaseRole/issue2402/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "snowflake_database" "database" {
name = var.database
}

resource "snowflake_database_role" "database_role" {
database = snowflake_database.database.name
name = var.database_role_name
}

resource "snowflake_database_role" "parent_database_role" {
database = snowflake_database.database.name
name = var.parent_database_role_name
}

resource "snowflake_grant_database_role" "g" {
database_role_name = "\"${snowflake_database.database.name}\".\"${snowflake_database_role.database_role.name}\""
parent_database_role_name = "\"${snowflake_database.database.name}\".\"${snowflake_database_role.parent_database_role.name}\""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "database_role_name" {
type = string
}

variable "parent_database_role_name" {
type = string
}

variable "database" {
type = string
}
Loading