Skip to content

Commit d817ead

Browse files
authored
Add more task container variables (#2)
1 parent 36999bc commit d817ead

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ 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+
## Requirements
46+
47+
No requirements.
48+
4549
## Providers
4650

4751
| Name | Version |
@@ -51,7 +55,7 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http
5155
## Inputs
5256

5357
| Name | Description | Type | Default | Required |
54-
|------|-------------|------|---------|:-----:|
58+
|------|-------------|------|---------|:--------:|
5559
| cloudwatch\_log\_group\_name | CloudWatch log group name required to enabled logDriver in container definitions for ecs task. | `string` | `""` | no |
5660
| container\_name | Optional name for the container to be used instead of name\_prefix. | `string` | `""` | no |
5761
| 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 |
@@ -63,12 +67,16 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http
6367
| 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 |
6468
| tags | A map of tags (key-value pairs) passed to resources. | `map(string)` | `{}` | no |
6569
| task\_container\_command | The command that is passed to the container. | `list(string)` | `[]` | no |
70+
| task\_container\_cpu | Amount of CPU to reserve for the container. | `number` | `null` | no |
6671
| task\_container\_environment | The environment variables to pass to a container. | `map(string)` | `{}` | no |
6772
| task\_container\_image | The image used to start a container. | `string` | n/a | yes |
73+
| task\_container\_memory | The hard limit (in MiB) of memory for the container. | `number` | `null` | no |
74+
| task\_container\_memory\_reservation | The soft limit (in MiB) of memory to reserve for the container. | `number` | `null` | no |
6875
| task\_container\_port | The port number on the container that is bound to the user-specified or automatically assigned host port | `number` | `0` | no |
76+
| task\_container\_working\_directory | The working directory to run commands inside the container. | `string` | `""` | no |
6977
| 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 |
78+
| task\_definition\_memory | The soft limit (in MiB) of memory to reserve for the task. | `number` | `512` | no |
79+
| task\_health\_check | An optional healthcheck definition for the task | `object({ command = list(string), interval = number, timeout = number, retries = number, startPeriod = number })` | `null` | no |
7280
| task\_host\_port | The port number on the container instance to reserve for your container. | `number` | `0` | no |
7381
| 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 |
7482

@@ -109,4 +117,4 @@ See LICENSE for full details.
109117

110118
```bash
111119
brew install pre-commit terraform-docs tflint
112-
```
120+
```

main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ resource "aws_ecs_task_definition" "task" {
112112
},
113113
%{~endif}
114114
"command": ${jsonencode(var.task_container_command)},
115+
%{if var.task_container_working_directory != ""~}
116+
"workingDirectory": ${var.task_container_working_directory},
117+
%{~endif}
118+
%{if var.task_container_memory != null~}
119+
"memory": ${var.task_container_memory},
120+
%{~endif}
121+
%{if var.task_container_memory_reservation != null~}
122+
"memoryReservation": ${var.task_container_memory_reservation},
123+
%{~endif}
124+
%{if var.task_container_cpu != null~}
125+
"cpu": ${var.task_container_cpu},
126+
%{~endif}
115127
"environment": ${jsonencode(local.task_environment)}
116128
}]
117129
EOF

variables.tf

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,41 @@ variable "task_definition_cpu" {
3939
}
4040

4141
variable "task_definition_memory" {
42-
description = "The soft limit (in MiB) of memory to reserve for the container."
42+
description = "The soft limit (in MiB) of memory to reserve for the task."
4343
default = 512
4444
type = number
4545
}
4646

47+
variable "task_container_cpu" {
48+
description = "Amount of CPU to reserve for the container."
49+
default = null
50+
type = number
51+
}
52+
53+
variable "task_container_memory" {
54+
description = "The hard limit (in MiB) of memory for the container."
55+
default = null
56+
type = number
57+
}
58+
59+
variable "task_container_memory_reservation" {
60+
description = "The soft limit (in MiB) of memory to reserve for the container."
61+
default = null
62+
type = number
63+
}
64+
4765
variable "task_container_command" {
4866
description = "The command that is passed to the container."
4967
default = []
5068
type = list(string)
5169
}
5270

71+
variable "task_container_working_directory" {
72+
description = "The working directory to run commands inside the container."
73+
default = ""
74+
type = string
75+
}
76+
5377
variable "task_container_environment" {
5478
description = "The environment variables to pass to a container."
5579
default = {}
@@ -109,4 +133,4 @@ variable "task_health_check" {
109133
type = object({ command = list(string), interval = number, timeout = number, retries = number, startPeriod = number })
110134
description = "An optional healthcheck definition for the task"
111135
default = null
112-
}
136+
}

0 commit comments

Comments
 (0)