Skip to content

Commit 77a3aff

Browse files
committed
Adding volume configuration
1 parent 11821d3 commit 77a3aff

File tree

3 files changed

+128
-43
lines changed

3 files changed

+128
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Check versions for this module on:
1717

1818
module "td" {
1919
source = "cn-terraform/ecs-fargate-task-definition/aws"
20-
version = "1.0.8"
20+
version = "1.0.9"
2121
name_preffix = var.name_preffix
2222
profile = var.profile
2323
region = var.region

main.tf

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy_attach
2525
# Container Definition
2626
module "container_definition" {
2727
source = "cloudposse/ecs-container-definition/aws"
28-
version = "0.21.0"
28+
version = "0.23.0"
2929

3030
container_name = var.container_name
3131
container_image = var.container_image
3232
container_memory = var.container_memory
3333
container_memory_reservation = var.container_memory_reservation
34-
port_mappings = local.port_mappings
34+
port_mappings = var.port_mappings
3535
healthcheck = var.healthcheck
3636
container_cpu = var.container_cpu
3737
essential = var.essential
@@ -41,6 +41,9 @@ module "container_definition" {
4141
environment = var.environment
4242
secrets = var.secrets
4343
readonly_root_filesystem = var.readonly_root_filesystem
44+
linux_parameters = var.linux_parameters
45+
log_configuration = var.log_configuration
46+
firelens_configuration = var.firelens_configuration
4447
mount_points = var.mount_points
4548
dns_servers = var.dns_servers
4649
ulimits = var.ulimits
@@ -53,8 +56,6 @@ module "container_definition" {
5356
start_timeout = var.start_timeout
5457
stop_timeout = var.stop_timeout
5558
system_controls = var.system_controls
56-
firelens_configuration = var.firelens_configuration
57-
log_configuration = var.log_configuration
5859
}
5960

6061
# Task Definition
@@ -82,5 +83,34 @@ resource "aws_ecs_task_definition" "td" {
8283
type = lookup(proxy_configuration.value, "type", null)
8384
}
8485
}
86+
dynamic "volume" {
87+
for_each = var.volumes
88+
content {
89+
host_path = lookup(volume.value, "host_path", null)
90+
name = volume.value.name
91+
92+
dynamic "docker_volume_configuration" {
93+
for_each = lookup(volume.value, "docker_volume_configuration", [])
94+
content {
95+
autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null)
96+
driver = lookup(docker_volume_configuration.value, "driver", null)
97+
driver_opts = lookup(docker_volume_configuration.value, "driver_opts", null)
98+
labels = lookup(docker_volume_configuration.value, "labels", null)
99+
scope = lookup(docker_volume_configuration.value, "scope", null)
100+
}
101+
}
102+
103+
dynamic "efs_volume_configuration" {
104+
for_each = lookup(volume.value, "efs_volume_configuration", [])
105+
content {
106+
file_system_id = lookup(efs_volume_configuration.value, "file_system_id", null)
107+
root_directory = lookup(efs_volume_configuration.value, "root_directory", null)
108+
}
109+
}
110+
}
111+
}
85112
}
86113

114+
115+
116+
# inference_accelerator - (Optional) Configuration block(s) with Inference Accelerators settings. Detailed below.

variables.tf

Lines changed: 93 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@ variable "container_name" {
3232
}
3333

3434
variable "command" {
35-
type = list(string)
3635
description = "(Optional) The command that is passed to the container"
36+
type = list(string)
3737
default = null
3838
}
3939

4040
variable "container_cpu" {
4141
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html#fargate-task-defs
4242
description = "(Optional) The number of cpu units to reserve for the container. This is optional for tasks using Fargate launch type and the total amount of container_cpu of all containers in a task will need to be lower than the task-level cpu value"
43-
default = 1024 # 1 vCPU
43+
default = 1024 # 1 vCPU
4444
}
4545

4646
variable "container_depends_on" {
47-
type = list(string)
4847
description = "(Optional) The dependencies defined for container startup and shutdown. A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed"
49-
default = null
48+
type = list(object({
49+
containerName = string
50+
condition = string
51+
}))
52+
default = null
5053
}
5154

