Skip to content

Commit 36999bc

Browse files
authored
add optional task healthcheck (#1)
1 parent 6ab9ec5 commit 36999bc

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

README.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,50 @@ Module is to be used with Terraform > 0.12.
4242
Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](https://www.linkedin.com/in/marcincuber/).
4343

4444
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
45+
## Providers
46+
47+
| Name | Version |
48+
|------|---------|
49+
| aws | n/a |
50+
4551
## Inputs
4652

4753
| Name | Description | Type | Default | Required |
48-
|------|-------------|:----:|:-----:|:-----:|
49-
| cloudwatch\_log\_group\_name | CloudWatch log group name required to enabled logDriver in container definitions for ecs task. | string | `""` | no |
50-
| container\_name | Optional name for the container to be used instead of name\_prefix. | string | `""` | no |
51-
| docker\_volume\_configuration | \(Optional\) Used to configure a docker volume option "docker\_volume\_configuration". Full set of options can be found at https://www.terraform.io/docs/providers/aws/r/ecs\_task\_definition.html | list | `[]` | no |
52-
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | bool | `"true"` | no |
53-
| name\_prefix | A prefix used for naming resources. | string | n/a | yes |
54-
| placement\_constraints | \(Optional\) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10. This is a list of maps, where each map should contain "type" and "expression" | list | `[]` | no |
55-
| proxy\_configuration | \(Optional\) The proxy configuration details for the App Mesh proxy. This is a list of maps, where each map should contain "container\_name", "properties" and "type" | list | `[]` | no |
56-
| repository\_credentials | name or ARN of a secrets manager secret \(arn:aws:secretsmanager:region:aws\_account\_id:secret:secret\_name\) | string | `""` | no |
57-
| repository\_credentials\_kms\_key | key id, key ARN, alias name or alias ARN of the key that encrypted the repository credentials | string | `"alias/aws/secretsmanager"` | no |
58-
| tags | A map of tags \(key-value pairs\) passed to resources. | map(string) | `{}` | no |
59-
| task\_container\_command | The command that is passed to the container. | list(string) | `[]` | no |
60-
| task\_container\_environment | The environment variables to pass to a container. | map(string) | `{}` | no |
61-
| task\_container\_image | The image used to start a container. | string | n/a | yes |
62-
| task\_container\_port | The port number on the container that is bound to the user-specified or automatically assigned host port | number | `"0"` | no |
63-
| task\_definition\_cpu | Amount of CPU to reserve for the task. | number | `"256"` | no |
64-
| task\_definition\_memory | The soft limit \(in MiB\) of memory to reserve for the container. | number | `"512"` | no |
65-
| task\_host\_port | The port number on the container instance to reserve for your container. | number | `"0"` | no |
66-
| volume | \(Optional\) A set of volume blocks that containers in your task may use. This is a list of maps, where each map should contain "name", "host\_path" and "docker\_volume\_configuration". Full set of options can be found at https://www.terraform.io/docs/providers/aws/r/ecs\_task\_definition.html | list | `[]` | no |
54+
|------|-------------|------|---------|:-----:|
55+
| cloudwatch\_log\_group\_name | CloudWatch log group name required to enabled logDriver in container definitions for ecs task. | `string` | `""` | no |
56+
| container\_name | Optional name for the container to be used instead of name\_prefix. | `string` | `""` | no |
57+
| docker\_volume\_configuration | (Optional) Used to configure a docker volume option "docker\_volume\_configuration". Full set of options can be found at https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html | `list` | `[]` | no |
58+
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | `bool` | `true` | no |
59+
| name\_prefix | A prefix used for naming resources. | `string` | n/a | yes |
60+
| placement\_constraints | (Optional) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10. This is a list of maps, where each map should contain "type" and "expression" | `list` | `[]` | no |
61+
| proxy\_configuration | (Optional) The proxy configuration details for the App Mesh proxy. This is a list of maps, where each map should contain "container\_name", "properties" and "type" | `list` | `[]` | no |
62+
| repository\_credentials | name or ARN of a secrets manager secret (arn:aws:secretsmanager:region:aws\_account\_id:secret:secret\_name) | `string` | `""` | no |
63+
| repository\_credentials\_kms\_key | key id, key ARN, alias name or alias ARN of the key that encrypted the repository credentials | `string` | `"alias/aws/secretsmanager"` | no |
64+
| tags | A map of tags (key-value pairs) passed to resources. | `map(string)` | `{}` | no |
65+
| task\_container\_command | The command that is passed to the container. | `list(string)` | `[]` | no |
66+
| task\_container\_environment | The environment variables to pass to a container. | `map(string)` | `{}` | no |
67+
| task\_container\_image | The image used to start a container. | `string` | n/a | yes |
68+
| task\_container\_port | The port number on the container that is bound to the user-specified or automatically assigned host port | `number` | `0` | no |
69+
| task\_definition\_cpu | Amount of CPU to reserve for the task. | `number` | `256` | no |
70+
| task\_definition\_memory | The soft limit (in MiB) of memory to reserve for the container. | `number` | `512` | no |
71+
| task\_health\_check | An optional healthcheck definition for the task | `object({ command = list(string), interval = number, timeout = number, retries = number, startPeriod = number })` | n/a | yes |
72+
| task\_host\_port | The port number on the container instance to reserve for your container. | `number` | `0` | no |
73+
| volume | (Optional) A set of volume blocks that containers in your task may use. This is a list of maps, where each map should contain "name", "host\_path" and "docker\_volume\_configuration". Full set of options can be found at https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html | `list` | `[]` | no |
6774

6875
## Outputs
6976

7077
| Name | Description |
7178
|------|-------------|
7279
| container\_port | Port on which the container is listening. |
73-
| execution\_role\_arn | The Amazon Resource Name \(ARN\) of execution role. |
80+
| execution\_role\_arn | The Amazon Resource Name (ARN) of execution role. |
7481
| execution\_role\_create\_date | The creation date of the IAM role. |
7582
| execution\_role\_id | The ID of the execution role. |
7683
| execution\_role\_name | The name of the execution service role. |
7784
| execution\_role\_unique\_id | The stable and unique string identifying the role. |
78-
| task\_definition\_arn | Full ARN of the Task Definition \(including both family and revision\). |
85+
| task\_definition\_arn | Full ARN of the Task Definition (including both family and revision). |
7986
| task\_definition\_family | The family of the Task Definition. |
8087
| task\_definition\_revision | The revision of the task in a particular family. |
81-
| task\_role\_arn | The Amazon Resource Name \(ARN\) specifying the ECS service role. |
88+
| task\_role\_arn | The Amazon Resource Name (ARN) specifying the ECS service role. |
8289
| task\_role\_create\_date | The creation date of the IAM role. |
8390
| task\_role\_id | The ID of the role. |
8491
| task\_role\_name | The name of the Fargate task service role. |

main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ resource "aws_ecs_task_definition" "task" {
102102
}
103103
},
104104
%{~endif}
105+
%{if var.task_health_check != null~}
106+
"healthcheck": {
107+
"command": ${jsonencode(var.task_health_check.command)},
108+
"interval": ${var.task_health_check.interval},
109+
"timeout": ${var.task_health_check.timeout},
110+
"retries": ${var.task_health_check.retries},
111+
"startPeriod": ${var.task_health_check.startPeriod}
112+
},
113+
%{~endif}
105114
"command": ${jsonencode(var.task_container_command)},
106115
"environment": ${jsonencode(local.task_environment)}
107116
}]

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,9 @@ variable "docker_volume_configuration" {
104104
description = "(Optional) Used to configure a docker volume option \"docker_volume_configuration\". Full set of options can be found at https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html"
105105
default = []
106106
}
107+
108+
variable "task_health_check" {
109+
type = object({ command = list(string), interval = number, timeout = number, retries = number, startPeriod = number })
110+
description = "An optional healthcheck definition for the task"
111+
default = null
112+
}

0 commit comments

Comments
 (0)