@@ -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
3734func 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
271262func (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}
0 commit comments