Skip to content

Commit 8240072

Browse files
committed
feat: Update container definition configurations
1 parent 5a4a70f commit 8240072

File tree

8 files changed

+395
-55
lines changed

8 files changed

+395
-55
lines changed

modules/container-definition/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,30 @@ No modules.
167167
| <a name="input_interactive"></a> [interactive](#input\_interactive) | When this parameter is `true`, you can deploy containerized applications that require `stdin` or a `tty` to be allocated | `bool` | `false` | no |
168168
| <a name="input_links"></a> [links](#input\_links) | The links parameter allows containers to communicate with each other without the need for port mappings. This parameter is only supported if the network mode of a task definition is `bridge` | `list(string)` | `null` | no |
169169
| <a name="input_linuxParameters"></a> [linuxParameters](#input\_linuxParameters) | Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. For more information see [KernelCapabilities](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_KernelCapabilities.html) | <pre>object({<br/> capabilities = optional(object({<br/> add = optional(list(string))<br/> drop = optional(list(string))<br/> }))<br/> devices = optional(list(object({<br/> containerPath = optional(string)<br/> hostPath = optional(string)<br/> permissions = optional(list(string))<br/> })))<br/> initProcessEnabled = optional(bool, false)<br/> maxSwap = optional(number)<br/> sharedMemorySize = optional(number)<br/> swappiness = optional(number)<br/> tmpfs = optional(list(object({<br/> containerPath = string<br/> mountOptions = optional(list(string))<br/> size = number<br/> })))<br/> })</pre> | <pre>{<br/> "initProcessEnabled": false<br/>}</pre> | no |
170-
| <a name="input_logConfiguration"></a> [logConfiguration](#input\_logConfiguration) | The log configuration for the container. For more information see [LogConfiguration](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html) | `any` | `{}` | no |
170+
| <a name="input_logConfiguration"></a> [logConfiguration](#input\_logConfiguration) | The log configuration for the container. For more information see [LogConfiguration](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html) | <pre>object({<br/> logDriver = optional(string)<br/> options = optional(map(string))<br/> secretOptions = optional(list(object({<br/> name = string<br/> valueFrom = string<br/> })))<br/> })</pre> | `{}` | no |
171171
| <a name="input_memory"></a> [memory](#input\_memory) | 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. The total amount of memory reserved for all containers within a task must be lower than the task `memory` value, if one is specified | `number` | `null` | no |
172172
| <a name="input_memoryReservation"></a> [memoryReservation](#input\_memoryReservation) | The soft limit (in MiB) of memory to reserve for the container. When system memory is under heavy contention, Docker attempts to keep the container memory to this soft limit. However, your container can consume more memory when it needs to, up to either the hard limit specified with the `memory` parameter (if applicable), or all of the available memory on the container instance | `number` | `null` | no |
173-
| <a name="input_mountPoints"></a> [mountPoints](#input\_mountPoints) | The mount points for data volumes in your container | `list(any)` | `null` | no |
173+
| <a name="input_mountPoints"></a> [mountPoints](#input\_mountPoints) | The mount points for data volumes in your container | <pre>list(object({<br/> containerPath = optional(string)<br/> readOnly = optional(bool)<br/> sourceVolume = optional(string)<br/> }))</pre> | `null` | no |
174174
| <a name="input_name"></a> [name](#input\_name) | The name of a container. If you're linking multiple containers together in a task definition, the name of one container can be entered in the links of another container to connect the containers. Up to 255 letters (uppercase and lowercase), numbers, underscores, and hyphens are allowed | `string` | `null` | no |
175175
| <a name="input_operating_system_family"></a> [operating\_system\_family](#input\_operating\_system\_family) | The OS family for task | `string` | `"LINUX"` | no |
176-
| <a name="input_portMappings"></a> [portMappings](#input\_portMappings) | The list of port mappings for the container. Port mappings allow containers to access ports on the host container instance to send or receive traffic. For task definitions that use the awsvpc network mode, only specify the containerPort. The hostPort can be left blank or it must be the same value as the containerPort | <pre>list(object({<br/> appProtocol = optional(string)<br/> containerPort = number<br/> hostPort = optional(number)<br/> name = string<br/> protocol = optional(string)<br/> }))</pre> | `null` | no |
176+
| <a name="input_portMappings"></a> [portMappings](#input\_portMappings) | The list of port mappings for the container. Port mappings allow containers to access ports on the host container instance to send or receive traffic. For task definitions that use the awsvpc network mode, only specify the containerPort. The hostPort can be left blank or it must be the same value as the containerPort | <pre>list(object({<br/> appProtocol = optional(string)<br/> containerPort = optional(number)<br/> containerPortRange = optional(string)<br/> hostPort = optional(number)<br/> name = optional(string)<br/> protocol = optional(string)<br/> }))</pre> | `null` | no |
177177
| <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 |
178178
| <a name="input_pseudoTerminal"></a> [pseudoTerminal](#input\_pseudoTerminal) | When this parameter is true, a `TTY` is allocated | `bool` | `false` | no |
179179
| <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` | `true` | no |
180-
| <a name="input_repositoryCredentials"></a> [repositoryCredentials](#input\_repositoryCredentials) | 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 | `map(string)` | `null` | no |
180+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
181+
| <a name="input_repositoryCredentials"></a> [repositoryCredentials](#input\_repositoryCredentials) | 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 | <pre>object({<br/> credentialsParameter = optional(string)<br/> })</pre> | `null` | no |
181182
| <a name="input_resourceRequirements"></a> [resourceRequirements](#input\_resourceRequirements) | The type and amount of a resource to assign to a container. The only supported resource is a GPU | <pre>list(object({<br/> type = string<br/> value = string<br/> }))</pre> | `null` | no |
182183
| <a name="input_restartPolicy"></a> [restartPolicy](#input\_restartPolicy) | Container restart policy; helps overcome transient failures faster and maintain task availability | <pre>object({<br/> enabled = optional(bool, true)<br/> ignoredExitCodes = optional(list(number))<br/> restartAttemptPeriod = optional(number)<br/> })</pre> | <pre>{<br/> "enabled": true<br/>}</pre> | no |
183184
| <a name="input_secrets"></a> [secrets](#input\_secrets) | The secrets to pass to the container. For more information, see [Specifying Sensitive Data](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html) in the Amazon Elastic Container Service Developer Guide | <pre>list(object({<br/> name = string<br/> valueFrom = string<br/> }))</pre> | `null` | no |
184185
| <a name="input_service"></a> [service](#input\_service) | The name of the service that the container definition is associated with | `string` | `""` | no |
185186
| <a name="input_startTimeout"></a> [startTimeout](#input\_startTimeout) | Time duration (in seconds) to wait before giving up on resolving dependencies for a container | `number` | `30` | no |
186187
| <a name="input_stopTimeout"></a> [stopTimeout](#input\_stopTimeout) | Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own | `number` | `120` | no |
187-
| <a name="input_systemControls"></a> [systemControls](#input\_systemControls) | A list of namespaced kernel parameters to set in the container | `list(map(string))` | `null` | no |
188+
| <a name="input_systemControls"></a> [systemControls](#input\_systemControls) | A list of namespaced kernel parameters to set in the container | <pre>list(object({<br/> namespace = optional(string)<br/> value = optional(string)<br/> }))</pre> | `null` | no |
188189
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
189190
| <a name="input_ulimits"></a> [ulimits](#input\_ulimits) | A list of ulimits to set in the container. If a ulimit value is specified in a task definition, it overrides the default values set by Docker | <pre>list(object({<br/> hardLimit = number<br/> name = string<br/> softLimit = number<br/> }))</pre> | `null` | no |
190191
| <a name="input_user"></a> [user](#input\_user) | The user to run as inside the container. Can be any of these formats: user, user:group, uid, uid:gid, user:gid, uid:group. The default (null) will use the container's configured `USER` directive or root if not set | `string` | `null` | no |
191-
| <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> | `null` | no |
192+
| <a name="input_versionConsistency"></a> [versionConsistency](#input\_versionConsistency) | Specifies whether Amazon ECS will resolve the container image tag provided in the container definition to an image digest | `string` | `"disabled"` | no |
193+
| <a name="input_volumesFrom"></a> [volumesFrom](#input\_volumesFrom) | Data volumes to mount from another container | <pre>list(object({<br/> readOnly = optional(bool)<br/> sourceContainer = optional(string)<br/> }))</pre> | `null` | no |
192194
| <a name="input_workingDirectory"></a> [workingDirectory](#input\_workingDirectory) | The working directory to run commands inside the container | `string` | `null` | no |
193195

194196
## Outputs

modules/container-definition/main.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
data "aws_region" "current" {}
1+
data "aws_region" "current" {
2+
region = var.region
3+
}
24

35
locals {
46
is_not_windows = contains(["LINUX"], var.operating_system_family)
57

68
log_group_name = try(coalesce(var.cloudwatch_log_group_name, "/aws/ecs/${var.service}/${var.name}"), "")
79

810
logConfiguration = merge(
9-
{ for k, v in {
11+
{
1012
logDriver = "awslogs",
1113
options = {
1214
awslogs-region = data.aws_region.current.region,
1315
awslogs-group = try(aws_cloudwatch_log_group.this[0].name, ""),
1416
awslogs-stream-prefix = "ecs"
1517
},
16-
} : k => v if var.enable_cloudwatch_logging },
18+
},
1719
var.logConfiguration
1820
)
1921

@@ -40,7 +42,7 @@ locals {
4042
interactive = var.interactive
4143
links = local.is_not_windows ? var.links : null
4244
linuxParameters = local.is_not_windows ? local.linuxParameters : null
43-
logConfiguration = length(local.logConfiguration) > 0 ? local.logConfiguration : null
45+
logConfiguration = var.create_cloudwatch_log_group ? local.logConfiguration : var.logConfiguration
4446
memory = var.memory
4547
memoryReservation = var.memoryReservation
4648
mountPoints = var.mountPoints
@@ -58,6 +60,7 @@ locals {
5860
systemControls = var.systemControls
5961
ulimits = local.is_not_windows ? var.ulimits : null
6062
user = local.is_not_windows ? var.user : null
63+
versionConsistency = var.versionConsistency
6164
volumesFrom = var.volumesFrom
6265
workingDirectory = var.workingDirectory
6366
}
@@ -69,6 +72,8 @@ locals {
6972
resource "aws_cloudwatch_log_group" "this" {
7073
count = var.create_cloudwatch_log_group && var.enable_cloudwatch_logging ? 1 : 0
7174

75+
region = var.region
76+
7277
name = var.cloudwatch_log_group_use_name_prefix ? null : local.log_group_name
7378
name_prefix = var.cloudwatch_log_group_use_name_prefix ? "${local.log_group_name}-" : null
7479
log_group_class = var.cloudwatch_log_group_class

modules/container-definition/variables.tf

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
variable "region" {
2+
description = "Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration"
3+
type = string
4+
default = null
5+
}
6+
17
variable "operating_system_family" {
28
description = "The OS family for task"
39
type = string
410
default = "LINUX"
511
}
612

13+
variable "tags" {
14+
description = "A map of tags to add to all resources"
15+
type = map(string)
16+
default = {}
17+
}
18+
719
################################################################################
820
# Container Definition
921
################################################################################
@@ -178,15 +190,14 @@ variable "linuxParameters" {
178190

179191
variable "logConfiguration" {
180192
description = "The log configuration for the container. For more information see [LogConfiguration](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html)"
181-
# type = object({
182-
# logDriver = optional(string)
183-
# options = optional(map(string))
184-
# secretOptions = optional(list(object({
185-
# name = string
186-
# valueFrom = string
187-
# })))
188-
# })
189-
type = any
193+
type = object({
194+
logDriver = optional(string)
195+
options = optional(map(string))
196+
secretOptions = optional(list(object({
197+
name = string
198+
valueFrom = string
199+
})))
200+
})
190201
default = {}
191202
}
192203

@@ -204,8 +215,12 @@ variable "memoryReservation" {
204215

205216
variable "mountPoints" {
206217
description = "The mount points for data volumes in your container"
207-
type = list(any)
208-
default = null
218+
type = list(object({
219+
containerPath = optional(string)
220+
readOnly = optional(bool)
221+
sourceVolume = optional(string)
222+
}))
223+
default = null
209224
}
210225

211226
variable "name" {
@@ -217,11 +232,12 @@ variable "name" {
217232
variable "portMappings" {
218233
description = "The list of port mappings for the container. Port mappings allow containers to access ports on the host container instance to send or receive traffic. For task definitions that use the awsvpc network mode, only specify the containerPort. The hostPort can be left blank or it must be the same value as the containerPort"
219234
type = list(object({
220-
appProtocol = optional(string)
221-
containerPort = number
222-
hostPort = optional(number)
223-
name = string
224-
protocol = optional(string)
235+
appProtocol = optional(string)
236+
containerPort = optional(number)
237+
containerPortRange = optional(string)
238+
hostPort = optional(number)
239+
name = optional(string)
240+
protocol = optional(string)
225241
}))
226242
default = null
227243
}
@@ -246,8 +262,10 @@ variable "readonlyRootFilesystem" {
246262

247263
variable "repositoryCredentials" {
248264
description = "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"
249-
type = map(string)
250-
default = null
265+
type = object({
266+
credentialsParameter = optional(string)
267+
})
268+
default = null
251269
}
252270

253271
variable "resourceRequirements" {
@@ -294,8 +312,11 @@ variable "stopTimeout" {
294312

295313
variable "systemControls" {
296314
description = "A list of namespaced kernel parameters to set in the container"
297-
type = list(map(string))
298-
default = null
315+
type = list(object({
316+
namespace = optional(string)
317+
value = optional(string)
318+
}))
319+
default = null
299320
}
300321

301322
variable "ulimits" {
@@ -314,11 +335,17 @@ variable "user" {
314335
default = null
315336
}
316337

338+
variable "versionConsistency" {
339+
description = "Specifies whether Amazon ECS will resolve the container image tag provided in the container definition to an image digest"
340+
type = string
341+
default = "disabled"
342+
}
343+
317344
variable "volumesFrom" {
318345
description = "Data volumes to mount from another container"
319346
type = list(object({
320-
readOnly = bool
321-
sourceContainer = string
347+
readOnly = optional(bool)
348+
sourceContainer = optional(string)
322349
}))
323350
default = null
324351
}
@@ -380,9 +407,3 @@ variable "cloudwatch_log_group_kms_key_id" {
380407
type = string
381408
default = null
382409
}
383-
384-
variable "tags" {
385-
description = "A map of tags to add to all resources"
386-
type = map(string)
387-
default = {}
388-
}

0 commit comments

Comments
 (0)