From c4d091fd712045edc2d1a41bdb4d2dac201cb20e Mon Sep 17 00:00:00 2001 From: CaerusKaru Date: Fri, 9 Feb 2024 00:18:20 +0000 Subject: [PATCH] feat: add backwards compatibility to the service block --- examples/fargate/main.tf | 16 +++++++--------- modules/service/main.tf | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/fargate/main.tf b/examples/fargate/main.tf index ea1b6c2..438971b 100644 --- a/examples/fargate/main.tf +++ b/examples/fargate/main.tf @@ -126,16 +126,14 @@ module "ecs_service" { service_connect_configuration = { namespace = aws_service_discovery_http_namespace.this.arn - service = [ - { - client_alias = { - port = local.container_port - dns_name = local.container_name - } - port_name = local.container_name - discovery_name = local.container_name + service = { + client_alias = { + port = local.container_port + dns_name = local.container_name } - ] + port_name = local.container_name + discovery_name = local.container_name + } } load_balancer = { diff --git a/modules/service/main.tf b/modules/service/main.tf index c024b52..97b3dda 100644 --- a/modules/service/main.tf +++ b/modules/service/main.tf @@ -153,7 +153,7 @@ resource "aws_ecs_service" "this" { namespace = lookup(service_connect_configuration.value, "namespace", null) dynamic "service" { - for_each = try(service_connect_configuration.value.service, []) + for_each = try(lookup(service_connect_configuration.value.service, "port_name") != null ? [service_connect_configuration.value.service] : [], try(service_connect_configuration.value.service, [])) content { @@ -339,7 +339,7 @@ resource "aws_ecs_service" "ignore_task_definition" { namespace = lookup(service_connect_configuration.value, "namespace", null) dynamic "service" { - for_each = try(service_connect_configuration.value.service, []) + for_each = try(lookup(service_connect_configuration.value.service, "port_name") != null ? [service_connect_configuration.value.service] : [], try(service_connect_configuration.value.service, [])) content {