From 5b2f59b13b954c59e6699626d357740dc1895567 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Wed, 25 Dec 2019 23:23:24 +0200 Subject: [PATCH 1/7] add arn validations add enum validations eventual consistency --- aws/resource_aws_ecs_service.go | 40 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index c8ba15a4952..1ddee4a0ec7 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": { @@ -120,10 +124,11 @@ func resourceAwsEcsService() *schema.Resource { }, "iam_role": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Computed: true, + Type: schema.TypeString, + ForceNew: true, + Optional: true, + Computed: true, + ValidateFunc: validateArn, }, "deployment_controller": { @@ -190,9 +195,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 +208,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 +254,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 +311,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 +528,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) } From 25ce049aef95bfc731a3873a95f81feb4e5bb38c Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Wed, 25 Dec 2019 23:32:27 +0200 Subject: [PATCH 2/7] check arn test change --- aws/resource_aws_ecs_service_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 45496aa9bd9..52d510d8946 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -322,10 +322,10 @@ 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 + "$") + //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) }, @@ -336,8 +336,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), + testAccCheckResourceAttrRegionalARN("aws_ecs_service.ghost", "cluster", "ecs", "cluster/"+clusterName+"$"), ), }, @@ -345,8 +344,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), + testAccCheckResourceAttrRegionalARN("aws_ecs_service.ghost", "cluster", "ecs", "cluster/"+uClusterName+"$"), ), }, }, From 96cd1ea3da19307bd148b606132faf811468cc9e Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Wed, 25 Dec 2019 23:41:53 +0200 Subject: [PATCH 3/7] remove role arn validation --- aws/resource_aws_ecs_service.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index 1ddee4a0ec7..1f8ab812de1 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -124,11 +124,10 @@ func resourceAwsEcsService() *schema.Resource { }, "iam_role": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Computed: true, - ValidateFunc: validateArn, + Type: schema.TypeString, + ForceNew: true, + Optional: true, + Computed: true, }, "deployment_controller": { From 05781edc20181c1c7c4b5d1e8e8982a8076c5ac8 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Thu, 26 Dec 2019 00:04:03 +0200 Subject: [PATCH 4/7] remove commented out code --- aws/resource_aws_ecs_service_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 52d510d8946..b4ac2a6ea7c 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, From e494a3c551aff3543d1d803b3174c7213a96b410 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Thu, 2 Jan 2020 21:58:55 +0200 Subject: [PATCH 5/7] Update aws/resource_aws_ecs_service_test.go comments Co-Authored-By: Brian Flad --- aws/resource_aws_ecs_service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index b4ac2a6ea7c..7a02fdabc4f 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -331,7 +331,7 @@ func TestAccAWSEcsService_withRenamedCluster(t *testing.T) { Config: testAccAWSEcsServiceWithRenamedCluster(clusterName, tdName, svcName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost", &service), - testAccCheckResourceAttrRegionalARN("aws_ecs_service.ghost", "cluster", "ecs", "cluster/"+clusterName+"$"), + resource.TestCheckResourceAttrPair("aws_ecs_service.ghost", "cluster", "aws_ecs_cluster.default", "arn"), ), }, From 124a143cf2b0c56e9f97e327a567ced57af1c341 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Thu, 2 Jan 2020 22:26:04 +0200 Subject: [PATCH 6/7] add name tags to test resources --- aws/resource_aws_ecs_service_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 7a02fdabc4f..6117510c4ae 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -2680,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" { @@ -2687,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" { @@ -2766,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" { @@ -2773,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" { From b03027b77c8993d673e050caacf25bdb8fc75b9b Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Thu, 2 Jan 2020 23:57:31 +0200 Subject: [PATCH 7/7] fix rename test --- aws/resource_aws_ecs_service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 6117510c4ae..53f43dc934a 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -339,7 +339,7 @@ func TestAccAWSEcsService_withRenamedCluster(t *testing.T) { Config: testAccAWSEcsServiceWithRenamedCluster(uClusterName, tdName, svcName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost", &service), - testAccCheckResourceAttrRegionalARN("aws_ecs_service.ghost", "cluster", "ecs", "cluster/"+uClusterName+"$"), + resource.TestCheckResourceAttrPair("aws_ecs_service.ghost", "cluster", "aws_ecs_cluster.default", "arn"), ), }, },