Skip to content

Commit a9f0ed6

Browse files
authored
Suppress diff for user_name in databricks_user when the changes only in character case (#2786)
* Suppress diff for `user_name` in `databricks_user` when the changes only in character case Identity management team rolled out the changes for AWS workspaces to force user names be lower-cased by default (to match behavior on GCP & Azure). But these changes are causing the permanent configuration drift because `user_name` is marked as `force_new`. To mitigate this problem, added a suppress diff function that ignores changes in case. * Add integration test * Clarify in the docs that name will be lower-cased
1 parent 8e785ed commit a9f0ed6

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

docs/resources/user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ resource "databricks_user" "account_user" {
8787

8888
The following arguments are available:
8989

90-
* `user_name` - (Required) This is the username of the given user and will be their form of access and identity.
90+
* `user_name` - (Required) This is the username of the given user and will be their form of access and identity. Provided username will be converted to lower case if it contains upper case characters.
9191
* `display_name` - (Optional) This is an alias for the username that can be the full name of the user.
9292
* `external_id` - (Optional) ID of the user in an external identity provider.
9393
* `allow_cluster_create` - (Optional) Allow the user to have [cluster](cluster.md) create privileges. Defaults to false. More fine grained permissions could be assigned with [databricks_permissions](permissions.md#Cluster-usage) and `cluster_id` argument. Everyone without `allow_cluster_create` argument set, but with [permission to use](permissions.md#Cluster-Policy-usage) Cluster Policy would be able to create clusters, but within boundaries of that specific policy.

internal/acceptance/user_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ func TestAccUserResource(t *testing.T) {
138138
user_name = "tf-derde+{var.RANDOM}@example.com"
139139
display_name = "Derde {var.RANDOM}"
140140
allow_instance_pool_create = true
141-
}`
141+
}
142+
`
142143
workspaceLevel(t, step{
143144
Template: differentUsers,
144145
Check: resource.ComposeTestCheckFunc(
@@ -153,3 +154,18 @@ func TestAccUserResource(t *testing.T) {
153154
Template: differentUsers,
154155
})
155156
}
157+
158+
func TestAccUserResourceCaseInsensitive(t *testing.T) {
159+
username := "CSTF-" + qa.RandomEmail()
160+
csUser := `resource "databricks_user" "first" {
161+
user_name = "` + username + `"
162+
}`
163+
workspaceLevel(t, step{
164+
Template: csUser,
165+
Check: resource.ComposeTestCheckFunc(
166+
resource.TestCheckResourceAttr("databricks_user.first", "user_name", strings.ToLower(username)),
167+
),
168+
}, step{
169+
Template: csUser,
170+
})
171+
}

scim/resource_user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func ResourceUser() *schema.Resource {
2929
userSchema := common.StructToSchema(entity{},
3030
func(m map[string]*schema.Schema) map[string]*schema.Schema {
3131
addEntitlementsToSchema(&m)
32+
m["user_name"].DiffSuppressFunc = common.EqualFoldDiffSuppress
3233
m["active"].Default = true
3334
m["force"] = &schema.Schema{
3435
Type: schema.TypeBool,

scim/resource_user_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,10 @@ func TestCreateForceOverwriteFindsAndSetsAccID(t *testing.T) {
727727
assert.Equal(t, "abc", d.Id())
728728
})
729729
}
730+
731+
func TestUserResource_SparkConfDiffSuppress(t *testing.T) {
732+
jr := ResourceUser()
733+
scs := jr.Schema["user_name"]
734+
assert.True(t, scs.DiffSuppressFunc("user_name", "[email protected]", "[email protected]", nil))
735+
assert.False(t, scs.DiffSuppressFunc("user_name", "[email protected]", "[email protected]", nil))
736+
}

0 commit comments

Comments
 (0)