From a736b9930ad67599fd492110dc9767cb3406ca40 Mon Sep 17 00:00:00 2001 From: Adam Tyler Date: Mon, 1 Feb 2021 16:12:56 -0500 Subject: [PATCH 1/5] Add ForceNew to ecs_service service_registries --- aws/resource_aws_ecs_service.go | 4 + aws/resource_aws_ecs_service_test.go | 135 +++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index 147946bb222..4ab7cb3dbbb 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -340,24 +340,28 @@ func resourceAwsEcsService() *schema.Resource { Type: schema.TypeString, ForceNew: true, Optional: true, + ForceNew: true, }, "container_port": { Type: schema.TypeInt, ForceNew: true, Optional: true, ValidateFunc: validation.IntBetween(0, 65536), + ForceNew: true, }, "port": { Type: schema.TypeInt, ForceNew: true, Optional: true, ValidateFunc: validation.IntBetween(0, 65536), + ForceNew: true, }, "registry_arn": { Type: schema.TypeString, ForceNew: true, Required: true, ValidateFunc: validateArn, + ForceNew: true, }, }, }, diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 1ba8a542e20..75c36aab1e6 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -1165,6 +1165,40 @@ func TestAccAWSEcsService_withServiceRegistries_container(t *testing.T) { }) } +// Regression for +func TestAccAWSEcsService_withServiceRegistriesChanges(t *testing.T) { + var service ecs.Service + rString := acctest.RandString(8) + + serviceDiscoveryName := fmt.Sprintf("tf-acc-sd-%s", rString) + updatedServiceDiscoveryName := fmt.Sprintf("tf-acc-sd-%s-updated", rString) + clusterName := fmt.Sprintf("tf-acc-cluster-svc-w-ups-%s", rString) + tdName := fmt.Sprintf("tf-acc-td-svc-w-ups-%s", rString) + svcName := fmt.Sprintf("tf-acc-svc-w-ups-%s", rString) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(servicediscovery.EndpointsID, t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEcsServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEcsService_withServiceRegistriesChanges(rString, serviceDiscoveryName, clusterName, tdName, svcName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists("aws_ecs_service.test", &service), + resource.TestCheckResourceAttr("aws_ecs_service.test", "service_registries.#", "1"), + ), + }, + { + Config: testAccAWSEcsService_withServiceRegistriesChanges(rString, updatedServiceDiscoveryName, clusterName, tdName, svcName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsServiceExists("aws_ecs_service.test", &service), + resource.TestCheckResourceAttr("aws_ecs_service.test", "service_registries.#", "1"), + ), + }, + }, + }) +} + func TestAccAWSEcsService_Tags(t *testing.T) { var service ecs.Service rName := acctest.RandomWithPrefix("tf-acc-test") @@ -3491,6 +3525,107 @@ resource "aws_ecs_service" "test" { `, rName, rName, rName, clusterName, tdName, svcName) } +func testAccAWSEcsService_withServiceRegistriesChanges(rName, discoveryName, clusterName, tdName, svcName string) string { + return fmt.Sprintf(` +data "aws_availability_zones" "test" { + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } +} + +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" { + name = "tf-acc-sg-%s" + vpc_id = aws_vpc.test.id + + ingress { + protocol = "-1" + from_port = 0 + to_port = 0 + cidr_blocks = [aws_vpc.test.cidr_block] + } +} + +resource "aws_service_discovery_private_dns_namespace" "test" { + name = "%s.terraform.local" + description = "test" + vpc = aws_vpc.test.id +} + +resource "aws_service_discovery_service" "test" { + name = "%s" + + dns_config { + namespace_id = aws_service_discovery_private_dns_namespace.test.id + + dns_records { + ttl = 5 + type = "SRV" + } + } +} + +resource "aws_ecs_cluster" "test" { + name = "%s" +} + +resource "aws_ecs_task_definition" "test" { + family = "%s" + network_mode = "awsvpc" + + container_definitions = < Date: Fri, 12 Feb 2021 15:45:00 -0500 Subject: [PATCH 2/5] Create CHANGELOG entry --- .changelog/17387.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17387.txt diff --git a/.changelog/17387.txt b/.changelog/17387.txt new file mode 100644 index 00000000000..6d944e503fc --- /dev/null +++ b/.changelog/17387.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ecs_service: Re-create service when service_registries changed +``` From d4669495c00de0e809a7e3e4d19e9171a4671c0c Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 25 Mar 2021 13:16:45 -0400 Subject: [PATCH 3/5] r/ecs_service: Remove duplicate fields --- aws/resource_aws_ecs_service.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index 4ab7cb3dbbb..147946bb222 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -340,28 +340,24 @@ func resourceAwsEcsService() *schema.Resource { Type: schema.TypeString, ForceNew: true, Optional: true, - ForceNew: true, }, "container_port": { Type: schema.TypeInt, ForceNew: true, Optional: true, ValidateFunc: validation.IntBetween(0, 65536), - ForceNew: true, }, "port": { Type: schema.TypeInt, ForceNew: true, Optional: true, ValidateFunc: validation.IntBetween(0, 65536), - ForceNew: true, }, "registry_arn": { Type: schema.TypeString, ForceNew: true, Required: true, ValidateFunc: validateArn, - ForceNew: true, }, }, }, From 12a6d2b9a75ddfa13d9ff3df061f9d25c70565bf Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 25 Mar 2021 13:26:04 -0400 Subject: [PATCH 4/5] tests/r/ecs_service: Add ErrorCheck --- aws/resource_aws_ecs_service_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 75c36aab1e6..7f0f60fac09 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -1178,6 +1178,7 @@ func TestAccAWSEcsService_withServiceRegistriesChanges(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(servicediscovery.EndpointsID, t) }, + ErrorCheck: testAccErrorCheck(t, ecs.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSEcsServiceDestroy, Steps: []resource.TestStep{ From 1281fe3909f41b9c1062801efd796928133472e9 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 25 Mar 2021 13:41:19 -0400 Subject: [PATCH 5/5] ecs_service: Update changelog, tests --- .changelog/17387.txt | 2 +- aws/resource_aws_ecs_service_test.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.changelog/17387.txt b/.changelog/17387.txt index 6d944e503fc..ad02895c6e8 100644 --- a/.changelog/17387.txt +++ b/.changelog/17387.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_ecs_service: Re-create service when service_registries changed +resource/aws_ecs_service: Re-create service when `service_registries` changes ``` diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index 7f0f60fac09..8d57b8627f3 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -1165,7 +1165,6 @@ func TestAccAWSEcsService_withServiceRegistries_container(t *testing.T) { }) } -// Regression for func TestAccAWSEcsService_withServiceRegistriesChanges(t *testing.T) { var service ecs.Service rString := acctest.RandString(8)