5255
variable "container_memory" {
@@ -68,63 +71,91 @@ variable "dns_servers" {
6871
}
6972

7073
variable "docker_labels" {
71-
type = map(string)
7274
description = "(Optional) The configuration options to send to the `docker_labels`"
75+
type = map(string)
7376
default = null
7477
}
7578

7679
variable "entrypoint" {
77-
type = list(string)
7880
description = "(Optional) The entry point that is passed to the container"
81+
type = list(string)
7982
default = null
8083
}
8184

8285
variable "environment" {
86+
description = "(Optional) The environment variables to pass to the container. This is a list of maps"
8387
type = list(object({
8488
name = string
8589
value = string
8690
}))
87-
description = "(Optional) The environment variables to pass to the container. This is a list of maps"
88-
default = null
91+
default = null
8992
}
9093

9194
variable "essential" {
92-
type = bool
9395
description = "(Optional) Determines whether all other containers in a task are stopped, if this container fails or stops for any reason. Due to how Terraform type casts booleans in json it is required to double quote this value"
96+
type = bool
9497
default = true
9598
}
9699

97100
# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html
98101
variable "firelens_configuration" {
102+
description = "(Optional) The FireLens configuration for the container. This is used to specify and configure a log router for container logs. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html"
99103
type = object({
100104
type = string
101105
options = map(string)
102106
})
103-
description = "(Optional) The FireLens configuration for the container. This is used to specify and configure a log router for container logs. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html"
104-
default = null
107+
default = null
105108
}
106109

107110
# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html
108111
variable "healthcheck" {
112+
description = "(Optional) A map containing command (string), timeout, interval (duration in seconds), retries (1-10, number of times to retry before marking container unhealthy), and startPeriod (0-300, optional grace period to wait, in seconds, before failed healthchecks count toward retries)"
109113
type = object({
110114
command = list(string)
111115
retries = number
112116
timeout = number
113117
interval = number
114118
startPeriod = number
115119
})
116-
description = "(Optional) A map containing command (string), timeout, interval (duration in seconds), retries (1-10, number of times to retry before marking container unhealthy), and startPeriod (0-300, optional grace period to wait, in seconds, before failed healthchecks count toward retries)"
117-
default = null
120+
default = null
118121
}
119122

120123
variable "links" {
121-
type = list(string)
122124
description = "(Optional) List of container names this container can communicate with without port mappings"
125+
type = list(string)
123126
default = null
124127
}
125128

129+
# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html
130+
variable "linux_parameters" {
131+
description = "Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html"
132+
type = object({
133+
capabilities = object({
134+
add = list(string)
135+
drop = list(string)
136+
})
137+
devices = list(object({
138+
containerPath = string
139+
hostPath = string
140+
permissions = list(string)
141+
}))
142+
initProcessEnabled = bool
143+
maxSwap = number
144+
sharedMemorySize = number
145+
swappiness = number
146+
tmpfs = list(object({
147+
containerPath = string
148+
mountOptions = list(string)
149+
size = number
150+
}))
151+
})
152+
153+
default = null
154+
}
155+
126156
# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html
127157
variable "log_configuration" {
158+
description = "(Optional) Log configuration options to send to a custom log driver for the container. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html"
128159
type = object({
129160
logDriver = string
130161
options = map(string)
@@ -133,48 +164,53 @@ variable "log_configuration" {
133164
valueFrom = string
134165
}))
135166
})
136-
description = "(Optional) Log configuration options to send to a custom log driver for the container. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html"
137-
default = null
167+
default = null
138168
}
139169

140170
variable "mount_points" {
171+
description = "(Optional) Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`"
141172
type = list(object({
142173
containerPath = string
143174
sourceVolume = string
144175
}))
145-
description = "(Optional) Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`"
146-
default = null
176+
default = null
147177
}
148178

