@@ -157,7 +157,7 @@ func stringOrNil(s string) *string {
157
157
// ToolArchitecture represents the common architecture structure for all tool versions
158
158
type ToolArchitecture struct {
159
159
URL types.String `tfsdk:"url"`
160
- Sha types.String `tfsdk:"sha"` // Standardized to lowercase field name
160
+ Sha types.String `tfsdk:"sha"`
161
161
OS types.String `tfsdk:"os"`
162
162
Arch types.String `tfsdk:"arch"`
163
163
}
@@ -218,7 +218,7 @@ func convertToToolVersionArchitectures(ctx context.Context, archs types.Set) ([]
218
218
for _ , model := range archModels {
219
219
result = append (result , & tfe.ToolVersionArchitecture {
220
220
URL : model .URL .ValueString (),
221
- Sha : model .Sha .ValueString (), // Consistent lowercase field name
221
+ Sha : model .Sha .ValueString (),
222
222
OS : model .OS .ValueString (),
223
223
Arch : model .Arch .ValueString (),
224
224
})
@@ -233,15 +233,12 @@ func PreserveAMD64ArchsOnChange() planmodifier.Set {
233
233
return & preserveAMD64ArchsModifier {}
234
234
}
235
235
236
- // Implement the plan modifier interface
237
236
type preserveAMD64ArchsModifier struct {}
238
237
239
- // Description provides a plain text description of the plan modifier
240
238
func (m * preserveAMD64ArchsModifier ) Description (ctx context.Context ) string {
241
239
return "Preserves AMD64 architecture entries when top-level URL or SHA changes"
242
240
}
243
241
244
- // MarkdownDescription provides markdown documentation
245
242
func (m * preserveAMD64ArchsModifier ) MarkdownDescription (ctx context.Context ) string {
246
243
return "Preserves AMD64 architecture entries when top-level URL or SHA changes"
247
244
}
@@ -260,13 +257,11 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
260
257
261
258
var configURL , stateURL , configSHA , stateSHA types.String
262
259
263
- // Get values from state and plan
264
260
req .Config .GetAttribute (ctx , path .Root ("url" ), & configURL )
265
261
req .State .GetAttribute (ctx , path .Root ("url" ), & stateURL )
266
262
req .Config .GetAttribute (ctx , path .Root ("sha" ), & configSHA )
267
263
req .State .GetAttribute (ctx , path .Root ("sha" ), & stateSHA )
268
264
269
- // Check if values are changing
270
265
urlChanged := ! configURL .Equal (stateURL )
271
266
shaChanged := ! configSHA .Equal (stateSHA )
272
267
@@ -276,18 +271,15 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
276
271
return
277
272
}
278
273
279
- // Extract state archs and plan archs
280
274
stateArchs := req .StateValue
281
275
planArchs := req .PlanValue
282
276
283
- // Extract archs from state
284
277
var stateArchsList []ToolArchitecture
285
278
diags := stateArchs .ElementsAs (ctx , & stateArchsList , false )
286
279
if diags .HasError () {
287
280
return
288
281
}
289
282
290
- // we need to update the plan amd url and sha to match the top level values
291
283
var planArchsList []ToolArchitecture
292
284
diags = planArchs .ElementsAs (ctx , & planArchsList , false )
293
285
if diags .HasError () {
@@ -307,7 +299,7 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
307
299
"stateSHA" : configSHA ,
308
300
"planSHA" : stateSHA ,
309
301
})
310
- // Check if AMD64 is already in the plan
302
+
311
303
for _ , arch := range planArchsList {
312
304
if arch .Arch .ValueString () == "amd64" {
313
305
tflog .Debug (ctx , "Found AMD64 architecture in plan" , map [string ]interface {}{
@@ -316,8 +308,7 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
316
308
"os" : arch .OS .ValueString (),
317
309
"arch" : arch .Arch .ValueString (),
318
310
})
319
- // If we found AMD64, update its URL and SHA if they are changing
320
- // If URL or SHA is changing, update the AMD64 arch to match
311
+
321
312
if urlChanged {
322
313
arch .URL = configURL
323
314
}
@@ -354,15 +345,12 @@ func SyncTopLevelURLSHAWithAMD64() planmodifier.String {
354
345
return & SyncTopLevelURLSHAWithAMD64Modifier {}
355
346
}
356
347
357
- // Implement the plan modifier interface
358
348
type SyncTopLevelURLSHAWithAMD64Modifier struct {}
359
349
360
- // Description provides a plain text description of the plan modifier
361
350
func (m * SyncTopLevelURLSHAWithAMD64Modifier ) Description (ctx context.Context ) string {
362
351
return "Combines top-level URL/SHA with AMD64 architecture"
363
352
}
364
353
365
- // MarkdownDescription provides markdown documentation
366
354
func (m * SyncTopLevelURLSHAWithAMD64Modifier ) MarkdownDescription (ctx context.Context ) string {
367
355
return "Combines top-level URL/SHA with AMD64 architecture"
368
356
}
@@ -380,9 +368,6 @@ func (m *SyncTopLevelURLSHAWithAMD64Modifier) PlanModifyString(ctx context.Conte
380
368
return
381
369
}
382
370
383
- // if config archs is not set we will not modify the plan
384
- // get the config archs
385
-
386
371
var configArchs types.Set
387
372
diags := req .Config .GetAttribute (ctx , path .Root ("archs" ), & configArchs )
388
373
if diags .HasError () {
@@ -397,13 +382,9 @@ func (m *SyncTopLevelURLSHAWithAMD64Modifier) PlanModifyString(ctx context.Conte
397
382
return
398
383
}
399
384
400
- // we do not know the name of the attibute
401
- // we are modifying, so we will use the path to get the attribute name
402
385
segments := req .Path .String ()
403
386
attributeName := segments [strings .LastIndex (segments , "." )+ 1 :]
404
387
405
- // get the archs from the plan
406
- // get the amd arch from the configArchs
407
388
var amd64Arch ToolArchitecture
408
389
var configArchsList []ToolArchitecture
409
390
diags = configArchs .ElementsAs (ctx , & configArchsList , false )
@@ -422,18 +403,14 @@ func (m *SyncTopLevelURLSHAWithAMD64Modifier) PlanModifyString(ctx context.Conte
422
403
}
423
404
424
405
if amd64Arch .Arch .IsNull () || amd64Arch .Arch .IsUnknown () {
425
- // set the plan's top level URL/SHA to null
426
406
resp .PlanValue = types .StringNull ()
427
407
return
428
408
}
429
409
430
- // Get the value of the attributeName from the amd64 arch
431
410
switch attributeName {
432
411
case "url" :
433
- // set the plan value to the URL of the AMD64 arch
434
412
resp .PlanValue = types .StringValue (amd64Arch .URL .ValueString ())
435
413
case "sha" :
436
- // set the plan value to the SHA of the AMD64 arch
437
414
resp .PlanValue = types .StringValue (amd64Arch .Sha .ValueString ())
438
415
default :
439
416
tflog .Debug (ctx , "Unsupported attribute for AMD64 combination" , map [string ]interface {}{
0 commit comments