From 492e323c82447fcaecaa818dc9c258daa923f254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Estrella?= <2049686+sestrella@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:45:55 -0500 Subject: [PATCH] fix: Adding a `health_check` generates a new task definition revision on every `terraform apply` (#149) * fix: Adding a `health_check` generates a new task definition revision on every `terraform apply` * Reformat code --- examples/complete/main.tf | 5 +++++ modules/container-definition/main.tf | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index ff7d6c5..b7353bb 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -69,6 +69,11 @@ module "ecs" { memory = 1024 essential = true image = "public.ecr.aws/aws-containers/ecsdemo-frontend:776fd50" + + health_check = { + command = ["CMD-SHELL", "curl -f http://localhost:${local.container_port}/health || exit 1"] + } + port_mappings = [ { name = local.container_name diff --git a/modules/container-definition/main.tf b/modules/container-definition/main.tf index 1e06312..9f6018b 100644 --- a/modules/container-definition/main.tf +++ b/modules/container-definition/main.tf @@ -19,6 +19,12 @@ locals { linux_parameters = var.enable_execute_command ? merge({ "initProcessEnabled" : true }, var.linux_parameters) : merge({ "initProcessEnabled" : false }, var.linux_parameters) + health_check = length(var.health_check) > 0 ? merge({ + interval = 30, + retries = 3, + timeout = 5 + }, var.health_check) : null + definition = { command = length(var.command) > 0 ? var.command : null cpu = var.cpu @@ -34,7 +40,7 @@ locals { essential = var.essential extraHosts = local.is_not_windows && length(var.extra_hosts) > 0 ? var.extra_hosts : null firelensConfiguration = length(var.firelens_configuration) > 0 ? var.firelens_configuration : null - healthCheck = length(var.health_check) > 0 ? var.health_check : null + healthCheck = local.health_check hostname = var.hostname image = var.image interactive = var.interactive