@@ -29,9 +29,6 @@ type OrganizationSyncSettingsResourceModel struct {
29
29
Field types.String `tfsdk:"field"`
30
30
AssignDefault types.Bool `tfsdk:"assign_default"`
31
31
Mapping types.Map `tfsdk:"mapping"`
32
-
33
- // Terraform requires that resources have an ID
34
- ID types.String `tfsdk:"id"`
35
32
}
36
33
37
34
func NewOrganizationSyncSettingsResource () resource.Resource {
@@ -70,11 +67,6 @@ This resource is only compatible with Coder version [2.19.0](https://github.com/
70
67
Optional : true ,
71
68
MarkdownDescription : "A map from OIDC group name to Coder organization ID." ,
72
69
},
73
- "id" : schema.StringAttribute {
74
- Computed : true ,
75
- MarkdownDescription : "An arbitrary ID, because Terraform requires that " +
76
- "all resources have IDs." ,
77
- },
78
70
},
79
71
}
80
72
}
@@ -113,24 +105,26 @@ func (r *OrganizationSyncSettingsResource) Read(ctx context.Context, req resourc
113
105
return
114
106
}
115
107
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
-
124
108
// Store the latest values that we just fetched.
125
109
data .Field = types .StringValue (settings .Field )
126
110
data .AssignDefault = types .BoolValue (settings .AssignDefault )
127
111
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
132
127
}
133
- data .Mapping = mapping
134
128
135
129
// Save updated data into Terraform state
136
130
resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
@@ -149,9 +143,6 @@ func (r *OrganizationSyncSettingsResource) Create(ctx context.Context, req resou
149
143
"assign_default" : data .AssignDefault .ValueBool (),
150
144
})
151
145
152
- // A random ID, since Terraform requires that we have one.
153
- data .ID = types .StringValue (uuid .New ().String ())
154
-
155
146
// Create and Update use a shared implementation
156
147
resp .Diagnostics .Append (r .Patch (ctx , data )... )
157
148
if resp .Diagnostics .HasError () {
@@ -270,5 +261,5 @@ func (r *OrganizationSyncSettingsResource) Delete(ctx context.Context, req resou
270
261
271
262
func (r * OrganizationSyncSettingsResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
272
263
// 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 )
274
265
}
0 commit comments