File tree Expand file tree Collapse file tree 4 files changed +12
-74
lines changed
Expand file tree Collapse file tree 4 files changed +12
-74
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ data "aws_region" "current" {}
66
77
88data "aws_lb_target_group" "TG" {
9- count = local. balanced ? 1 : 0
9+ count = local. balanced ? length (local . target_group_names ) : 0
1010
11- name = local. target_group_name
11+ name = local. target_group_names [ count . index ]
1212}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -29,8 +29,6 @@ resource "aws_ecs_service" "service" {
2929 deployment_minimum_healthy_percent = var. deployment_minimum_healthy_percent
3030 deployment_maximum_percent = var. deployment_maximum_percent
3131
32- iam_role = local. balanced ? aws_iam_role. task-role-alb [0 ]. arn : " "
33-
3432 ordered_placement_strategy {
3533 type = " spread"
3634 field = " attribute:ecs.availability-zone"
@@ -42,10 +40,10 @@ resource "aws_ecs_service" "service" {
4240 }
4341
4442 dynamic "load_balancer" {
45- for_each = local. balanced ? [ 1 ] : []
43+ for_each = local. balanced ? data . aws_lb_target_group . TG [ * ] . arn : []
4644
4745 content {
48- target_group_arn = data . aws_lb_target_group . TG [ 0 ] . arn
46+ target_group_arn = load_balancer . value
4947 container_name = var. service_name
5048 container_port = var. container_port
5149 }
Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ variable "target_group_name" {
1111 default = " "
1212}
1313
14+ variable "target_group_names" {
15+ description = " Names of the ALB target groups. Defaults to the `[cluster_name]` if not set"
16+ default = []
17+ }
18+
1419variable "environment" {
1520 description = " Enviropnment vars to pass to the container. Note: they will be visible in the task definition, so please don't pass any secrets here."
1621 type = map
@@ -80,8 +85,9 @@ variable "desired_count" {
8085}
8186
8287locals {
83- balanced = var. container_port > 0
84- target_group_name = coalesce (var. target_group_name , var. cluster_name )
88+ balanced = var. container_port > 0
89+
90+ target_group_names = coalescelist (distinct (compact (concat (var. target_group_names , list (var. target_group_name )))), list (var. cluster_name ))
8591
8692 default_log_configuration = {
8793 " logDriver" = " awslogs"
You can’t perform that action at this time.
0 commit comments