Skip to content

Dedicated cpu and memory for task defintion #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ repos:
- id: terraform_docs
- id: terraform_fmt
repo: https://github.com/antonbabenko/pre-commit-terraform.git
rev: v1.11.0
rev: v1.48.0

- hooks:
- id: go-fmt
- id: go-lint
exclude: vendor
repo: https://github.com/dnephin/pre-commit-golang.git
rev: v0.3.3
rev: v0.3.5
124 changes: 71 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,72 +106,90 @@ Invoking the commands defined below creates an ECS task definition with the foll
By default, this module creates a task definition with a single container definition. To create a task definition with multiple container definitions, refer to the documentation of the [`merge`](modules/merge) module.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12 |

## Providers

| Name | Version |
|------|---------|
| aws | n/a |
| template | n/a |
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
| <a name="provider_template"></a> [template](#provider\_template) | n/a |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_ecs_task_definition.ecs_task_definition](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) | resource |
| [template_file.container_definition](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| command | The command that is passed to the container | `list(string)` | `[]` | no |
| cpu | The number of cpu units reserved for the container | `number` | `0` | no |
| disableNetworking | When this parameter is true, networking is disabled within the container | `bool` | `false` | no |
| dnsSearchDomains | A list of DNS search domains that are presented to the container | `list(string)` | `[]` | no |
| dnsServers | A list of DNS servers that are presented to the container | `list(string)` | `[]` | no |
| dockerLabels | A key/value map of labels to add to the container | `map(string)` | `{}` | no |
| dockerSecurityOptions | A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems | `list(string)` | `[]` | no |
| entryPoint | The entry point that is passed to the container | `list(string)` | `[]` | no |
| environment | The environment variables to pass to a container | `list(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 Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume | `string` | `""` | no |
| extraHosts | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container | `list(string)` | `[]` | no |
| family | You must specify a family for a task definition, which allows you to track multiple versions of the same task definition | `any` | n/a | yes |
| healthCheck | The health check command and associated configuration parameters for the container | `any` | `{}` | no |
| hostname | The hostname to use for your container | `string` | `""` | no |
| image | The image used to start a container | `string` | `""` | no |
| interactive | When this parameter is true, this allows you to deploy containerized applications that require stdin or a tty to be allocated | `bool` | `false` | no |
| ipc\_mode | The IPC resource namespace to use for the containers in the task | `string` | `"host"` | no |
| links | The link parameter allows containers to communicate with each other without the need for port mappings | `list(string)` | `[]` | no |
| linuxParameters | Linux-specific modifications that are applied to the container, such as Linux KernelCapabilities | `any` | `{}` | no |
| logConfiguration | The log configuration specification for the container | `any` | `{}` | no |
| memory | The hard limit (in MiB) of memory to present to the container | `number` | `0` | no |
| memoryReservation | The soft limit (in MiB) of memory to reserve for the container | `number` | `0` | no |
| mountPoints | The mount points for data volumes in your container | `list(any)` | `[]` | no |
| name | The name of a container | `string` | `""` | no |
| network\_mode | The Docker networking mode to use for the containers in the task | `string` | `"bridge"` | no |
| pid\_mode | The process namespace to use for the containers in the task | `string` | `"host"` | no |
| placement\_constraints | An array of placement constraint objects to use for the task | `list(string)` | `[]` | no |
| portMappings | The list of port mappings for the container | `list(any)` | `[]` | no |
| privileged | When this parameter is true, the container is given elevated privileges on the host container instance (similar to the root user) | `bool` | `false` | no |
| pseudoTerminal | When this parameter is true, a TTY is allocated | `bool` | `false` | no |
| readonlyRootFilesystem | When this parameter is true, the container is given read-only access to its root file system | `bool` | `false` | no |
| register\_task\_definition | Registers a new task definition from the supplied family and containerDefinitions | `bool` | `true` | no |
| repositoryCredentials | The private repository authentication credentials to use | `map(string)` | `{}` | no |
| requires\_compatibilities | The launch type required by the task | `list(string)` | `[]` | no |
| resourceRequirements | The type and amount of a resource to assign to a container | `list(string)` | `[]` | no |
| secrets | The secrets to pass to the container | `list(map(string))` | `[]` | no |
| systemControls | A list of namespaced kernel parameters to set in the container | `list(string)` | `[]` | no |
| tags | The metadata that you apply to the task definition to help you categorize and organize them | `map(string)` | `{}` | no |
| task\_role\_arn | The short name or full Amazon Resource Name (ARN) of the IAM role that containers in this task can assume | `string` | `""` | no |
| ulimits | A list of ulimits to set in the container | `list(any)` | `[]` | no |
| user | The user name to use inside the container | `string` | `""` | no |
| volumes | A list of volume definitions in JSON format that containers in your task may use | `list(any)` | `[]` | no |
| volumesFrom | Data volumes to mount from another container | `list(object)` | `[]` | no |
| workingDirectory | The working directory in which to run commands inside the container | `string` | `""` | no |
|------|-------------|------|---------|:--------:|
| <a name="input_command"></a> [command](#input\_command) | The command that is passed to the container | `list(string)` | `[]` | no |
| <a name="input_cpu"></a> [cpu](#input\_cpu) | The number of cpu units reserved for the container | `number` | `0` | no |
| <a name="input_disableNetworking"></a> [disableNetworking](#input\_disableNetworking) | When this parameter is true, networking is disabled within the container | `bool` | `false` | no |
| <a name="input_dnsSearchDomains"></a> [dnsSearchDomains](#input\_dnsSearchDomains) | A list of DNS search domains that are presented to the container | `list(string)` | `[]` | no |
| <a name="input_dnsServers"></a> [dnsServers](#input\_dnsServers) | A list of DNS servers that are presented to the container | `list(string)` | `[]` | no |
| <a name="input_dockerLabels"></a> [dockerLabels](#input\_dockerLabels) | A key/value map of labels to add to the container | `map(string)` | `{}` | no |
| <a name="input_dockerSecurityOptions"></a> [dockerSecurityOptions](#input\_dockerSecurityOptions) | A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems | `list(string)` | `[]` | no |
| <a name="input_entryPoint"></a> [entryPoint](#input\_entryPoint) | The entry point that is passed to the container | `list(string)` | `[]` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | The environment variables to pass to a container | `list(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 Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume | `string` | `""` | no |
| <a name="input_extraHosts"></a> [extraHosts](#input\_extraHosts) | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container | <pre>list(object({<br> ipAddress = string<br> hostname = string<br> }))</pre> | `[]` | no |
| <a name="input_family"></a> [family](#input\_family) | You must specify a family for a task definition, which allows you to track multiple versions of the same task definition | `any` | n/a | yes |
| <a name="input_healthCheck"></a> [healthCheck](#input\_healthCheck) | The health check command and associated configuration parameters for the container | `any` | `{}` | no |
| <a name="input_hostname"></a> [hostname](#input\_hostname) | The hostname to use for your container | `string` | `""` | no |
| <a name="input_image"></a> [image](#input\_image) | The image used to start a container | `string` | `""` | no |
| <a name="input_interactive"></a> [interactive](#input\_interactive) | When this parameter is true, this allows you to deploy containerized applications that require stdin or a tty to be allocated | `bool` | `false` | no |
| <a name="input_ipc_mode"></a> [ipc\_mode](#input\_ipc\_mode) | The IPC resource namespace to use for the containers in the task | `any` | `null` | no |
| <a name="input_links"></a> [links](#input\_links) | The link parameter allows containers to communicate with each other without the need for port mappings | `list(string)` | `[]` | no |
| <a name="input_linuxParameters"></a> [linuxParameters](#input\_linuxParameters) | Linux-specific modifications that are applied to the container, such as Linux KernelCapabilities | `any` | `{}` | no |
| <a name="input_logConfiguration"></a> [logConfiguration](#input\_logConfiguration) | The log configuration specification for the container | `any` | `{}` | no |
| <a name="input_memory"></a> [memory](#input\_memory) | The hard limit (in MiB) of memory to present to the container | `number` | `512` | no |
| <a name="input_memoryReservation"></a> [memoryReservation](#input\_memoryReservation) | The soft limit (in MiB) of memory to reserve for the container | `number` | `0` | no |
| <a name="input_mountPoints"></a> [mountPoints](#input\_mountPoints) | The mount points for data volumes in your container | `list(any)` | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | The name of a container | `string` | `""` | no |
| <a name="input_network_mode"></a> [network\_mode](#input\_network\_mode) | The Docker networking mode to use for the containers in the task | `string` | `"bridge"` | no |
| <a name="input_pid_mode"></a> [pid\_mode](#input\_pid\_mode) | The process namespace to use for the containers in the task | `any` | `null` | no |
| <a name="input_placement_constraints"></a> [placement\_constraints](#input\_placement\_constraints) | An array of placement constraint objects to use for the task | <pre>list(object({<br> type = string<br> expression = string<br> }))</pre> | `[]` | no |
| <a name="input_portMappings"></a> [portMappings](#input\_portMappings) | The list of port mappings for the container | `list(any)` | `[]` | no |
| <a name="input_privileged"></a> [privileged](#input\_privileged) | When this parameter is true, the container is given elevated privileges on the host container instance (similar to the root user) | `bool` | `false` | no |
| <a name="input_pseudoTerminal"></a> [pseudoTerminal](#input\_pseudoTerminal) | When this parameter is true, a TTY is allocated | `bool` | `false` | no |
| <a name="input_readonlyRootFilesystem"></a> [readonlyRootFilesystem](#input\_readonlyRootFilesystem) | When this parameter is true, the container is given read-only access to its root file system | `bool` | `false` | no |
| <a name="input_register_task_definition"></a> [register\_task\_definition](#input\_register\_task\_definition) | Registers a new task definition from the supplied family and containerDefinitions | `bool` | `true` | no |
| <a name="input_repositoryCredentials"></a> [repositoryCredentials](#input\_repositoryCredentials) | The private repository authentication credentials to use | `map(string)` | `{}` | no |
| <a name="input_requires_compatibilities"></a> [requires\_compatibilities](#input\_requires\_compatibilities) | The launch type required by the task | `list(string)` | `[]` | no |
| <a name="input_resourceRequirements"></a> [resourceRequirements](#input\_resourceRequirements) | The type and amount of a resource to assign to a container | `list(string)` | `[]` | no |
| <a name="input_secrets"></a> [secrets](#input\_secrets) | The secrets to pass to the container | `list(map(string))` | `[]` | no |
| <a name="input_systemControls"></a> [systemControls](#input\_systemControls) | A list of namespaced kernel parameters to set in the container | `list(string)` | `[]` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | The metadata that you apply to the task definition to help you categorize and organize them | `map(string)` | `{}` | no |
| <a name="input_taskCpu"></a> [taskCpu](#input\_taskCpu) | The number of cpu units limited for the task. Required for Fargate. _null_ to disable | `number` | `256` | no |
| <a name="input_taskMemory"></a> [taskMemory](#input\_taskMemory) | Memory (in MiB) for the task. Required for Fargate. _null_ to disable | `number` | `256` | no |
| <a name="input_task_role_arn"></a> [task\_role\_arn](#input\_task\_role\_arn) | The short name or full Amazon Resource Name (ARN) of the IAM role that containers in this task can assume | `string` | `""` | no |
| <a name="input_ulimits"></a> [ulimits](#input\_ulimits) | A list of ulimits to set in the container | `list(any)` | `[]` | no |
| <a name="input_user"></a> [user](#input\_user) | The user name to use inside the container | `string` | `""` | no |
| <a name="input_volumes"></a> [volumes](#input\_volumes) | A list of volume definitions in JSON format that containers in your task may use | `list(any)` | `[]` | no |
| <a name="input_volumesFrom"></a> [volumesFrom](#input\_volumesFrom) | Data volumes to mount from another container | <pre>list(object({<br> readOnly = bool<br> sourceContainer = string<br> }))</pre> | `[]` | no |
| <a name="input_workingDirectory"></a> [workingDirectory](#input\_workingDirectory) | The working directory in which to run commands inside the container | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| arn | The full Amazon Resource Name (ARN) of the task definition |
| container\_definitions | A list of container definitions in JSON format that describe the different containers that make up your task |
| family | The family of your task definition, used as the definition name |
| revision | The revision of the task in a particular family |

| <a name="output_arn"></a> [arn](#output\_arn) | The full Amazon Resource Name (ARN) of the task definition |
| <a name="output_container_definitions"></a> [container\_definitions](#output\_container\_definitions) | A list of container definitions in JSON format that describe the different containers that make up your task |
| <a name="output_family"></a> [family](#output\_family) | The family of your task definition, used as the definition name |
| <a name="output_revision"></a> [revision](#output\_revision) | The revision of the task in a particular family |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## Testing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "container_definitions" {
value = "${module.merged.container_definitions}"
value = module.merged.container_definitions
}
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ resource "aws_ecs_task_definition" "ecs_task_definition" {
pid_mode = var.pid_mode

# Fargate requires cpu and memory to be defined at the task level
cpu = var.cpu
memory = var.memory
cpu = var.taskCpu
memory = var.taskMemory

dynamic "placement_constraints" {
for_each = var.placement_constraints
Expand Down
21 changes: 16 additions & 5 deletions modules/merge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,31 @@ resource "aws_ecs_task_definition" "hello_world" {
**Note:** The `register_task_definition` flag for both task definitions is required; otherwise a task definition containing a single container definition is registered created for both the `wordpress` and `mysql` services.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No provider.
No providers.

## Modules

No modules.

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:-----:|
| container\_definitions | A list of container definitions in JSON format that describe the different containers that make up your task | `list` | `[]` | no |
|------|-------------|------|---------|:--------:|
| <a name="input_container_definitions"></a> [container\_definitions](#input\_container\_definitions) | A list of container definitions in JSON format that describe the different containers that make up your task | `list` | `[]` | no |

## Outputs

| Name | Description |
|------|-------------|
| container\_definitions | A list of container definitions in JSON format that describe the different containers that make up your task |

| <a name="output_container_definitions"></a> [container\_definitions](#output\_container\_definitions) | A list of container definitions in JSON format that describe the different containers that make up your task |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2 changes: 1 addition & 1 deletion modules/merge/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "container_definitions" {
description = "A list of container definitions in JSON format that describe the different containers that make up your task"
value = "${format("[%s]", join(",", var.container_definitions))}"
value = format("[%s]", join(",", var.container_definitions))
}
14 changes: 13 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ variable "command" {
}

variable "cpu" {
default = 256
default = 0
description = "The number of cpu units reserved for the container"
type = number
}
Expand Down Expand Up @@ -225,6 +225,17 @@ variable "tags" {
type = map(string)
}

variable "taskCpu" {
default = 256
description = "The number of cpu units limited for the task. Required for Fargate. _null_ to disable"
type = number
}

variable "taskMemory" {
default = 256
description = "Memory (in MiB) for the task. Required for Fargate. _null_ to disable"
type = number
}
variable "task_role_arn" {
default = ""
description = "The short name or full Amazon Resource Name (ARN) of the IAM role that containers in this task can assume"
Expand Down Expand Up @@ -261,3 +272,4 @@ variable "workingDirectory" {
default = ""
description = "The working directory in which to run commands inside the container"
}