Skip to content

Commit

Permalink
Allow changes to display_name of databricks_group resource withou…
Browse files Browse the repository at this point in the history
…t recreating a group (#3334)

* Update ResourceGroup to allow changes to display_name without forcing new

* Add acc tests

---------

Co-authored-by: frosforever <frosforever@users.noreply.github.com>
  • Loading branch information
frosforever and frosforever authored Mar 11, 2024
1 parent f591dda commit edbda2a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
80 changes: 80 additions & 0 deletions internal/acceptance/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package acceptance

import (
"context"
"github.com/stretchr/testify/assert"

"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/qa"
Expand Down Expand Up @@ -68,3 +69,82 @@ func TestAccGroupsExternalIdAndScimProvisioning(t *testing.T) {
}`,
})
}

func TestMwsAccGroupsUpdateDisplayName(t *testing.T) {
nameInit := qa.RandomName("tfgroup")
nameUpdate := qa.RandomName("tfgroup")
accountLevel(t, step{
Template: `resource "databricks_group" "this" {
display_name = "` + nameInit + `"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("databricks_group.this", "display_name", nameInit),
resourceCheck("databricks_group.this",
func(ctx context.Context, client *common.DatabricksClient, id string) error {
groupsAPI := scim.NewGroupsAPI(ctx, client)
group, err := groupsAPI.Read(id, "displayName,entitlements")
if err != nil {
return err
}
assert.Equal(t, group.DisplayName, nameInit)
return nil
}),
),
}, step{
Template: `resource "databricks_group" "this" {
display_name = "` + nameUpdate + `"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("databricks_group.this", "display_name", nameUpdate),
resourceCheck("databricks_group.this",
func(ctx context.Context, client *common.DatabricksClient, id string) error {
groupsAPI := scim.NewGroupsAPI(ctx, client)
group, err := groupsAPI.Read(id, "displayName,entitlements")
if err != nil {
return err
}
assert.Equal(t, group.DisplayName, nameUpdate)
return nil
}),
),
})
}
func TestAccGroupsUpdateDisplayName(t *testing.T) {
nameInit := qa.RandomName("tfgroup")
nameUpdate := qa.RandomName("tfgroup")
workspaceLevel(t, step{
Template: `resource "databricks_group" "this" {
display_name = "` + nameInit + `"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("databricks_group.this", "display_name", nameInit),
resourceCheck("databricks_group.this",
func(ctx context.Context, client *common.DatabricksClient, id string) error {
groupsAPI := scim.NewGroupsAPI(ctx, client)
group, err := groupsAPI.Read(id, "displayName,entitlements")
if err != nil {
return err
}
assert.Equal(t, group.DisplayName, nameInit)
return nil
}),
),
}, step{
Template: `resource "databricks_group" "this" {
display_name = "` + nameUpdate + `"
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("databricks_group.this", "display_name", nameUpdate),
resourceCheck("databricks_group.this",
func(ctx context.Context, client *common.DatabricksClient, id string) error {
groupsAPI := scim.NewGroupsAPI(ctx, client)
group, err := groupsAPI.Read(id, "displayName,entitlements")
if err != nil {
return err
}
assert.Equal(t, group.DisplayName, nameUpdate)
return nil
}),
),
})
}
2 changes: 1 addition & 1 deletion scim/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// ResourceGroup manages user groups
func ResourceGroup() common.Resource {
type entity struct {
DisplayName string `json:"display_name" tf:"force_new"`
DisplayName string `json:"display_name"`
ExternalID string `json:"external_id,omitempty" tf:"force_new,suppress_diff"`
URL string `json:"url,omitempty" tf:"computed"`
}
Expand Down
2 changes: 1 addition & 1 deletion scim/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestResourceGroupUpdate(t *testing.T) {
allow_cluster_create = true
databricks_sql_access = true
`,
RequiresNew: true,
RequiresNew: false,
Update: true,
ID: "abc",
}.Apply(t)
Expand Down

0 comments on commit edbda2a

Please sign in to comment.