From 548c6993f5e183d286a784add4eb0ba0ba20d94b Mon Sep 17 00:00:00 2001 From: Fredrik Oterholt Date: Fri, 8 Dec 2023 13:55:33 +0100 Subject: [PATCH] Add option to set a healthCheck property on the task container definition (#91) --- examples/basic/main.tf | 8 ++++++++ main.tf | 3 ++- variables.tf | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 16cb92d..49b10de 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -112,6 +112,14 @@ module "fargate" { TEST_VARIABLE = "TEST_VALUE" } + task_container_health_check = { + retries = 3, + command = ["CMD-SHELL", "curl -f http://localhost:9000/ || exit 1"], + timeout = 5, + interval = 30, + startPeriod = 15 + } + health_check = { port = "traffic-port" path = "/" diff --git a/main.tf b/main.tf index 920c669..42b7120 100644 --- a/main.tf +++ b/main.tf @@ -137,6 +137,7 @@ locals { log_multiline_pattern = var.log_multiline_pattern != "" ? { "awslogs-multiline-pattern" = var.log_multiline_pattern } : null task_container_secrets = length(var.task_container_secrets) > 0 ? { "secrets" = var.task_container_secrets } : null repository_credentials = length(var.repository_credentials) > 0 ? { "repositoryCredentials" = { "credentialsParameter" = var.repository_credentials } } : null + task_container_health_check = length(var.task_container_health_check) > 0 ? { "healthCheck" = var.task_container_health_check } : null task_container_port_mappings = var.task_container_port == 0 ? var.task_container_port_mappings : concat(var.task_container_port_mappings, [{ containerPort = var.task_container_port, hostPort = var.task_container_port, protocol = "tcp" }]) task_container_environment = [for k, v in var.task_container_environment : { name = k, value = v }] task_container_mount_points = concat([for v in var.efs_volumes : { containerPath = v.mount_point, readOnly = v.readOnly, sourceVolume = v.name }], var.mount_points) @@ -163,7 +164,7 @@ locals { } "privileged" : var.privileged "readonlyRootFilesystem" : var.readonlyRootFilesystem - }, local.task_container_secrets, local.repository_credentials) + }, local.task_container_secrets, local.repository_credentials, local.task_container_health_check) } resource "aws_ecs_task_definition" "task" { diff --git a/variables.tf b/variables.tf index 1a74d87..36dec86 100644 --- a/variables.tf +++ b/variables.tf @@ -24,6 +24,11 @@ variable "task_container_secrets_kms_key" { default = "alias/aws/secretsmanager" } +variable "task_container_health_check" { + description = "https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html" + default = "" +} + variable "vpc_id" { description = "The VPC ID." type = string