149-
locals {
150-
port_mappings = [
179+
variable "port_mappings" {
180+
description = "The port mappings to configure for the container. This is a list of maps. Each map should contain \"containerPort\", \"hostPort\", and \"protocol\", where \"protocol\" is one of \"tcp\" or \"udp\". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort"
181+
type = list(object({
182+
containerPort = number
183+
hostPort = number
184+
protocol = string
185+
}))
186+
default = [
151187
{
152-
"containerPort" = var.container_port
153-
"hostPort" = var.container_port
154-
"protocol" = "HTTP"
155-
},
188+
containerPort = 80
189+
hostPort = 80
190+
protocol = "tcp"
191+
}
156192
]
157193
}
158194

159195
variable "readonly_root_filesystem" {
160-
type = bool
161196
description = "(Optional) Determines whether a container is given read-only access to its root filesystem. Due to how Terraform type casts booleans in json it is required to double quote this value"
197+
type = bool
162198
default = false
163199
}
164200

165201
variable "repository_credentials" {
166-
type = map(string)
167202
description = "(Optional) Container repository credentials; required when using a private repo. This map currently supports a single key; \"credentialsParameter\", which should be the ARN of a Secrets Manager's secret holding the credentials"
203+
type = map(string)
168204
default = null
169205
}
170206

171207
variable "secrets" {
208+
description = "(Optional) The secrets to pass to the container. This is a list of maps"
172209
type = list(object({
173210
name = string
174211
valueFrom = string
175212
}))
176-
description = "(Optional) The secrets to pass to the container. This is a list of maps"
177-
default = null
213+
default = null
178214
}
179215

180216
variable "start_timeout" {
@@ -183,60 +219,79 @@ variable "start_timeout" {
183219
}
184220

185221
variable "system_controls" {
186-
type = list(map(string))
187222
description = "(Optional) A list of namespaced kernel parameters to set in the container, mapping to the --sysctl option to docker run. This is a list of maps: { namespace = \"\", value = \"\"}"
223+
type = list(map(string))
188224
default = null
189225
}
190226

191227
variable "stop_timeout" {
192-
type = number
193228
description = "(Optional) Timeout in seconds between sending SIGTERM and SIGKILL to container"
229+
type = number
194230
default = 30
195231
}
196232

197233
variable "ulimits" {
234+
description = "(Optional) Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\""
198235
type = list(object({
199236
name = string
200237
hardLimit = number
201238
softLimit = number
202239
}))
203-
description = "(Optional) Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\""
204-
default = null
240+
default = null
205241
}
206242

207243
variable "user" {
208-
type = string
209244
description = "(Optional) The user to run as inside the container. Can be any of these formats: user, user:group, uid, uid:gid, user:gid, uid:group"
245+
type = string
210246
default = null
211247
}
212248

213249
variable "volumes_from" {
250+
description = "(Optional) A list of VolumesFrom maps which contain \"sourceContainer\" (name of the container that has the volumes to mount) and \"readOnly\" (whether the container can write to the volume)"
214251
type = list(object({
215252
sourceContainer = string
216253
readOnly = bool
217254
}))
218-
description = "(Optional) A list of VolumesFrom maps which contain \"sourceContainer\" (name of the container that has the volumes to mount) and \"readOnly\" (whether the container can write to the volume)"
219-
default = null
255+
default = null
220256
}
221257

222258
variable "working_directory" {
223-
type = string
224259
description = "(Optional) The working directory to run commands inside the container"
260+
type = string
225261
default = null
226262
}
227263

228264
# ---------------------------------------------------------------------------------------------------------------------
229265
# AWS ECS Task Definition Variables
230266
# ---------------------------------------------------------------------------------------------------------------------
231267
variable "placement_constraints" {
232-
type = list
233268
description = "(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\""
269+
type = list
234270
default = []
235271
}
236272

237273
variable "proxy_configuration" {
238-
type = list
239274
description = "(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\""
275+
type = list
240276
default = []
241277
}
242278

279+
variable "volumes" {
280+
description = "(Optional) A set of volume blocks that containers in your task may use"
281+
type = list(object({
282+
host_path = string
283+
name = string
284+
docker_volume_configuration = list(object({
285+
autoprovision = bool
286+
driver = string
287+
driver_opts = map(string)
288+
labels = map(string)
289+
scope = string
290+
}))
291+
efs_volume_configuration = list(object({
292+
file_system_id = string
293+
root_directory = string
294+
}))
295+
}))
296+
default = []
297+
}

0 commit comments

Comments
 (0)