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

Add ForceNew to ecs_service service_registries #17387

Merged
merged 5 commits into from
Mar 25, 2021
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
3 changes: 3 additions & 0 deletions .changelog/17387.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecs_service: Re-create service when `service_registries` changes
```
135 changes: 135 additions & 0 deletions aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = <<DEFINITION
[
{
"cpu": 128,
"essential": true,
"image": "mongo:latest",
"memory": 128,
"name": "mongodb"
}
]
DEFINITION
}

resource "aws_ecs_service" "test" {
name = "%s"
cluster = aws_ecs_cluster.test.id
task_definition = aws_ecs_task_definition.test.arn
desired_count = 1

service_registries {
port = 34567
registry_arn = aws_service_discovery_service.test.arn
}

network_configuration {
security_groups = [aws_security_group.test.id]
subnets = aws_subnet.test[*].id
}
}
`, rName, discoveryName, discoveryName, clusterName, tdName, svcName)
}

func testAccAWSEcsServiceWithDaemonSchedulingStrategy(clusterName, tdName, svcName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "default" {
Expand Down