Skip to content

Commit

Permalink
resource/aws_ecs_service: Retry on IAM SLR eventual consistency error…
Browse files Browse the repository at this point in the history
…, add attribute validation (#11423)

Output from acceptance testing:

```
--- PASS: TestAccAWSEcsService_basicImport (71.79s)
--- PASS: TestAccAWSEcsService_disappears (57.94s)
--- PASS: TestAccAWSEcsService_healthCheckGracePeriodSeconds (276.32s)
--- PASS: TestAccAWSEcsService_ManagedTags (52.67s)
--- PASS: TestAccAWSEcsService_PropagateTags (183.42s)
--- PASS: TestAccAWSEcsService_Tags (64.17s)
--- PASS: TestAccAWSEcsService_withAlb (259.80s)
--- PASS: TestAccAWSEcsService_withARN (79.09s)
--- PASS: TestAccAWSEcsService_withCapacityProviderStrategy (176.03s)
--- PASS: TestAccAWSEcsService_withDaemonSchedulingStrategy (53.32s)
--- PASS: TestAccAWSEcsService_withDaemonSchedulingStrategySetDeploymentMinimum (43.60s)
--- PASS: TestAccAWSEcsService_withDeploymentController_Type_CodeDeploy (280.11s)
--- PASS: TestAccAWSEcsService_withDeploymentMinimumZeroMaximumOneHundred (72.30s)
--- PASS: TestAccAWSEcsService_withDeploymentValues (72.28s)
--- PASS: TestAccAWSEcsService_withEcsClusterName (81.11s)
--- PASS: TestAccAWSEcsService_withFamilyAndRevision (76.29s)
--- PASS: TestAccAWSEcsService_withIamRole (156.20s)
--- PASS: TestAccAWSEcsService_withLaunchTypeEC2AndNetworkConfiguration (74.68s)
--- PASS: TestAccAWSEcsService_withLaunchTypeFargate (111.62s)
--- PASS: TestAccAWSEcsService_withLaunchTypeFargateAndPlatformVersion (172.06s)
--- PASS: TestAccAWSEcsService_withLbChanges (166.77s)
--- PASS: TestAccAWSEcsService_withMultipleCapacityProviderStrategies (124.27s)
--- PASS: TestAccAWSEcsService_withMultipleTargetGroups (310.64s)
--- PASS: TestAccAWSEcsService_withPlacementConstraints (73.55s)
--- PASS: TestAccAWSEcsService_withPlacementConstraints_emptyExpression (72.31s)
--- PASS: TestAccAWSEcsService_withPlacementStrategy (203.05s)
--- PASS: TestAccAWSEcsService_withRenamedCluster (102.43s)
--- PASS: TestAccAWSEcsService_withReplicaSchedulingStrategy (73.27s)
--- PASS: TestAccAWSEcsService_withServiceRegistries (152.38s)
--- PASS: TestAccAWSEcsService_withServiceRegistries_container (142.99s)
--- PASS: TestAccAWSEcsService_withUnnormalizedPlacementStrategy (71.10s)
--- PASS: TestAccAWSEcsServiceDataSource_basic (73.13s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Jan 3, 2020
1 parent 1b644dc commit 1d5f9dd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
31 changes: 25 additions & 6 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func resourceAwsEcsService() *schema.Resource {
ForceNew: true,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
ecs.LaunchTypeEc2,
ecs.LaunchTypeFargate,
}, false),
},

"platform_version": {
Expand Down Expand Up @@ -190,9 +194,10 @@ func resourceAwsEcsService() *schema.Resource {
},

"target_group_arn": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateArn,
},

"container_name": {
Expand All @@ -202,9 +207,10 @@ func resourceAwsEcsService() *schema.Resource {
},

"container_port": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(0, 65536),
},
},
},
Expand Down Expand Up @@ -247,6 +253,11 @@ func resourceAwsEcsService() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
ecs.PlacementStrategyTypeBinpack,
ecs.PlacementStrategyTypeRandom,
ecs.PlacementStrategyTypeSpread,
}, false),
},
"field": {
Type: schema.TypeString,
Expand Down Expand Up @@ -299,6 +310,10 @@ func resourceAwsEcsService() *schema.Resource {
Type: schema.TypeString,
ForceNew: true,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
ecs.PlacementConstraintTypeDistinctInstance,
ecs.PlacementConstraintTypeMemberOf,
}, false),
},
"expression": {
Type: schema.TypeString,
Expand Down Expand Up @@ -512,6 +527,10 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error
if isAWSErr(err, ecs.ErrCodeInvalidParameterException, "does not have an associated load balancer") {
return resource.RetryableError(err)
}
if isAWSErr(err, ecs.ErrCodeInvalidParameterException, "Unable to assume the service linked role."+
" Please verify that the ECS service linked role exists") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}

Expand Down
27 changes: 18 additions & 9 deletions aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,6 @@ func TestAccAWSEcsService_withRenamedCluster(t *testing.T) {
tdName := fmt.Sprintf("tf-acc-td-svc-w-rc-%s", rString)
svcName := fmt.Sprintf("tf-acc-svc-w-rc-%s", rString)

originalRegexp := regexp.MustCompile(
"^arn:aws:ecs:[^:]+:[0-9]+:cluster/" + clusterName + "$")
modifiedRegexp := regexp.MustCompile(
"^arn:aws:ecs:[^:]+:[0-9]+:cluster/" + uClusterName + "$")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -336,17 +331,15 @@ func TestAccAWSEcsService_withRenamedCluster(t *testing.T) {
Config: testAccAWSEcsServiceWithRenamedCluster(clusterName, tdName, svcName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost", &service),
resource.TestMatchResourceAttr(
"aws_ecs_service.ghost", "cluster", originalRegexp),
resource.TestCheckResourceAttrPair("aws_ecs_service.ghost", "cluster", "aws_ecs_cluster.default", "arn"),
),
},

{
Config: testAccAWSEcsServiceWithRenamedCluster(uClusterName, tdName, svcName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost", &service),
resource.TestMatchResourceAttr(
"aws_ecs_service.ghost", "cluster", modifiedRegexp),
resource.TestCheckResourceAttrPair("aws_ecs_service.ghost", "cluster", "aws_ecs_cluster.default", "arn"),
),
},
},
Expand Down Expand Up @@ -2687,13 +2680,21 @@ data "aws_availability_zones" "test" {}
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "tf-acc-with-svc-reg"
}
}
resource "aws_subnet" "test" {
count = 2
cidr_block = "${cidrsubnet(aws_vpc.test.cidr_block, 8, count.index)}"
availability_zone = "${data.aws_availability_zones.test.names[count.index]}"
vpc_id = "${aws_vpc.test.id}"
tags = {
Name = "tf-acc-with-svc-reg"
}
}
resource "aws_security_group" "test" {
Expand Down Expand Up @@ -2773,13 +2774,21 @@ data "aws_availability_zones" "test" {}
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "tf-acc-with-svc-reg-cont"
}
}
resource "aws_subnet" "test" {
count = 2
cidr_block = "${cidrsubnet(aws_vpc.test.cidr_block, 8, count.index)}"
availability_zone = "${data.aws_availability_zones.test.names[count.index]}"
vpc_id = "${aws_vpc.test.id}"
tags = {
Name = "tf-acc-with-svc-reg"
}
}
resource "aws_security_group" "test" {
Expand Down

0 comments on commit 1d5f9dd

Please sign in to comment.