Skip to content

Commit

Permalink
validate force new based on AWS docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lmml-dwp authored and YakDriver committed Nov 24, 2021
1 parent 1e6d287 commit 4b349e0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/service/ecs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ecs

import (
"bytes"
"context"
"fmt"
"log"
"math"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -44,27 +46,24 @@ func ResourceService() *schema.Resource {
"capacity_provider_strategy": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"base": {
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Optional: true,

ValidateFunc: validation.IntBetween(0, 100000),
ForceNew: true,
},

"capacity_provider": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"weight": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 1000),
ForceNew: true,
},
},
},
Expand Down Expand Up @@ -383,6 +382,15 @@ func ResourceService() *schema.Resource {
Default: false,
},
},

CustomizeDiff: customdiff.All(
customdiff.ForceNewIfChange("capacity_provider_strategy", func(_ context.Context, old, new, _ interface{}) bool {
ol := old.(*schema.Set).Len()
nl := new.(*schema.Set).Len()

return (ol == 0 && nl > 0) || (ol > 0 && nl == 0)
}),
),
}
}

Expand Down

0 comments on commit 4b349e0

Please sign in to comment.