Skip to content

Commit e0bcc83

Browse files
committed
fix customdiff func
Only `force_new_deployment = true` is required in updating capacity_provider
1 parent e2cfbd1 commit e0bcc83

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

internal/service/ecs/service.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,31 +2337,11 @@ func triggersCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta any)
23372337
}
23382338

23392339
func capacityProviderStrategyCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta any) error {
2340-
// to be backward compatible, should ForceNew almost always (previous behavior), unless:
2341-
// force_new_deployment is true and
2342-
// neither the old set nor new set is 0 length
2343-
if v := d.Get("force_new_deployment").(bool); !v {
2344-
return capacityProviderStrategyForceNew(d)
2345-
}
2346-
2347-
old, new := d.GetChange(names.AttrCapacityProviderStrategy)
2348-
2349-
ol := old.(*schema.Set).Len()
2350-
nl := new.(*schema.Set).Len()
2351-
2352-
if (ol == 0 && nl > 0) || (ol > 0 && nl == 0) {
2353-
return capacityProviderStrategyForceNew(d)
2354-
}
2355-
2356-
return nil
2357-
}
2358-
2359-
func capacityProviderStrategyForceNew(d *schema.ResourceDiff) error {
2360-
for _, key := range d.GetChangedKeysPrefix(names.AttrCapacityProviderStrategy) {
2361-
if d.HasChange(key) {
2362-
if err := d.ForceNew(key); err != nil {
2363-
return fmt.Errorf("while attempting to force a new ECS service for capacity_provider_strategy: %w", err)
2364-
}
2340+
// This if-statement is true only when the resource is being updated.
2341+
// d.Id() != "" means the resource (ecs service) already exists.
2342+
if d.Id() != "" && d.HasChange(names.AttrCapacityProviderStrategy) {
2343+
if v := d.Get("force_new_deployment").(bool); !v {
2344+
return fmt.Errorf("force_new_deployment should be true when capacity_provider_strategy is being updated")
23652345
}
23662346
}
23672347
return nil

0 commit comments

Comments
 (0)