Skip to content

Commit

Permalink
fix: Adding a health_check generates a new task definition revision…
Browse files Browse the repository at this point in the history
… on every `terraform apply` (#149)

* fix: Adding a `health_check` generates a new task definition revision on every `terraform apply`

* Reformat code
  • Loading branch information
sestrella committed Dec 21, 2023
1 parent 32f1169 commit 492e323
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion modules/container-definition/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 492e323

Please sign in to comment.