Skip to content

Commit

Permalink
Fix diff suppression for default_x in user resource
Browse files Browse the repository at this point in the history
References: #2836
  • Loading branch information
sfc-gh-asawicki committed Aug 23, 2024
1 parent 1f8db8c commit 61fd26c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ According to https://docs.snowflake.com/en/sql-reference/functions/all_user_name

Connected issues: [#2662](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2662), [#2668](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2668).

### *(bugfix)* Properly suppressing diffs for quoted `default_warehouse`, `default_namespace`, and `default_role`

During the [identifiers rework](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/ROADMAP.md#identifiers-rework), we generalized how we compute the differences correctly for the identifier fields (TODO link to doc?). Proper suppressor was applied to `default_warehouse`, `default_namespace`, and `default_role`.

Connected issues: [#2836](https://github.com/Snowflake-Labs/terraform-provider-snowflake/pull/2836)

## v0.94.0 ➞ v0.94.1
### changes in snowflake_schema

Expand Down
11 changes: 6 additions & 5 deletions pkg/resources/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ var userSchema = map[string]*schema.Schema{
Computed: true,
},
"default_warehouse": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the virtual warehouse that is active by default for the user’s session upon login.",
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: suppressIdentifierQuoting,
Description: "Specifies the virtual warehouse that is active by default for the user’s session upon login.",
},
"default_namespace": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: ignoreCaseSuppressFunc,
DiffSuppressFunc: suppressIdentifierQuoting,
Description: "Specifies the namespace (database only or database and schema) that is active by default for the user’s session upon login.",
},
"default_role": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: ignoreCaseSuppressFunc,
DiffSuppressFunc: suppressIdentifierQuoting,
Description: "Specifies the role that is active by default for the user’s session upon login.",
},
"default_secondary_roles": {
Expand Down
28 changes: 28 additions & 0 deletions pkg/resources/user_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectassert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/objectparametersassert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert/resourceparametersassert"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/config"
Expand Down Expand Up @@ -572,3 +573,30 @@ func TestAcc_User_AllParameters(t *testing.T) {
},
})
}

func TestAcc_User_issue2836(t *testing.T) {
userId := acc.TestClient().Ids.RandomAccountObjectIdentifier()
defaultRole := "SOME ROLE WITH SPACE case sensitive"
defaultRoleQuoted := fmt.Sprintf(`"%s"`, defaultRole)

userModel := model.User("u", userId.Name()).
WithDefaultRole(defaultRoleQuoted)

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
PreCheck: func() { acc.TestAccPreCheck(t) },
CheckDestroy: acc.CheckDestroy(t, resources.User),
Steps: []resource.TestStep{
{
Config: config.FromModel(t, userModel),
Check: assert.AssertThat(t,
objectassert.User(t, userId).
HasDefaultRole(defaultRole),
),
},
},
})
}

0 comments on commit 61fd26c

Please sign in to comment.