Skip to content

Commit

Permalink
Merge pull request #177 from jfrog/GH-176-fix-unexpected-value-error-…
Browse files Browse the repository at this point in the history
…with-group

Fix unexpected new value error for platform_group resource
  • Loading branch information
alexhung authored Dec 10, 2024
2 parents 4a023cb + 98cb586 commit 1393b75
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.19.1 (December 10, 2024). Tested on Artifactory 7.98.10 with Terraform 1.10.1 and OpenTofu 1.8.7

BUG FIXES:

* resource/platform_group: Fix "Provider produced inconsistent result after apply" error for attribute `members`. Issue: [#176](https://github.com/jfrog/terraform-provider-platform/issues/176) PR: [#177](https://github.com/jfrog/terraform-provider-platform/pull/177)

## 1.19.0 (December 3, 2024). Tested on Artifactory 7.98.9 with Terraform 1.10.0 and OpenTofu 1.8.6

FEATURES:
Expand Down
15 changes: 9 additions & 6 deletions pkg/platform/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,16 @@ func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest,
return
}

ms, d := types.SetValueFrom(ctx, types.StringType, membersRes.Members)
if d != nil {
resp.Diagnostics.Append(d...)
return
// only update members attribute if it is set in the configuration
if !plan.Members.IsNull() {
ms, d := types.SetValueFrom(ctx, types.StringType, membersRes.Members)
if d != nil {
resp.Diagnostics.Append(d...)
return
}

plan.Members = ms
}

plan.Members = ms
}

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
Expand Down
79 changes: 79 additions & 0 deletions pkg/platform/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,85 @@ func TestAccGroup_full(t *testing.T) {
})
}

func TestAccGroup_no_members(t *testing.T) {
_, fqrn, groupName := testutil.MkNames("test-group", "platform_group")

temp := `
resource "platform_group" "{{ .groupName }}" {
name = "{{ .groupName }}"
description = "Test group"
external_id = "externalID"
auto_join = {{ .autoJoin }}
admin_privileges = false
}
resource "artifactory_managed_user" "test-user" {
name = "test-user"
password = "Password1!"
email = "[email protected]"
groups = [platform_group.{{ .groupName }}.name]
}
`

testData := map[string]string{
"groupName": groupName,
"autoJoin": fmt.Sprintf("%t", testutil.RandBool()),
}

config := util.ExecuteTemplate(groupName, temp, testData)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"artifactory": {
Source: "jfrog/artifactory",
},
},
ProtoV6ProviderFactories: testAccProviders(),
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(fqrn, "name", testData["groupName"]),
resource.TestCheckResourceAttr(fqrn, "description", "Test group"),
resource.TestCheckResourceAttr(fqrn, "external_id", "externalID"),
resource.TestCheckResourceAttr(fqrn, "auto_join", testData["autoJoin"]),
resource.TestCheckResourceAttr(fqrn, "admin_privileges", "false"),
resource.TestCheckResourceAttrSet(fqrn, "realm"),
resource.TestCheckNoResourceAttr(fqrn, "realm_attributes"),
resource.TestCheckNoResourceAttr(fqrn, "members"),
),
ExpectNonEmptyPlan: true,
ConfigPlanChecks: resource.ConfigPlanChecks{
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(fqrn, plancheck.ResourceActionUpdate),
},
},
},
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(fqrn, "name", testData["groupName"]),
resource.TestCheckResourceAttr(fqrn, "description", "Test group"),
resource.TestCheckResourceAttr(fqrn, "external_id", "externalID"),
resource.TestCheckResourceAttr(fqrn, "auto_join", testData["autoJoin"]),
resource.TestCheckResourceAttr(fqrn, "admin_privileges", "false"),
resource.TestCheckResourceAttrSet(fqrn, "realm"),
resource.TestCheckNoResourceAttr(fqrn, "realm_attributes"),
resource.TestCheckResourceAttr(fqrn, "members.#", "0"),
),
ExpectNonEmptyPlan: true,
ConfigPlanChecks: resource.ConfigPlanChecks{
PostApplyPostRefresh: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(fqrn, plancheck.ResourceActionNoop),
plancheck.ExpectResourceAction("artifactory_managed_user.test-user", plancheck.ResourceActionUpdate),
},
},
},
},
})
}

func TestAccGroup_auto_join_conflict(t *testing.T) {
_, _, groupName := testutil.MkNames("test-group", "platform_group")
temp := `
Expand Down

0 comments on commit 1393b75

Please sign in to comment.