diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index c8ba15a4952..1f8ab812de1 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -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": { @@ -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": { @@ -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), }, }, }, @@ -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, @@ -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, @@ -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) } diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 45496aa9bd9..53f43dc934a 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -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, @@ -336,8 +331,7 @@ 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"), ), }, @@ -345,8 +339,7 @@ func TestAccAWSEcsService_withRenamedCluster(t *testing.T) { 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"), ), }, }, @@ -2687,6 +2680,10 @@ 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" { @@ -2694,6 +2691,10 @@ resource "aws_subnet" "test" { 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" { @@ -2773,6 +2774,10 @@ 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" { @@ -2780,6 +2785,10 @@ resource "aws_subnet" "test" { 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" {