diff --git a/alb.tf b/alb.tf
index 5fe50a8..4142de4 100644
--- a/alb.tf
+++ b/alb.tf
@@ -37,6 +37,10 @@ resource "aws_alb_target_group" "main" {
matcher = lookup(health_check.value, "matcher", null)
}
}
+
+ lifecycle {
+ create_before_destroy = true
+ }
}
resource "aws_alb_listener_rule" "public" {
diff --git a/examples/complete/README.md b/examples/complete/README.md
index 6dfdb6b..49ba9bf 100644
--- a/examples/complete/README.md
+++ b/examples/complete/README.md
@@ -36,8 +36,8 @@ Note that this example may create resources which cost money. Run `terraform des
|------|--------|---------|
| [alb\_security\_group\_public](#module\_alb\_security\_group\_public) | registry.terraform.io/terraform-aws-modules/security-group/aws | >= 4.17 |
| [service](#module\_service) | ../../ | n/a |
-| [vpc](#module\_vpc) | registry.terraform.io/terraform-aws-modules/vpc/aws | >= 3.18 |
-| [vpc\_endpoints](#module\_vpc\_endpoints) | registry.terraform.io/terraform-aws-modules/vpc/aws//modules/vpc-endpoints | >= 3.18 |
+| [vpc](#module\_vpc) | registry.terraform.io/terraform-aws-modules/vpc/aws | >= 4.0 |
+| [vpc\_endpoints](#module\_vpc\_endpoints) | registry.terraform.io/terraform-aws-modules/vpc/aws//modules/vpc-endpoints | >= 4.0 |
## Resources
diff --git a/examples/complete/main.tf b/examples/complete/main.tf
index 4664515..aa08ee7 100644
--- a/examples/complete/main.tf
+++ b/examples/complete/main.tf
@@ -1,20 +1,19 @@
locals {
container_port = 8000
image_tag = "production"
- service_name = "${random_pet.this.id}-service"
}
resource "random_pet" "this" {
- length = 2
+ length = 1
}
resource "aws_ecs_cluster" "this" {
- name = "${random_pet.this.id}-cluster"
+ name = random_pet.this.id
}
module "vpc" {
source = "registry.terraform.io/terraform-aws-modules/vpc/aws"
- version = ">= 3.18"
+ version = ">= 4.0"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
cidr = "10.0.0.0/16"
@@ -35,7 +34,7 @@ module "vpc" {
// see https://docs.aws.amazon.com/AmazonECR/latest/userguide/vpc-endpoints.html for necessary endpoints to run Fargate tasks
module "vpc_endpoints" {
source = "registry.terraform.io/terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
- version = ">= 3.18"
+ version = ">= 4.0"
security_group_ids = [data.aws_security_group.default.id]
vpc_id = module.vpc.vpc_id
@@ -118,7 +117,7 @@ module "service" {
desired_count = 1
ecr_force_delete = true
memory = 512
- service_name = local.service_name
+ service_name = random_pet.this.id
vpc_id = module.vpc.vpc_id
ecr_image_tag = local.image_tag
@@ -152,7 +151,7 @@ module "service" {
// add a target group to route ALB traffic to this service
target_groups = [
{
- name = "${local.service_name}-public"
+ name_prefix = "${substr(random_pet.this.id, 0, 5)}-"
backend_protocol = "HTTP"
backend_port = local.container_port
load_balancer_arn = aws_lb_listener.http.load_balancer_arn