Skip to content

Commit 73e6df5

Browse files
author
Paolo Cerletti
committed
added dedicated variables for task cpu and memory
1 parent b8ef2ad commit 73e6df5

File tree

6 files changed

+104
-63
lines changed

6 files changed

+104
-63
lines changed

README.md

+71-53
Original file line numberDiff line numberDiff line change
@@ -106,72 +106,90 @@ Invoking the commands defined below creates an ECS task definition with the foll
106106
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.
107107

108108
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
109+
## Requirements
110+
111+
| Name | Version |
112+
|------|---------|
113+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12 |
114+
109115
## Providers
110116

111117
| Name | Version |
112118
|------|---------|
113-
| aws | n/a |
114-
| template | n/a |
119+
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
120+
| <a name="provider_template"></a> [template](#provider\_template) | n/a |
121+
122+
## Modules
123+
124+
No modules.
125+
126+
## Resources
127+
128+
| Name | Type |
129+
|------|------|
130+
| [aws_ecs_task_definition.ecs_task_definition](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) | resource |
131+
| [template_file.container_definition](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
115132

116133
## Inputs
117134

118135
| Name | Description | Type | Default | Required |
119-
|------|-------------|------|---------|:-----:|
120-
| command | The command that is passed to the container | `list(string)` | `[]` | no |
121-
| cpu | The number of cpu units reserved for the container | `number` | `0` | no |
122-
| disableNetworking | When this parameter is true, networking is disabled within the container | `bool` | `false` | no |
123-
| dnsSearchDomains | A list of DNS search domains that are presented to the container | `list(string)` | `[]` | no |
124-
| dnsServers | A list of DNS servers that are presented to the container | `list(string)` | `[]` | no |
125-
| dockerLabels | A key/value map of labels to add to the container | `map(string)` | `{}` | no |
126-
| dockerSecurityOptions | A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems | `list(string)` | `[]` | no |
127-
| entryPoint | The entry point that is passed to the container | `list(string)` | `[]` | no |
128-
| environment | The environment variables to pass to a container | `list(map(string))` | `[]` | no |
129-
| 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 |
130-
| 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 |
131-
| extraHosts | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container | `list(string)` | `[]` | no |
132-
| 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 |
133-
| healthCheck | The health check command and associated configuration parameters for the container | `any` | `{}` | no |
134-
| hostname | The hostname to use for your container | `string` | `""` | no |
135-
| image | The image used to start a container | `string` | `""` | no |
136-
| 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 |
137-
| ipc\_mode | The IPC resource namespace to use for the containers in the task | `string` | `"host"` | no |
138-
| links | The link parameter allows containers to communicate with each other without the need for port mappings | `list(string)` | `[]` | no |
139-
| linuxParameters | Linux-specific modifications that are applied to the container, such as Linux KernelCapabilities | `any` | `{}` | no |
140-
| logConfiguration | The log configuration specification for the container | `any` | `{}` | no |
141-
| memory | The hard limit (in MiB) of memory to present to the container | `number` | `0` | no |
142-
| memoryReservation | The soft limit (in MiB) of memory to reserve for the container | `number` | `0` | no |
143-
| mountPoints | The mount points for data volumes in your container | `list(any)` | `[]` | no |
144-
| name | The name of a container | `string` | `""` | no |
145-
| network\_mode | The Docker networking mode to use for the containers in the task | `string` | `"bridge"` | no |
146-
| pid\_mode | The process namespace to use for the containers in the task | `string` | `"host"` | no |
147-
| placement\_constraints | An array of placement constraint objects to use for the task | `list(string)` | `[]` | no |
148-
| portMappings | The list of port mappings for the container | `list(any)` | `[]` | no |
149-
| 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 |
150-
| pseudoTerminal | When this parameter is true, a TTY is allocated | `bool` | `false` | no |
151-
| readonlyRootFilesystem | When this parameter is true, the container is given read-only access to its root file system | `bool` | `false` | no |
152-
| register\_task\_definition | Registers a new task definition from the supplied family and containerDefinitions | `bool` | `true` | no |
153-
| repositoryCredentials | The private repository authentication credentials to use | `map(string)` | `{}` | no |
154-
| requires\_compatibilities | The launch type required by the task | `list(string)` | `[]` | no |
155-
| resourceRequirements | The type and amount of a resource to assign to a container | `list(string)` | `[]` | no |
156-
| secrets | The secrets to pass to the container | `list(map(string))` | `[]` | no |
157-
| systemControls | A list of namespaced kernel parameters to set in the container | `list(string)` | `[]` | no |
158-
| tags | The metadata that you apply to the task definition to help you categorize and organize them | `map(string)` | `{}` | no |
159-
| 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 |
160-
| ulimits | A list of ulimits to set in the container | `list(any)` | `[]` | no |
161-
| user | The user name to use inside the container | `string` | `""` | no |
162-
| volumes | A list of volume definitions in JSON format that containers in your task may use | `list(any)` | `[]` | no |
163-
| volumesFrom | Data volumes to mount from another container | `list(object)` | `[]` | no |
164-
| workingDirectory | The working directory in which to run commands inside the container | `string` | `""` | no |
136+
|------|-------------|------|---------|:--------:|
137+
| <a name="input_command"></a> [command](#input\_command) | The command that is passed to the container | `list(string)` | `[]` | no |
138+
| <a name="input_cpu"></a> [cpu](#input\_cpu) | The number of cpu units reserved for the container | `number` | `0` | no |
139+
| <a name="input_disableNetworking"></a> [disableNetworking](#input\_disableNetworking) | When this parameter is true, networking is disabled within the container | `bool` | `false` | no |
140+
| <a name="input_dnsSearchDomains"></a> [dnsSearchDomains](#input\_dnsSearchDomains) | A list of DNS search domains that are presented to the container | `list(string)` | `[]` | no |
141+
| <a name="input_dnsServers"></a> [dnsServers](#input\_dnsServers) | A list of DNS servers that are presented to the container | `list(string)` | `[]` | no |
142+
| <a name="input_dockerLabels"></a> [dockerLabels](#input\_dockerLabels) | A key/value map of labels to add to the container | `map(string)` | `{}` | no |
143+
| <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 |
144+
| <a name="input_entryPoint"></a> [entryPoint](#input\_entryPoint) | The entry point that is passed to the container | `list(string)` | `[]` | no |
145+
| <a name="input_environment"></a> [environment](#input\_environment) | The environment variables to pass to a container | `list(map(string))` | `[]` | no |
146+
| <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 |
147+
| <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 |
148+
| <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 |
149+
| <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 |
150+
| <a name="input_healthCheck"></a> [healthCheck](#input\_healthCheck) | The health check command and associated configuration parameters for the container | `any` | `{}` | no |
151+
| <a name="input_hostname"></a> [hostname](#input\_hostname) | The hostname to use for your container | `string` | `""` | no |
152+
| <a name="input_image"></a> [image](#input\_image) | The image used to start a container | `string` | `""` | no |
153+
| <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 |
154+
| <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 |
155+
| <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 |
156+
| <a name="input_linuxParameters"></a> [linuxParameters](#input\_linuxParameters) | Linux-specific modifications that are applied to the container, such as Linux KernelCapabilities | `any` | `{}` | no |
157+
| <a name="input_logConfiguration"></a> [logConfiguration](#input\_logConfiguration) | The log configuration specification for the container | `any` | `{}` | no |
158+
| <a name="input_memory"></a> [memory](#input\_memory) | The hard limit (in MiB) of memory to present to the container | `number` | `512` | no |
159+
| <a name="input_memoryReservation"></a> [memoryReservation](#input\_memoryReservation) | The soft limit (in MiB) of memory to reserve for the container | `number` | `0` | no |
160+
| <a name="input_mountPoints"></a> [mountPoints](#input\_mountPoints) | The mount points for data volumes in your container | `list(any)` | `[]` | no |
161+
| <a name="input_name"></a> [name](#input\_name) | The name of a container | `string` | `""` | no |
162+
| <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 |
163+
| <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 |
164+
| <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 |
165+
| <a name="input_portMappings"></a> [portMappings](#input\_portMappings) | The list of port mappings for the container | `list(any)` | `[]` | no |
166+
| <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 |
167+
| <a name="input_pseudoTerminal"></a> [pseudoTerminal](#input\_pseudoTerminal) | When this parameter is true, a TTY is allocated | `bool` | `false` | no |
168+
| <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 |
169+
| <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 |
170+
| <a name="input_repositoryCredentials"></a> [repositoryCredentials](#input\_repositoryCredentials) | The private repository authentication credentials to use | `map(string)` | `{}` | no |
171+
| <a name="input_requires_compatibilities"></a> [requires\_compatibilities](#input\_requires\_compatibilities) | The launch type required by the task | `list(string)` | `[]` | no |
172+
| <a name="input_resourceRequirements"></a> [resourceRequirements](#input\_resourceRequirements) | The type and amount of a resource to assign to a container | `list(string)` | `[]` | no |
173+
| <a name="input_secrets"></a> [secrets](#input\_secrets) | The secrets to pass to the container | `list(map(string))` | `[]` | no |
174+
| <a name="input_systemControls"></a> [systemControls](#input\_systemControls) | A list of namespaced kernel parameters to set in the container | `list(string)` | `[]` | no |
175+
| <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 |
176+
| <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 |
177+
| <a name="input_taskMemory"></a> [taskMemory](#input\_taskMemory) | Memory (in MiB) for the task. Required for Fargate. _null_ to disable | `number` | `256` | no |
178+
| <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 |
179+
| <a name="input_ulimits"></a> [ulimits](#input\_ulimits) | A list of ulimits to set in the container | `list(any)` | `[]` | no |
180+
| <a name="input_user"></a> [user](#input\_user) | The user name to use inside the container | `string` | `""` | no |
181+
| <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 |
182+
| <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 |
183+
| <a name="input_workingDirectory"></a> [workingDirectory](#input\_workingDirectory) | The working directory in which to run commands inside the container | `string` | `""` | no |
165184

166185
## Outputs
167186

168187
| Name | Description |
169188
|------|-------------|
170-
| arn | The full Amazon Resource Name (ARN) of the task definition |
171-
| container\_definitions | A list of container definitions in JSON format that describe the different containers that make up your task |
172-
| family | The family of your task definition, used as the definition name |
173-
| revision | The revision of the task in a particular family |
174-
189+
| <a name="output_arn"></a> [arn](#output\_arn) | The full Amazon Resource Name (ARN) of the task definition |
190+
| <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 |
191+
| <a name="output_family"></a> [family](#output\_family) | The family of your task definition, used as the definition name |
192+
| <a name="output_revision"></a> [revision](#output\_revision) | The revision of the task in a particular family |
175193
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
176194

177195
## Testing
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "container_definitions" {
2-
value = "${module.merged.container_definitions}"
2+
value = module.merged.container_definitions
33
}

main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ resource "aws_ecs_task_definition" "ecs_task_definition" {
137137
pid_mode = var.pid_mode
138138

139139
# Fargate requires cpu and memory to be defined at the task level
140-
cpu = var.cpu
141-
memory = var.memory
140+
cpu = var.taskCpu
141+
memory = var.taskMemory
142142

143143
dynamic "placement_constraints" {
144144
for_each = var.placement_constraints

modules/merge/README.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,31 @@ resource "aws_ecs_task_definition" "hello_world" {
115115
**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.
116116

117117
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
118+
## Requirements
119+
120+
No requirements.
121+
118122
## Providers
119123

120-
No provider.
124+
No providers.
125+
126+
## Modules
127+
128+
No modules.
129+
130+
## Resources
131+
132+
No resources.
121133

122134
## Inputs
123135

124136
| Name | Description | Type | Default | Required |
125-
|------|-------------|------|---------|:-----:|
126-
| container\_definitions | A list of container definitions in JSON format that describe the different containers that make up your task | `list` | `[]` | no |
137+
|------|-------------|------|---------|:--------:|
138+
| <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 |
127139

128140
## Outputs
129141

130142
| Name | Description |
131143
|------|-------------|
132-
| container\_definitions | A list of container definitions in JSON format that describe the different containers that make up your task |
133-
144+
| <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 |
134145
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/merge/outputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "container_definitions" {
22
description = "A list of container definitions in JSON format that describe the different containers that make up your task"
3-
value = "${format("[%s]", join(",", var.container_definitions))}"
3+
value = format("[%s]", join(",", var.container_definitions))
44
}

variables.tf

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ variable "command" {
88
}
99

1010
variable "cpu" {
11-
default = 256
11+
default = 0
1212
description = "The number of cpu units reserved for the container"
1313
type = number
1414
}
@@ -225,6 +225,17 @@ variable "tags" {
225225
type = map(string)
226226
}
227227

228+
variable "taskCpu" {
229+
default = 256
230+
description = "The number of cpu units limited for the task. Required for Fargate. _null_ to disable"
231+
type = number
232+
}
233+
234+
variable "taskMemory" {
235+
default = 256
236+
description = "Memory (in MiB) for the task. Required for Fargate. _null_ to disable"
237+
type = number
238+
}
228239
variable "task_role_arn" {
229240
default = ""
230241
description = "The short name or full Amazon Resource Name (ARN) of the IAM role that containers in this task can assume"
@@ -261,3 +272,4 @@ variable "workingDirectory" {
261272
default = ""
262273
description = "The working directory in which to run commands inside the container"
263274
}
275+

0 commit comments

Comments
 (0)