Creates a task definition with a single container and CloudWatch log group
There's 3 ways to specify the container image:
-
By specifying the full image name
image = "name:tag"
-
By specifying name and tag separately
image_name = "name" image_tag = "tag"
-
By specifying just the name, so the module fetches the tag used in the latest revision of the task definition
image_name = "name"
This enables you to update the image externally, eg. with the CI/CD pipeline responsible for the given service.
We recommend creating the task definition using image
or image_name
+ image_tag
and then switching to just image_name
to allow for external updates.
Name | Version |
---|---|
terraform | >= 0.12, <2.0 |
aws | >= 4.0.0 |
Name | Version |
---|---|
aws | >= 4.0.0 |
Name | Source | Version |
---|---|---|
container | ./container_definition | n/a |
container_log | ./log_group | n/a |
Name | Type |
---|---|
aws_ecs_task_definition.task | resource |
aws_ecs_container_definition.current | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
command | Command override. | list(string) |
null |
no |
container | Container name within the task definition, defaults to task name | string |
null |
no |
cpu | The number of cpu units (1/1024 vCPU) the Amazon ECS container agent will reserve for the container. | number |
0 |
no |
create | Should resources be created | bool |
true |
no |
enable_environment_parameters_hash | Inject an SSM_PARAMETERS_HASH environment variable to ensure that whenever parameter versions change the container definition will also change.This makes sure that any services will be updated with new task definitions whenever a parameter is updated, so the service itself doesn't need to poll SSM. |
bool |
true |
no |
entry_point | Entry point override. | list(string) |
null |
no |
environment | Kebab-cased environment name, eg. development, staging, production. | string |
n/a | yes |
environment_parameters | Environment variables that should be set to Systems Manager parameter values. Maps environment variable names to parameters. |
map(object({ |
{} |
no |
environment_variables | Environment variables to pass to a container. | map(string) |
{} |
no |
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 |
execution_role_arn | The ARN of IAM role that allows ECS to execute your task. Required when: - using environment_parameters to give ECS access to the SSM parameters- using launch_type = "FARGATE" when running the task |
string |
null |
no |
image | Full container image name, including the version tag. Either image or image_name has to be provided. | string |
null |
no |
image_name | Container image name, without the version tag. Either image or image_name has to be provided. | string |
null |
no |
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 |
log_retention | Log retention in days. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0. If you select 0, the events in the log group are always retained and never expire. |
number |
7 |
no |
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 |
memory_soft_limit | The soft limit (in MiB) of memory to reserve for the container. When system memory is under contention, Docker attempts to keep the container memory to this soft limit; however, your container can consume more memory when needed. | number |
256 |
no |
network_mode | Docker networking mode to use for the containers in the task. Valid values are none , bridge , awsvpc , and host . |
string |
null |
no |
placement_constraint_expressions | Placement constraint expressions for the task in Cluster Query Language | list(string) |
[] |
no |
ports | List of TCP ports that should be exposed on the host, a random host port will be assigned for each container port | list(number) |
[] |
no |
project | Kebab-cased project name | string |
n/a | yes |
role_arn | The ARN of IAM role that allows your Amazon ECS container task to make calls to other AWS services. | string |
null |
no |
tags | Tags to add to resources that support them | map(string) |
{} |
no |
task | ECS task definition name | string |
n/a | yes |
task_cpu | CPU reserved for the task. Required when running on Fargate. | number |
null |
no |
task_memory | Memory reserved for the task. Required when running on Fargate. | number |
null |
no |
working_directory | Working directory override. | string |
null |
no |
Name | Description |
---|---|
arn | Created task definition revision ARN |
family | Task definition family |
image | Container image used |
image_tag | Container image tag used |
log_group_arn | CloudWatch log group ARN |
log_group_name | CloudWatch log group name |
revision | Task definition revision |