Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ecs/task/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ We recommend creating the task definition using `image` or `image_name` + `image
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | Environment variables to pass to a container. | `map(string)` | `{}` | no |
| <a name="input_essential"></a> [essential](#input\_essential) | If the essential parameter of a container is marked as true, and that container fails or stops for any reason, all other containers that are part of the task are stopped. | `bool` | `true` | no |
| <a name="input_execution_role_arn"></a> [execution\_role\_arn](#input\_execution\_role\_arn) | The ARN of IAM role that allows ECS to execute your task.<br><br>Required when:<br>- using `environment_parameters` to give ECS access to the SSM parameters<br>- using `launch_type = "FARGATE"` when running the task | `string` | `null` | no |
| <a name="input_healthcheck_command"></a> [healthcheck\_command](#input\_healthcheck\_command) | Command that the container runs to determine if it is healthy | `string` | `null` | no |
| <a name="input_healthcheck_interval"></a> [healthcheck\_interval](#input\_healthcheck\_interval) | The time period in seconds between each health check execution. You may specify between 5 and 300 seconds. | `number` | `30` | no |
| <a name="input_healthcheck_retries"></a> [healthcheck\_retries](#input\_healthcheck\_retries) | The number of times to retry a failed health check before the container is considered unhealthy. You may specify between 1 and 10 retries. | `number` | `2` | no |
| <a name="input_healthcheck_shell"></a> [healthcheck\_shell](#input\_healthcheck\_shell) | Whether the healthcheck\_command should be run using a shell | `bool` | `true` | no |
| <a name="input_healthcheck_start_period"></a> [healthcheck\_start\_period](#input\_healthcheck\_start\_period) | The optional grace period to provide containers time to bootstrap before failed health checks count towards the maximum number of retries. You can specify between 0 and 300 seconds. | `number` | `0` | no |
| <a name="input_healthcheck_timeout"></a> [healthcheck\_timeout](#input\_healthcheck\_timeout) | The time period in seconds to wait for a health check to succeed before it is considered a failure. You may specify between 2 and 60 seconds. | `number` | `5` | no |
| <a name="input_image"></a> [image](#input\_image) | Full container image name, including the version tag. Either image or image\_name has to be provided. | `string` | `null` | no |
| <a name="input_image_name"></a> [image\_name](#input\_image\_name) | Container image name, without the version tag. Either image or image\_name has to be provided. | `string` | `null` | no |
| <a name="input_image_tag"></a> [image\_tag](#input\_image\_tag) | Container image version tag, if omitted will use one from the latest revision. Used only when image\_name is provided. | `string` | `null` | no |
Expand Down
6 changes: 6 additions & 0 deletions ecs/task/container_definition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ No resources.
| <a name="input_environment_parameters"></a> [environment\_parameters](#input\_environment\_parameters) | Environment variables that should be set to Systems Manager parameter values.<br>Maps environment variable names to parameters. | <pre>map(object({<br> arn = string<br> version = number<br> }))</pre> | `{}` | no |
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | Environment variables to pass to a container. | `map(string)` | `{}` | no |
| <a name="input_essential"></a> [essential](#input\_essential) | If the essential parameter of a container is marked as true, and that container fails or stops for any reason, all other containers that are part of the task are stopped. | `bool` | `true` | no |
| <a name="input_healthcheck_command"></a> [healthcheck\_command](#input\_healthcheck\_command) | Command that the container runs to determine if it is healthy | `string` | `null` | no |
| <a name="input_healthcheck_interval"></a> [healthcheck\_interval](#input\_healthcheck\_interval) | The time period in seconds between each health check execution. You may specify between 5 and 300 seconds. | `number` | `30` | no |
| <a name="input_healthcheck_retries"></a> [healthcheck\_retries](#input\_healthcheck\_retries) | The number of times to retry a failed health check before the container is considered unhealthy. You may specify between 1 and 10 retries. | `number` | `2` | no |
| <a name="input_healthcheck_shell"></a> [healthcheck\_shell](#input\_healthcheck\_shell) | Whether the healthcheck\_command should be run using a shell | `bool` | `true` | no |
| <a name="input_healthcheck_start_period"></a> [healthcheck\_start\_period](#input\_healthcheck\_start\_period) | The optional grace period to provide containers time to bootstrap before failed health checks count towards the maximum number of retries. You can specify between 0 and 300 seconds. | `number` | `0` | no |
| <a name="input_healthcheck_timeout"></a> [healthcheck\_timeout](#input\_healthcheck\_timeout) | The time period in seconds to wait for a health check to succeed before it is considered a failure. You may specify between 2 and 60 seconds. | `number` | `5` | no |
| <a name="input_image"></a> [image](#input\_image) | Container image | `string` | n/a | yes |
| <a name="input_log_config"></a> [log\_config](#input\_log\_config) | jsonencodable logging configuration | `any` | `null` | no |
| <a name="input_memory_hard_limit"></a> [memory\_hard\_limit](#input\_memory\_hard\_limit) | The amount (in MiB) of memory to present to the container. If your container attempts to exceed the memory specified here, the container is killed. | `number` | `1024` | no |
Expand Down
9 changes: 9 additions & 0 deletions ecs/task/container_definition/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,14 @@ locals {
}]

logConfiguration = var.log_config

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html
healthCheck = var.healthcheck_command ? {
command = [var.healthcheck_shell ? "CMD-SHELL" : "CMD", var.healthcheck_command]
interval = var.healthcheck_interval
retries = var.healthcheck_retries
timeout = var.healthcheck_timeout
startPeriod = var.healthcheck_start_period
} : null
}
}
35 changes: 35 additions & 0 deletions ecs/task/container_definition/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,38 @@ variable "log_config" {
default = null
}

variable "healthcheck_command" {
description = "Command that the container runs to determine if it is healthy"
type = string
default = null
}

variable "healthcheck_shell" {
description = "Whether the healthcheck_command should be run using a shell"
type = bool
default = true
}

variable "healthcheck_interval" {
description = "The time period in seconds between each health check execution. You may specify between 5 and 300 seconds."
type = number
default = 30
}

variable "healthcheck_retries" {
description = "The number of times to retry a failed health check before the container is considered unhealthy. You may specify between 1 and 10 retries."
type = number
default = 2
}

variable "healthcheck_start_period" {
description = "The optional grace period to provide containers time to bootstrap before failed health checks count towards the maximum number of retries. You can specify between 0 and 300 seconds."
type = number
default = 0
}

variable "healthcheck_timeout" {
description = "The time period in seconds to wait for a health check to succeed before it is considered a failure. You may specify between 2 and 60 seconds."
type = number
default = 5
}
2 changes: 2 additions & 0 deletions ecs/task/examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module "httpbin" {
}

execution_role_arn = module.httpbin_execution_role.arn

healthcheck_command = "python3 -c \"import http.client, sys; conn = http.client.HTTPConnection('localhost'); conn.request('GET', '/'); sys.exit(0) if conn.getresponse().status == 200 else sys.exit(1)\""
}

output "httpbin_arn" {
Expand Down
7 changes: 7 additions & 0 deletions ecs/task/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ module "container" {
environment_parameters = var.environment_parameters
enable_environment_parameters_hash = var.enable_environment_parameters_hash
log_config = module.container_log.container_config

healthcheck_command = var.healthcheck_command
healthcheck_shell = var.healthcheck_shell
healthcheck_interval = var.healthcheck_interval
healthcheck_retries = var.healthcheck_retries
healthcheck_start_period = var.healthcheck_start_period
healthcheck_timeout = var.healthcheck_timeout
}

resource "aws_ecs_task_definition" "task" {
Expand Down
36 changes: 36 additions & 0 deletions ecs/task/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,39 @@ variable "placement_constraint_expressions" {
type = list(string)
default = []
}

variable "healthcheck_command" {
description = "Command that the container runs to determine if it is healthy"
type = string
default = null
}

variable "healthcheck_shell" {
description = "Whether the healthcheck_command should be run using a shell"
type = bool
default = true
}

variable "healthcheck_interval" {
description = "The time period in seconds between each health check execution. You may specify between 5 and 300 seconds."
type = number
default = 30
}

variable "healthcheck_retries" {
description = "The number of times to retry a failed health check before the container is considered unhealthy. You may specify between 1 and 10 retries."
type = number
default = 2
}

variable "healthcheck_start_period" {
description = "The optional grace period to provide containers time to bootstrap before failed health checks count towards the maximum number of retries. You can specify between 0 and 300 seconds."
type = number
default = 0
}

variable "healthcheck_timeout" {
description = "The time period in seconds to wait for a health check to succeed before it is considered a failure. You may specify between 2 and 60 seconds."
type = number
default = 5
}
Loading