Skip to content

Commit bd73bb4

Browse files
committed
fix uuid handling
1 parent 68c6ad5 commit bd73bb4

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

internal/provider/organization_resource.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,19 @@ func (r *OrganizationResource) patchGroupSync(
413413
groupSync.Field = groupSyncData.Field.ValueString()
414414
groupSync.RegexFilter = regexp.MustCompile(groupSyncData.RegexFilter.ValueString())
415415
groupSync.AutoCreateMissing = groupSyncData.AutoCreateMissing.ValueBool()
416-
diags.Append(groupSyncData.Mapping.ElementsAs(ctx, &groupSync.Mapping, false)...)
416+
groupSync.Mapping = make(map[string][]uuid.UUID)
417+
// Terraform doesn't know how to turn one our `UUID` Terraform values into a
418+
// `uuid.UUID`, so we have to do the unwrapping manually here.
419+
var mapping map[string][]UUID
420+
diags.Append(groupSyncData.Mapping.ElementsAs(ctx, &mapping, false)...)
417421
if diags.HasError() {
418422
return diags
419423
}
424+
for key, ids := range mapping {
425+
for _, id := range ids {
426+
groupSync.Mapping[key] = append(groupSync.Mapping[key], id.ValueUUID())
427+
}
428+
}
420429

421430
// Perform the PATCH
422431
_, err := r.Client.PatchGroupIDPSyncSettings(ctx, orgID.String(), groupSync)

internal/provider/organization_resource_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/coder/coder/v2/coderd/util/ptr"
1111
"github.com/coder/coder/v2/codersdk"
1212
"github.com/coder/terraform-provider-coderd/integration"
13+
"github.com/google/uuid"
1314
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1415
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
1516
"github.com/hashicorp/terraform-plugin-testing/statecheck"
@@ -41,12 +42,12 @@ func TestAccOrganizationResource(t *testing.T) {
4142
cfg2.DisplayName = ptr.Ref("Example Organization New")
4243

4344
cfg3 := cfg2
44-
// cfg3.GroupSync = ptr.Ref(codersdk.GroupSyncSettings{
45-
// Field: "wibble",
46-
// Mapping: map[string][]uuid.UUID{
47-
// "wibble": {uuid.MustParse("6e57187f-6543-46ab-a62c-a10065dd4314")},
48-
// },
49-
// })
45+
cfg3.GroupSync = ptr.Ref(codersdk.GroupSyncSettings{
46+
Field: "wibble",
47+
Mapping: map[string][]uuid.UUID{
48+
"wibble": {uuid.MustParse("6e57187f-6543-46ab-a62c-a10065dd4314")},
49+
},
50+
})
5051
cfg3.RoleSync = ptr.Ref(codersdk.RoleSyncSettings{
5152
Field: "wobble",
5253
Mapping: map[string][]string{
@@ -89,8 +90,8 @@ func TestAccOrganizationResource(t *testing.T) {
8990
{
9091
Config: cfg3.String(t),
9192
ConfigStateChecks: []statecheck.StateCheck{
92-
// statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("group_sync").AtMapKey("field"), knownvalue.StringExact("wibble")),
93-
// statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("group_sync").AtMapKey("mapping").AtMapKey("wibble").AtSliceIndex(0), knownvalue.StringExact("6e57187f-6543-46ab-a62c-a10065dd4314")),
93+
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("group_sync").AtMapKey("field"), knownvalue.StringExact("wibble")),
94+
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("group_sync").AtMapKey("mapping").AtMapKey("wibble").AtSliceIndex(0), knownvalue.StringExact("6e57187f-6543-46ab-a62c-a10065dd4314")),
9495
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("role_sync").AtMapKey("field"), knownvalue.StringExact("wobble")),
9596
statecheck.ExpectKnownValue("coderd_organization.test", tfjsonpath.New("role_sync").AtMapKey("mapping").AtMapKey("wobble").AtSliceIndex(0), knownvalue.StringExact("wobbly")),
9697
},

0 commit comments

Comments
 (0)