diff --git a/pkg/resources/grant_database_role.go b/pkg/resources/grant_database_role.go index c39e46de5c..d3ea17e7a2 100644 --- a/pkg/resources/grant_database_role.go +++ b/pkg/resources/grant_database_role.go @@ -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() diff --git a/pkg/resources/grant_database_role_acceptance_test.go b/pkg/resources/grant_database_role_acceptance_test.go index 7112774c19..4fcec9f346 100644 --- a/pkg/resources/grant_database_role_acceptance_test.go +++ b/pkg/resources/grant_database_role_acceptance_test.go @@ -57,6 +57,39 @@ func TestAcc_GrantDatabaseRole_databaseRole(t *testing.T) { }) } +func TestAcc_GrantDatabaseRole_issue2402(t *testing.T) { + databaseName := "DB_TEST_DB_DEV" + 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)) diff --git a/pkg/resources/testdata/TestAcc_GrantDatabaseRole/issue2402/test.tf b/pkg/resources/testdata/TestAcc_GrantDatabaseRole/issue2402/test.tf new file mode 100644 index 0000000000..77ba6e94fe --- /dev/null +++ b/pkg/resources/testdata/TestAcc_GrantDatabaseRole/issue2402/test.tf @@ -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}\"" +} diff --git a/pkg/resources/testdata/TestAcc_GrantDatabaseRole/issue2402/variables.tf b/pkg/resources/testdata/TestAcc_GrantDatabaseRole/issue2402/variables.tf new file mode 100644 index 0000000000..18d979d8e1 --- /dev/null +++ b/pkg/resources/testdata/TestAcc_GrantDatabaseRole/issue2402/variables.tf @@ -0,0 +1,11 @@ +variable "database_role_name" { + type = string +} + +variable "parent_database_role_name" { + type = string +} + +variable "database" { + type = string +}