@@ -248,12 +248,8 @@ func resourceComputeEnvironmentCreate(d *schema.ResourceData, meta interface{})
248
248
Type : aws .String (computeEnvironmentType ),
249
249
}
250
250
251
- // TODO Check in CustomizeDiff that UNMANAGED compute environment has no compute_resources.
252
- // TODO This would be a breaking change.
253
- if computeEnvironmentType := strings .ToUpper (computeEnvironmentType ); computeEnvironmentType == batch .CETypeManaged {
254
- if v , ok := d .GetOk ("compute_resources" ); ok && len (v .([]interface {})) > 0 && v .([]interface {})[0 ] != nil {
255
- input .ComputeResources = expandBatchComputeResource (v .([]interface {})[0 ].(map [string ]interface {}))
256
- }
251
+ if v , ok := d .GetOk ("compute_resources" ); ok && len (v .([]interface {})) > 0 && v .([]interface {})[0 ] != nil {
252
+ input .ComputeResources = expandBatchComputeResource (v .([]interface {})[0 ].(map [string ]interface {}))
257
253
}
258
254
259
255
if v , ok := d .GetOk ("state" ); ok {
@@ -309,15 +305,12 @@ func resourceComputeEnvironmentRead(d *schema.ResourceData, meta interface{}) er
309
305
d .Set ("status_reason" , computeEnvironment .StatusReason )
310
306
d .Set ("type" , computeEnvironmentType )
311
307
312
- // TODO See above on how to remove check on type.
313
- if computeEnvironmentType == batch .CETypeManaged {
314
- if computeEnvironment .ComputeResources != nil {
315
- if err := d .Set ("compute_resources" , []interface {}{flattenBatchComputeResource (computeEnvironment .ComputeResources )}); err != nil {
316
- return fmt .Errorf ("error setting compute_resources: %w" , err )
317
- }
318
- } else {
319
- d .Set ("compute_resources" , nil )
308
+ if computeEnvironment .ComputeResources != nil {
309
+ if err := d .Set ("compute_resources" , []interface {}{flattenBatchComputeResource (computeEnvironment .ComputeResources )}); err != nil {
310
+ return fmt .Errorf ("error setting compute_resources: %w" , err )
320
311
}
312
+ } else {
313
+ d .Set ("compute_resources" , nil )
321
314
}
322
315
323
316
tags := KeyValueTags (computeEnvironment .Tags ).IgnoreAWS ().IgnoreConfig (ignoreTagsConfig )
@@ -350,7 +343,6 @@ func resourceComputeEnvironmentUpdate(d *schema.ResourceData, meta interface{})
350
343
input .State = aws .String (d .Get ("state" ).(string ))
351
344
}
352
345
353
- // TODO See above on how to remove check on type.
354
346
if computeEnvironmentType := strings .ToUpper (d .Get ("type" ).(string )); computeEnvironmentType == batch .CETypeManaged {
355
347
// "At least one compute-resources attribute must be specified"
356
348
computeResourceUpdate := & batch.ComputeResourceUpdate {
@@ -435,6 +427,13 @@ func resourceComputeEnvironmentDelete(d *schema.ResourceData, meta interface{})
435
427
}
436
428
437
429
func resourceComputeEnvironmentCustomizeDiff (_ context.Context , diff * schema.ResourceDiff , meta interface {}) error {
430
+ if computeEnvironmentType := strings .ToUpper (diff .Get ("type" ).(string )); computeEnvironmentType == batch .CETypeUnmanaged {
431
+ // UNMANAGED compute environments can have no compute_resources configured.
432
+ if v , ok := diff .GetOk ("compute_resources" ); ok && len (v .([]interface {})) > 0 && v .([]interface {})[0 ] != nil {
433
+ return fmt .Errorf ("no `compute_resources` can be specified when `type` is %q" , computeEnvironmentType )
434
+ }
435
+ }
436
+
438
437
if diff .Id () != "" {
439
438
// Update.
440
439
0 commit comments