Skip to content

Commit b94078c

Browse files
committed
hmm
1 parent 65c5d6b commit b94078c

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

internal/provider/organization_sync_settings_resource.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ type OrganizationSyncSettingsResourceModel struct {
2929
Field types.String `tfsdk:"field"`
3030
AssignDefault types.Bool `tfsdk:"assign_default"`
3131
Mapping types.Map `tfsdk:"mapping"`
32-
33-
// Terraform requires that resources have an ID
34-
ID types.String `tfsdk:"id"`
3532
}
3633

3734
func NewOrganizationSyncSettingsResource() resource.Resource {
@@ -70,11 +67,6 @@ This resource is only compatible with Coder version [2.19.0](https://github.com/
7067
Optional: true,
7168
MarkdownDescription: "A map from OIDC group name to Coder organization ID.",
7269
},
73-
"id": schema.StringAttribute{
74-
Computed: true,
75-
MarkdownDescription: "An arbitrary ID, because Terraform requires that " +
76-
"all resources have IDs.",
77-
},
7870
},
7971
}
8072
}
@@ -113,24 +105,26 @@ func (r *OrganizationSyncSettingsResource) Read(ctx context.Context, req resourc
113105
return
114106
}
115107

116-
// Convert IDs to strings
117-
elements := make(map[string][]string)
118-
for key, ids := range settings.Mapping {
119-
for _, id := range ids {
120-
elements[key] = append(elements[key], id.String())
121-
}
122-
}
123-
124108
// Store the latest values that we just fetched.
125109
data.Field = types.StringValue(settings.Field)
126110
data.AssignDefault = types.BoolValue(settings.AssignDefault)
127111

128-
mapping, diags := types.MapValueFrom(ctx, types.ListType{ElemType: UUIDType}, elements)
129-
resp.Diagnostics.Append(diags...)
130-
if resp.Diagnostics.HasError() {
131-
return
112+
if !data.Mapping.IsNull() {
113+
// Convert IDs to strings
114+
elements := make(map[string][]string)
115+
for key, ids := range settings.Mapping {
116+
for _, id := range ids {
117+
elements[key] = append(elements[key], id.String())
118+
}
119+
}
120+
121+
mapping, diags := types.MapValueFrom(ctx, types.ListType{ElemType: UUIDType}, elements)
122+
resp.Diagnostics.Append(diags...)
123+
if resp.Diagnostics.HasError() {
124+
return
125+
}
126+
data.Mapping = mapping
132127
}
133-
data.Mapping = mapping
134128

135129
// Save updated data into Terraform state
136130
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
@@ -149,9 +143,6 @@ func (r *OrganizationSyncSettingsResource) Create(ctx context.Context, req resou
149143
"assign_default": data.AssignDefault.ValueBool(),
150144
})
151145

152-
// A random ID, since Terraform requires that we have one.
153-
data.ID = types.StringValue(uuid.New().String())
154-
155146
// Create and Update use a shared implementation
156147
resp.Diagnostics.Append(r.Patch(ctx, data)...)
157148
if resp.Diagnostics.HasError() {
@@ -270,5 +261,5 @@ func (r *OrganizationSyncSettingsResource) Delete(ctx context.Context, req resou
270261

271262
func (r *OrganizationSyncSettingsResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
272263
// Any random string provided as the ID will work for importing.
273-
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
264+
resource.ImportStatePassthroughID(ctx, path.Root("field"), req, resp)
274265
}

internal/provider/organization_sync_settings_resource_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestAccOrganizationSyncSettingsResource(t *testing.T) {
4444
"wibble": {uuid.MustParse("151b5a4e-391a-464d-a88c-ac50f1458d6f")},
4545
}
4646

47-
t.Run("CreateImportUpdateReadOk", func(t *testing.T) {
47+
t.Run("CreateUpdateReadOk", func(t *testing.T) {
4848
resource.Test(t, resource.TestCase{
4949
IsUnitTest: true,
5050
PreCheck: func() { testAccPreCheck(t) },
@@ -58,14 +58,6 @@ func TestAccOrganizationSyncSettingsResource(t *testing.T) {
5858
statecheck.ExpectKnownValue("coderd_organization_sync_settings.test", tfjsonpath.New("assign_default"), knownvalue.Bool(true)),
5959
},
6060
},
61-
// Import
62-
{
63-
Config: cfg1.String(t),
64-
ResourceName: "coderd_organization_sync_settings.test",
65-
ImportState: true,
66-
ImportStateVerify: true,
67-
ImportStateId: ":)",
68-
},
6961
// Update and Read
7062
{
7163
Config: cfg2.String(t),
@@ -105,13 +97,17 @@ provider coderd {
10597
}
10698
10799
resource "coderd_organization_sync_settings" "test" {
108-
field = {{.Field}}
100+
field = "{{.Field}}"
109101
assign_default = {{.AssignDefault}}
110102
111103
{{- if .Mapping}}
112104
mapping = {
113105
{{- range $key, $value := .Mapping}}
114-
{{$key}} = "{{$value}}"
106+
{{$key}} = [
107+
{{- range $id := $value}}
108+
"{{$id}}",
109+
{{- end}}
110+
]
115111
{{- end}}
116112
}
117113
{{- end}}

0 commit comments

Comments
 (0)