Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECS Service enums + eventual consistency for service-role #11423

Merged
merged 7 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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