diff --git a/main.tf b/main.tf index 6caae8b..de40960 100644 --- a/main.tf +++ b/main.tf @@ -63,6 +63,31 @@ module "efs" { } +resource "aws_service_discovery_service" "main" { + count = var.public == true ? 0 : 1 + name = "${var.namespace}-${var.env}-${local.ecs_service_name}" + + tags = { + env = var.env + Env = var.env + Name = local.ecs_service_name + } + + dns_config { + namespace_id = var.service_discovery_id + routing_policy = "MULTIVALUE" + + dns_records { + ttl = 10 + type = "A" + } + } + + health_check_custom_config { + failure_threshold = 1 + } +} + module "service" { source = "./ecs-modules/ecs-service" @@ -184,6 +209,13 @@ module "service" { PROXY_ENABLED = var.web_proxy_enabled ? "true" : "false" } ) + + dynamic service_registries { + for_each = var.public ? [] : [1] + content { + registry_arn = aws_service_discovery_service.main[0].arn + } + } } resource "aws_route53_record" "alb" { diff --git a/variables.tf b/variables.tf index f251bc5..6b8f46a 100644 --- a/variables.tf +++ b/variables.tf @@ -697,6 +697,12 @@ variable "cpu_architecture" { default = "X86_64" } +variable "service_discovery_id" { + type = string + description = "When you use Service Discovery" + default = "" +} + variable "ecr_force_delete" { default = false description = "If true, will delete the ECR repository even if it contains images."