@@ -252,7 +252,13 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
252
252
return
253
253
}
254
254
255
+ // skip if archs is set in the config
256
+ if ! req .ConfigValue .IsUnknown () && ! req .ConfigValue .IsNull () {
257
+ return
258
+ }
259
+
255
260
var stateURL , planURL , stateSHA , planSHA types.String
261
+
256
262
// Get values from state and plan
257
263
req .State .GetAttribute (ctx , path .Root ("url" ), & stateURL )
258
264
req .Plan .GetAttribute (ctx , path .Root ("url" ), & planURL )
@@ -289,100 +295,115 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
289
295
return
290
296
}
291
297
298
+ tflog .Debug (ctx , "plan architectures" , map [string ]interface {}{
299
+ "planArchsList" : planArchsList ,
300
+ "stateArchsList" : stateArchsList ,
301
+ "urlChanged" : urlChanged ,
302
+ "shaChanged" : shaChanged ,
303
+ "stateURL" : stateURL ,
304
+ "planURL" : planURL ,
305
+ "stateSHA" : stateSHA ,
306
+ "planSHA" : planSHA ,
307
+ })
292
308
// Check if AMD64 is already in the plan
293
- for i , arch := range planArchsList {
309
+ for _ , arch := range planArchsList {
294
310
if arch .Arch .ValueString () == "amd64" {
311
+ tflog .Debug (ctx , "Found AMD64 architecture in plan" , map [string ]interface {}{
312
+ "url" : arch .URL .ValueString (),
313
+ "sha" : arch .Sha .ValueString (),
314
+ "os" : arch .OS .ValueString (),
315
+ "arch" : arch .Arch .ValueString (),
316
+ })
317
+ // If we found AMD64, update its URL and SHA if they are changing
295
318
// If URL or SHA is changing, update the AMD64 arch to match
296
319
if urlChanged {
297
320
arch .URL = planURL
298
321
}
299
322
if shaChanged {
300
323
arch .Sha = planSHA
301
324
}
302
- // Update the plan architecture list with the modified AMD64 arch
303
- planArchsList [i ] = arch
304
325
305
326
// Update the plan with the modified AMD64 arch
306
327
archObjectType := ObjectTypeForArchitectures ()
307
- attrValues := make ([]attr.Value , len (planArchsList ))
308
-
309
- for i , arch := range planArchsList {
310
- attrValues [i ] = types .ObjectValueMust (
311
- archObjectType .AttrTypes ,
312
- map [string ]attr.Value {
313
- "url" : arch .URL ,
314
- "sha" : arch .Sha ,
315
- "os" : arch .OS ,
316
- "arch" : arch .Arch ,
317
- },
318
- )
319
- }
328
+ attrValue := types .ObjectValueMust (
329
+ archObjectType .AttrTypes ,
330
+ map [string ]attr.Value {
331
+ "url" : arch .URL ,
332
+ "sha" : arch .Sha ,
333
+ "os" : arch .OS ,
334
+ "arch" : arch .Arch ,
335
+ },
336
+ )
320
337
321
- resp .PlanValue = types .SetValueMust (archObjectType , attrValues )
338
+ resp .PlanValue = types .SetValueMust (archObjectType , []attr. Value { attrValue } )
322
339
return
323
340
}
324
341
}
325
342
}
326
343
327
- // ValidateToolVersion provides common validation for tool version resources
328
- func ValidateToolVersion (ctx context.Context , url , sha types.String , archs types.Set , resourceType string ) diag.Diagnostics {
329
- var diags diag.Diagnostics
330
-
331
- urlPresent := ! url .IsNull () && ! url .IsUnknown ()
332
- shaPresent := ! sha .IsNull () && ! sha .IsUnknown ()
333
-
334
- // If URL or SHA is not set, we will rely on the archs attribute
335
- if ! urlPresent || ! shaPresent {
336
- return diags
337
- }
338
-
339
- // Check if archs is present
340
- if ! archs .IsNull () && ! archs .IsUnknown () {
341
- // Extract archs
342
- var archsList []ToolArchitecture
343
- archDiags := archs .ElementsAs (ctx , & archsList , false )
344
- if archDiags .HasError () {
345
- diags .Append (archDiags ... )
346
- return diags
347
- }
348
-
349
- // Check for AMD64 architecture
350
- var hasAMD64 bool
351
- for _ , arch := range archsList {
352
- if arch .Arch .ValueString () == "amd64" {
353
- hasAMD64 = true
354
-
355
- // If URL and SHA are set at top level, check they match AMD64 arch
356
- // Check URL matches
357
- if urlPresent && url .ValueString () != arch .URL .ValueString () {
358
- diags .AddError (
359
- fmt .Sprintf ("Inconsistent %s URL values" , resourceType ),
360
- fmt .Sprintf ("Top-level URL (%s) doesn't match AMD64 architecture URL (%s)" ,
361
- url .ValueString (), arch .URL .ValueString ()),
362
- )
363
- }
364
-
365
- // Check SHA matches
366
- if shaPresent && sha .ValueString () != arch .Sha .ValueString () {
367
- diags .AddError (
368
- fmt .Sprintf ("Inconsistent %s SHA values" , resourceType ),
369
- fmt .Sprintf ("Top-level SHA (%s) doesn't match AMD64 architecture SHA (%s)" ,
370
- sha .ValueString (), arch .Sha .ValueString ()),
371
- )
372
- }
373
-
374
- break
375
- }
376
- }
377
-
378
- // If top-level URL/SHA are set and no AMD64 arch found, add error
379
- if ! hasAMD64 && (! url .IsNull () || ! sha .IsNull ()) {
380
- diags .AddError (
381
- fmt .Sprintf ("Missing AMD64 architecture in %s" , resourceType ),
382
- "When specifying both top-level URL/SHA and archs, an AMD64 architecture entry must be included" ,
383
- )
384
- }
385
- }
386
-
387
- return diags
388
- }
344
+ //
345
+ // // ValidateToolVersion provides common validation for tool version resources
346
+ // func ValidateToolVersion(ctx context.Context, url, sha types.String, archs types.Set, resourceType string) diag.Diagnostics {
347
+ // var diags diag.Diagnostics
348
+
349
+ // urlPresent := !url.IsNull() && !url.IsUnknown()
350
+ // shaPresent := !sha.IsNull() && !sha.IsUnknown()
351
+
352
+ // // If URL or SHA is not set, we will rely on the archs attribute
353
+ // if !urlPresent || !shaPresent {
354
+ // return diags
355
+ // }
356
+
357
+ // // If archs aren't present, we can't validate against them
358
+ // if archs.IsNull() || archs.IsUnknown() {
359
+ // return diags
360
+ // }
361
+
362
+ // // Extract archs
363
+ // var archsList []ToolArchitecture
364
+ // archDiags := archs.ElementsAs(ctx, &archsList, false)
365
+ // if archDiags.HasError() {
366
+ // diags.Append(archDiags...)
367
+ // return diags
368
+ // }
369
+
370
+ // // Check for AMD64 architecture
371
+ // hasAMD64 := false
372
+ // var amd64Arch ToolArchitecture
373
+ // for _, arch := range archsList {
374
+ // if arch.Arch.ValueString() == "amd64" {
375
+ // hasAMD64 = true
376
+ // amd64Arch = arch
377
+ // break
378
+ // }
379
+ // }
380
+
381
+ // // If top-level URL/SHA are set and no AMD64 arch found, add error
382
+ // if !hasAMD64 {
383
+ // diags.AddError(
384
+ // fmt.Sprintf("Missing AMD64 architecture in %s", resourceType),
385
+ // "When specifying both top-level URL/SHA and archs, an AMD64 architecture entry must be included",
386
+ // )
387
+ // return diags
388
+ // }
389
+
390
+ // // If URL and SHA are set at top level, check they match AMD64 arch
391
+ // if url.ValueString() != amd64Arch.URL.ValueString() {
392
+ // diags.AddError(
393
+ // fmt.Sprintf("Inconsistent %s URL values", resourceType),
394
+ // fmt.Sprintf("Top-level URL (%s) doesn't match AMD64 architecture URL (%s)",
395
+ // url.ValueString(), amd64Arch.URL.ValueString()),
396
+ // )
397
+ // }
398
+
399
+ // // Check SHA matches
400
+ // if sha.ValueString() != amd64Arch.Sha.ValueString() {
401
+ // diags.AddError(
402
+ // fmt.Sprintf("Inconsistent %s SHA values", resourceType),
403
+ // fmt.Sprintf("Top-level SHA (%s) doesn't match AMD64 architecture SHA (%s)",
404
+ // sha.ValueString(), amd64Arch.Sha.ValueString()),
405
+ // )
406
+ // }
407
+
408
+ // return diags
409
+ // }
0 commit comments