diff --git a/.changelog/17387.txt b/.changelog/17387.txt new file mode 100644 index 00000000000..ad02895c6e8 --- /dev/null +++ b/.changelog/17387.txt @@ -0,0 +1,3 @@ +```release-note:bug +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 1ba8a542e20..8d57b8627f3 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) { }) } +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) }, + ErrorCheck: testAccErrorCheck(t, ecs.EndpointsID), + 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 = <