Skip to content

Commit

Permalink
Add option to set a healthCheck property on the task container defini…
Browse files Browse the repository at this point in the history
…tion (#91)
  • Loading branch information
k1rd3rf authored Dec 8, 2023
1 parent 1aab526 commit 548c699
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/"
Expand Down
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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" {
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 548c699

Please sign in to comment.