diff --git a/README.md b/README.md index 4851ebb..f4f4d09 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,8 @@ Available targets: | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [terraform](#requirement\_terraform) | >= 0.15.0 | +| [local](#requirement\_local) | >= 1.2 | ## Providers @@ -177,8 +178,8 @@ No resources. |------|-------------|------|---------|:--------:| | [command](#input\_command) | The command that is passed to the container | `list(string)` | `null` | no | | [container\_cpu](#input\_container\_cpu) | 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 | `number` | `0` | no | -| [container\_definition](#input\_container\_definition) | Container definition overrides which allows for extra keys or overriding existing keys. | `map(any)` | `{}` | no | -| [container\_depends\_on](#input\_container\_depends\_on) | 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. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY |
list(object({
containerName = string
condition = string
}))
| `null` | no | +| [container\_definition](#input\_container\_definition) | Container definition overrides which allows for extra keys or overriding existing keys. |
object({
command = optional(list(string))
cpu = optional(number)
dependsOn = optional(list(object({
condition = string
containerName = string
})))
disableNetworking = optional(bool)
dnsSearchDomains = optional(list(string))
dnsServers = optional(list(string))
dockerLabels = optional(map(string))
dockerSecurityOptions = optional(list(string))
entryPoint = optional(list(string))
environment = optional(list(object({
name = string
value = string
})))
environmentFiles = optional(list(object({
type = string
value = string
})))
essential = optional(bool)
extraHosts = optional(list(object({
hostname = string
ipAddress = string
})))
firelensConfiguration = optional(object({
options = optional(map(string))
type = string
}))
healthCheck = optional(object({
command = list(string)
interval = optional(number)
retries = optional(number)
startPeriod = optional(number)
timeout = optional(number)
}))
hostname = optional(string)
image = optional(string)
interactive = optional(bool)
links = optional(list(string))
linuxParameters = optional(object({
capabilities = optional(object({
add = optional(list(string))
drop = optional(list(string))
}))
devices = optional(list(object({
containerPath = string
hostPath = string
permissions = optional(list(string))
})))
initProcessEnabled = optional(bool)
maxSwap = optional(number)
sharedMemorySize = optional(number)
swappiness = optional(number)
tmpfs = optional(list(object({
containerPath = string
mountOptions = optional(list(string))
size = number
})))
}))
logConfiguration = optional(object({
logDriver = string
options = optional(map(string))
secretOptions = optional(list(object({
name = string
valueFrom = string
})))
}))
memory = optional(number)
memoryReservation = optional(number)
mountPoints = optional(list(object({
containerPath = optional(string)
readOnly = optional(bool)
sourceVolume = optional(string)
})))
name = optional(string)
portMappings = optional(list(object({
containerPort = number
hostPort = optional(number)
protocol = optional(string)
})))
privileged = optional(bool)
pseudoTerminal = optional(bool)
readonlyRootFilesystem = optional(bool)
repositoryCredentials = optional(object({
credentialsParameter = string
}))
resourceRequirements = optional(list(object({
type = string
value = string
})))
secrets = optional(list(object({
name = string
valueFrom = string
})))
startTimeout = optional(number)
stopTimeout = optional(number)
systemControls = optional(list(object({
namespace = string
value = string
})))
ulimits = optional(list(object({
hardLimit = number
name = string
softLimit = number
})))
user = optional(string)
volumesFrom = optional(list(object({
readOnly = optional(bool)
sourceContainer = string
})))
workingDirectory = optional(string)
})
| `{}` | no | +| [container\_depends\_on](#input\_container\_depends\_on) | 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. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY |
list(object({
condition = string
containerName = string
}))
| `null` | no | | [container\_image](#input\_container\_image) | The image used to start the container. Images in the Docker Hub registry available by default | `string` | n/a | yes | | [container\_memory](#input\_container\_memory) | The amount of memory (in MiB) to allow the container to use. This is a hard limit, if the container attempts to exceed the container\_memory, the container is killed. This field is optional for Fargate launch type and the total amount of container\_memory of all containers in a task will need to be lower than the task memory value | `number` | `null` | no | | [container\_memory\_reservation](#input\_container\_memory\_reservation) | The amount of memory (in MiB) to reserve for the container. If container needs to exceed this threshold, it can do so up to the set container\_memory hard limit | `number` | `null` | no | @@ -189,33 +190,33 @@ No resources. | [docker\_labels](#input\_docker\_labels) | The configuration options to send to the `docker_labels` | `map(string)` | `null` | no | | [docker\_security\_options](#input\_docker\_security\_options) | A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems. | `list(string)` | `null` | no | | [entrypoint](#input\_entrypoint) | The entry point that is passed to the container | `list(string)` | `null` | no | -| [environment](#input\_environment) | The environment variables to pass to the container. This is a list of maps. map\_environment overrides environment |
list(object({
name = string
value = string
}))
| `[]` | no | -| [environment\_files](#input\_environment\_files) | One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps |
list(object({
value = string
type = string
}))
| `null` | no | +| [environment](#input\_environment) | The environment variables to pass to the container. This is a list of maps. map\_environment overrides environment |
list(object({
name = string
value = string
}))
| `null` | no | +| [environment\_files](#input\_environment\_files) | One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps |
list(object({
type = string
value = string
}))
| `null` | no | | [essential](#input\_essential) | 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 | `bool` | `true` | no | -| [extra\_hosts](#input\_extra\_hosts) | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps |
list(object({
ipAddress = string
hostname = string
}))
| `null` | no | -| [firelens\_configuration](#input\_firelens\_configuration) | 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 |
object({
type = string
options = map(string)
})
| `null` | no | -| [healthcheck](#input\_healthcheck) | 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) |
object({
command = list(string)
retries = number
timeout = number
interval = number
startPeriod = number
})
| `null` | no | +| [extra\_hosts](#input\_extra\_hosts) | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps |
list(object({
hostname = string
ipAddress = string
}))
| `null` | no | +| [firelens\_configuration](#input\_firelens\_configuration) | 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 |
object({
options = optional(map(string))
type = string
})
| `null` | no | +| [healthcheck](#input\_healthcheck) | 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) |
object({
command = list(string)
interval = optional(number)
retries = optional(number)
startPeriod = optional(number)
timeout = optional(number)
})
| `null` | no | | [hostname](#input\_hostname) | The hostname to use for your container. | `string` | `null` | no | | [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` | `null` | no | | [links](#input\_links) | List of container names this container can communicate with without port mappings | `list(string)` | `null` | no | -| [linux\_parameters](#input\_linux\_parameters) | 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 |
object({
capabilities = object({
add = list(string)
drop = list(string)
})
devices = list(object({
containerPath = string
hostPath = string
permissions = list(string)
}))
initProcessEnabled = bool
maxSwap = number
sharedMemorySize = number
swappiness = number
tmpfs = list(object({
containerPath = string
mountOptions = list(string)
size = number
}))
})
| `null` | no | -| [log\_configuration](#input\_log\_configuration) | 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 | `any` | `null` | no | +| [linux\_parameters](#input\_linux\_parameters) | 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 |
object({
capabilities = optional(object({
add = optional(list(string))
drop = optional(list(string))
}))
devices = optional(list(object({
containerPath = string
hostPath = string
permissions = optional(list(string))
})))
initProcessEnabled = optional(bool)
maxSwap = optional(number)
sharedMemorySize = optional(number)
swappiness = optional(number)
tmpfs = optional(list(object({
containerPath = string
mountOptions = optional(list(string))
size = number
})))
})
| `null` | no | +| [log\_configuration](#input\_log\_configuration) | 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 |
object({
logDriver = string
options = optional(map(string))
secretOptions = optional(list(object({
name = string
valueFrom = string
})))
})
| `null` | no | | [map\_environment](#input\_map\_environment) | The environment variables to pass to the container. This is a map of string: {key: value}. map\_environment overrides environment | `map(string)` | `null` | no | | [map\_secrets](#input\_map\_secrets) | The secrets variables to pass to the container. This is a map of string: {key: value}. map\_secrets overrides secrets | `map(string)` | `null` | no | -| [mount\_points](#input\_mount\_points) | Container mount points. This is a list of maps, where each map should contain `containerPath`, `sourceVolume` and `readOnly` |
list(object({
containerPath = string
sourceVolume = string
readOnly = bool
}))
| `[]` | no | -| [port\_mappings](#input\_port\_mappings) | 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 |
list(object({
containerPort = number
hostPort = number
protocol = string
}))
| `[]` | no | +| [mount\_points](#input\_mount\_points) | Container mount points. This is a list of maps, where each map should contain `containerPath`, `sourceVolume` and `readOnly` |
list(object({
containerPath = optional(string)
readOnly = optional(bool)
sourceVolume = optional(string)
}))
| `null` | no | +| [port\_mappings](#input\_port\_mappings) | 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 |
list(object({
containerPort = number
hostPort = optional(number)
protocol = optional(string)
}))
| `null` | no | | [privileged](#input\_privileged) | When this variable is `true`, the container is given elevated privileges on the host container instance (similar to the root user). This parameter is not supported for Windows containers or tasks using the Fargate launch type. | `bool` | `null` | no | | [pseudo\_terminal](#input\_pseudo\_terminal) | When this parameter is true, a TTY is allocated. | `bool` | `null` | no | | [readonly\_root\_filesystem](#input\_readonly\_root\_filesystem) | 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 | `bool` | `false` | no | -| [repository\_credentials](#input\_repository\_credentials) | 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 | +| [repository\_credentials](#input\_repository\_credentials) | 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 |
object({
credentialsParameter = string
})
| `null` | no | | [resource\_requirements](#input\_resource\_requirements) | The type and amount of a resource to assign to a container. The only supported resource is a GPU. |
list(object({
type = string
value = string
}))
| `null` | no | -| [secrets](#input\_secrets) | The secrets to pass to the container. This is a list of maps |
list(object({
name = string
valueFrom = string
}))
| `[]` | no | +| [secrets](#input\_secrets) | The secrets to pass to the container. This is a list of maps |
list(object({
name = string
valueFrom = string
}))
| `null` | no | | [start\_timeout](#input\_start\_timeout) | Time duration (in seconds) to wait before giving up on resolving dependencies for a container | `number` | `null` | no | | [stop\_timeout](#input\_stop\_timeout) | Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own | `number` | `null` | no | -| [system\_controls](#input\_system\_controls) | 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 = ""} | `list(map(string))` | `null` | no | -| [ulimits](#input\_ulimits) | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" |
list(object({
name = string
hardLimit = number
softLimit = number
}))
| `null` | no | +| [system\_controls](#input\_system\_controls) | 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 = ""} |
list(object({
namespace = string
value = string
}))
| `null` | no | +| [ulimits](#input\_ulimits) | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" |
list(object({
hardLimit = number
name = string
softLimit = number
}))
| `null` | no | | [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 | -| [volumes\_from](#input\_volumes\_from) | 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) |
list(object({
sourceContainer = string
readOnly = bool
}))
| `[]` | no | +| [volumes\_from](#input\_volumes\_from) | 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) |
list(object({
readOnly = optional(bool)
sourceContainer = string
}))
| `null` | no | | [working\_directory](#input\_working\_directory) | The working directory to run commands inside the container | `string` | `null` | no | ## Outputs diff --git a/docs/terraform.md b/docs/terraform.md index bf90313..7acc36f 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -3,7 +3,8 @@ | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [terraform](#requirement\_terraform) | >= 0.15.0 | +| [local](#requirement\_local) | >= 1.2 | ## Providers @@ -23,8 +24,8 @@ No resources. |------|-------------|------|---------|:--------:| | [command](#input\_command) | The command that is passed to the container | `list(string)` | `null` | no | | [container\_cpu](#input\_container\_cpu) | 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 | `number` | `0` | no | -| [container\_definition](#input\_container\_definition) | Container definition overrides which allows for extra keys or overriding existing keys. | `map(any)` | `{}` | no | -| [container\_depends\_on](#input\_container\_depends\_on) | 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. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY |
list(object({
containerName = string
condition = string
}))
| `null` | no | +| [container\_definition](#input\_container\_definition) | Container definition overrides which allows for extra keys or overriding existing keys. |
object({
command = optional(list(string))
cpu = optional(number)
dependsOn = optional(list(object({
condition = string
containerName = string
})))
disableNetworking = optional(bool)
dnsSearchDomains = optional(list(string))
dnsServers = optional(list(string))
dockerLabels = optional(map(string))
dockerSecurityOptions = optional(list(string))
entryPoint = optional(list(string))
environment = optional(list(object({
name = string
value = string
})))
environmentFiles = optional(list(object({
type = string
value = string
})))
essential = optional(bool)
extraHosts = optional(list(object({
hostname = string
ipAddress = string
})))
firelensConfiguration = optional(object({
options = optional(map(string))
type = string
}))
healthCheck = optional(object({
command = list(string)
interval = optional(number)
retries = optional(number)
startPeriod = optional(number)
timeout = optional(number)
}))
hostname = optional(string)
image = optional(string)
interactive = optional(bool)
links = optional(list(string))
linuxParameters = optional(object({
capabilities = optional(object({
add = optional(list(string))
drop = optional(list(string))
}))
devices = optional(list(object({
containerPath = string
hostPath = string
permissions = optional(list(string))
})))
initProcessEnabled = optional(bool)
maxSwap = optional(number)
sharedMemorySize = optional(number)
swappiness = optional(number)
tmpfs = optional(list(object({
containerPath = string
mountOptions = optional(list(string))
size = number
})))
}))
logConfiguration = optional(object({
logDriver = string
options = optional(map(string))
secretOptions = optional(list(object({
name = string
valueFrom = string
})))
}))
memory = optional(number)
memoryReservation = optional(number)
mountPoints = optional(list(object({
containerPath = optional(string)
readOnly = optional(bool)
sourceVolume = optional(string)
})))
name = optional(string)
portMappings = optional(list(object({
containerPort = number
hostPort = optional(number)
protocol = optional(string)
})))
privileged = optional(bool)
pseudoTerminal = optional(bool)
readonlyRootFilesystem = optional(bool)
repositoryCredentials = optional(object({
credentialsParameter = string
}))
resourceRequirements = optional(list(object({
type = string
value = string
})))
secrets = optional(list(object({
name = string
valueFrom = string
})))
startTimeout = optional(number)
stopTimeout = optional(number)
systemControls = optional(list(object({
namespace = string
value = string
})))
ulimits = optional(list(object({
hardLimit = number
name = string
softLimit = number
})))
user = optional(string)
volumesFrom = optional(list(object({
readOnly = optional(bool)
sourceContainer = string
})))
workingDirectory = optional(string)
})
| `{}` | no | +| [container\_depends\_on](#input\_container\_depends\_on) | 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. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY |
list(object({
condition = string
containerName = string
}))
| `null` | no | | [container\_image](#input\_container\_image) | The image used to start the container. Images in the Docker Hub registry available by default | `string` | n/a | yes | | [container\_memory](#input\_container\_memory) | The amount of memory (in MiB) to allow the container to use. This is a hard limit, if the container attempts to exceed the container\_memory, the container is killed. This field is optional for Fargate launch type and the total amount of container\_memory of all containers in a task will need to be lower than the task memory value | `number` | `null` | no | | [container\_memory\_reservation](#input\_container\_memory\_reservation) | The amount of memory (in MiB) to reserve for the container. If container needs to exceed this threshold, it can do so up to the set container\_memory hard limit | `number` | `null` | no | @@ -35,33 +36,33 @@ No resources. | [docker\_labels](#input\_docker\_labels) | The configuration options to send to the `docker_labels` | `map(string)` | `null` | no | | [docker\_security\_options](#input\_docker\_security\_options) | A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems. | `list(string)` | `null` | no | | [entrypoint](#input\_entrypoint) | The entry point that is passed to the container | `list(string)` | `null` | no | -| [environment](#input\_environment) | The environment variables to pass to the container. This is a list of maps. map\_environment overrides environment |
list(object({
name = string
value = string
}))
| `[]` | no | -| [environment\_files](#input\_environment\_files) | One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps |
list(object({
value = string
type = string
}))
| `null` | no | +| [environment](#input\_environment) | The environment variables to pass to the container. This is a list of maps. map\_environment overrides environment |
list(object({
name = string
value = string
}))
| `null` | no | +| [environment\_files](#input\_environment\_files) | One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps |
list(object({
type = string
value = string
}))
| `null` | no | | [essential](#input\_essential) | 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 | `bool` | `true` | no | -| [extra\_hosts](#input\_extra\_hosts) | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps |
list(object({
ipAddress = string
hostname = string
}))
| `null` | no | -| [firelens\_configuration](#input\_firelens\_configuration) | 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 |
object({
type = string
options = map(string)
})
| `null` | no | -| [healthcheck](#input\_healthcheck) | 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) |
object({
command = list(string)
retries = number
timeout = number
interval = number
startPeriod = number
})
| `null` | no | +| [extra\_hosts](#input\_extra\_hosts) | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps |
list(object({
hostname = string
ipAddress = string
}))
| `null` | no | +| [firelens\_configuration](#input\_firelens\_configuration) | 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 |
object({
options = optional(map(string))
type = string
})
| `null` | no | +| [healthcheck](#input\_healthcheck) | 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) |
object({
command = list(string)
interval = optional(number)
retries = optional(number)
startPeriod = optional(number)
timeout = optional(number)
})
| `null` | no | | [hostname](#input\_hostname) | The hostname to use for your container. | `string` | `null` | no | | [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` | `null` | no | | [links](#input\_links) | List of container names this container can communicate with without port mappings | `list(string)` | `null` | no | -| [linux\_parameters](#input\_linux\_parameters) | 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 |
object({
capabilities = object({
add = list(string)
drop = list(string)
})
devices = list(object({
containerPath = string
hostPath = string
permissions = list(string)
}))
initProcessEnabled = bool
maxSwap = number
sharedMemorySize = number
swappiness = number
tmpfs = list(object({
containerPath = string
mountOptions = list(string)
size = number
}))
})
| `null` | no | -| [log\_configuration](#input\_log\_configuration) | 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 | `any` | `null` | no | +| [linux\_parameters](#input\_linux\_parameters) | 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 |
object({
capabilities = optional(object({
add = optional(list(string))
drop = optional(list(string))
}))
devices = optional(list(object({
containerPath = string
hostPath = string
permissions = optional(list(string))
})))
initProcessEnabled = optional(bool)
maxSwap = optional(number)
sharedMemorySize = optional(number)
swappiness = optional(number)
tmpfs = optional(list(object({
containerPath = string
mountOptions = optional(list(string))
size = number
})))
})
| `null` | no | +| [log\_configuration](#input\_log\_configuration) | 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 |
object({
logDriver = string
options = optional(map(string))
secretOptions = optional(list(object({
name = string
valueFrom = string
})))
})
| `null` | no | | [map\_environment](#input\_map\_environment) | The environment variables to pass to the container. This is a map of string: {key: value}. map\_environment overrides environment | `map(string)` | `null` | no | | [map\_secrets](#input\_map\_secrets) | The secrets variables to pass to the container. This is a map of string: {key: value}. map\_secrets overrides secrets | `map(string)` | `null` | no | -| [mount\_points](#input\_mount\_points) | Container mount points. This is a list of maps, where each map should contain `containerPath`, `sourceVolume` and `readOnly` |
list(object({
containerPath = string
sourceVolume = string
readOnly = bool
}))
| `[]` | no | -| [port\_mappings](#input\_port\_mappings) | 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 |
list(object({
containerPort = number
hostPort = number
protocol = string
}))
| `[]` | no | +| [mount\_points](#input\_mount\_points) | Container mount points. This is a list of maps, where each map should contain `containerPath`, `sourceVolume` and `readOnly` |
list(object({
containerPath = optional(string)
readOnly = optional(bool)
sourceVolume = optional(string)
}))
| `null` | no | +| [port\_mappings](#input\_port\_mappings) | 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 |
list(object({
containerPort = number
hostPort = optional(number)
protocol = optional(string)
}))
| `null` | no | | [privileged](#input\_privileged) | When this variable is `true`, the container is given elevated privileges on the host container instance (similar to the root user). This parameter is not supported for Windows containers or tasks using the Fargate launch type. | `bool` | `null` | no | | [pseudo\_terminal](#input\_pseudo\_terminal) | When this parameter is true, a TTY is allocated. | `bool` | `null` | no | | [readonly\_root\_filesystem](#input\_readonly\_root\_filesystem) | 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 | `bool` | `false` | no | -| [repository\_credentials](#input\_repository\_credentials) | 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 | +| [repository\_credentials](#input\_repository\_credentials) | 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 |
object({
credentialsParameter = string
})
| `null` | no | | [resource\_requirements](#input\_resource\_requirements) | The type and amount of a resource to assign to a container. The only supported resource is a GPU. |
list(object({
type = string
value = string
}))
| `null` | no | -| [secrets](#input\_secrets) | The secrets to pass to the container. This is a list of maps |
list(object({
name = string
valueFrom = string
}))
| `[]` | no | +| [secrets](#input\_secrets) | The secrets to pass to the container. This is a list of maps |
list(object({
name = string
valueFrom = string
}))
| `null` | no | | [start\_timeout](#input\_start\_timeout) | Time duration (in seconds) to wait before giving up on resolving dependencies for a container | `number` | `null` | no | | [stop\_timeout](#input\_stop\_timeout) | Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own | `number` | `null` | no | -| [system\_controls](#input\_system\_controls) | 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 = ""} | `list(map(string))` | `null` | no | -| [ulimits](#input\_ulimits) | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" |
list(object({
name = string
hardLimit = number
softLimit = number
}))
| `null` | no | +| [system\_controls](#input\_system\_controls) | 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 = ""} |
list(object({
namespace = string
value = string
}))
| `null` | no | +| [ulimits](#input\_ulimits) | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" |
list(object({
hardLimit = number
name = string
softLimit = number
}))
| `null` | no | | [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 | -| [volumes\_from](#input\_volumes\_from) | 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) |
list(object({
sourceContainer = string
readOnly = bool
}))
| `[]` | no | +| [volumes\_from](#input\_volumes\_from) | 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) |
list(object({
readOnly = optional(bool)
sourceContainer = string
}))
| `null` | no | | [working\_directory](#input\_working\_directory) | The working directory to run commands inside the container | `string` | `null` | no | ## Outputs diff --git a/examples/complete/fixtures.us-east-2.tfvars b/examples/complete/fixtures.us-east-2.tfvars index eee59fe..ed65f82 100644 --- a/examples/complete/fixtures.us-east-2.tfvars +++ b/examples/complete/fixtures.us-east-2.tfvars @@ -49,17 +49,18 @@ port_mappings = [ log_configuration = { logDriver = "json-file" options = { - "max-size" = "10m" - "max-file" = "3" + max-size = "10m" + max-file = "3" } secretOptions = null } privileged = false -extra_hosts = [{ - ipAddress = "127.0.0.1" - hostname = "app.local" +extra_hosts = [ + { + ipAddress = "127.0.0.1" + hostname = "app.local" }, ] diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index e157d07..51e9ff4 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -1,7 +1,3 @@ -variable "region" { - type = string -} - variable "container_name" { type = string description = "The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, _ allowed)" @@ -24,32 +20,145 @@ variable "container_memory_reservation" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html variable "container_definition" { - type = map(any) + type = object({ + command = optional(list(string)) + cpu = optional(number) + dependsOn = optional(list(object({ + condition = string + containerName = string + }))) + disableNetworking = optional(bool) + dnsSearchDomains = optional(list(string)) + dnsServers = optional(list(string)) + dockerLabels = optional(map(string)) + dockerSecurityOptions = optional(list(string)) + entryPoint = optional(list(string)) + environment = optional(list(object({ + name = string + value = string + }))) + environmentFiles = optional(list(object({ + type = string + value = string + }))) + essential = optional(bool) + extraHosts = optional(list(object({ + hostname = string + ipAddress = string + }))) + firelensConfiguration = optional(object({ + options = optional(map(string)) + type = string + })) + healthCheck = optional(object({ + command = list(string) + interval = optional(number) + retries = optional(number) + startPeriod = optional(number) + timeout = optional(number) + })) + hostname = optional(string) + image = optional(string) + interactive = optional(bool) + links = optional(list(string)) + linuxParameters = optional(object({ + capabilities = optional(object({ + add = optional(list(string)) + drop = optional(list(string)) + })) + devices = optional(list(object({ + containerPath = string + hostPath = string + permissions = optional(list(string)) + }))) + initProcessEnabled = optional(bool) + maxSwap = optional(number) + sharedMemorySize = optional(number) + swappiness = optional(number) + tmpfs = optional(list(object({ + containerPath = string + mountOptions = optional(list(string)) + size = number + }))) + })) + logConfiguration = optional(object({ + logDriver = string + options = optional(map(string)) + secretOptions = optional(list(object({ + name = string + valueFrom = string + }))) + })) + memory = optional(number) + memoryReservation = optional(number) + mountPoints = optional(list(object({ + containerPath = optional(string) + readOnly = optional(bool) + sourceVolume = optional(string) + }))) + name = optional(string) + portMappings = optional(list(object({ + containerPort = number + hostPort = optional(number) + protocol = optional(string) + }))) + privileged = optional(bool) + pseudoTerminal = optional(bool) + readonlyRootFilesystem = optional(bool) + repositoryCredentials = optional(object({ + credentialsParameter = string + })) + resourceRequirements = optional(list(object({ + type = string + value = string + }))) + secrets = optional(list(object({ + name = string + valueFrom = string + }))) + startTimeout = optional(number) + stopTimeout = optional(number) + systemControls = optional(list(object({ + namespace = string + value = string + }))) + ulimits = optional(list(object({ + hardLimit = number + name = string + softLimit = number + }))) + user = optional(string) + volumesFrom = optional(list(object({ + readOnly = optional(bool) + sourceContainer = string + }))) + workingDirectory = optional(string) + }) description = "Container definition overrides which allows for extra keys or overriding existing keys." default = {} } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PortMapping.html variable "port_mappings" { type = list(object({ containerPort = number - hostPort = number - protocol = string + hostPort = optional(number) + protocol = optional(string) })) - 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" - - default = [] + default = null } # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html variable "healthcheck" { type = object({ command = list(string) - retries = number - timeout = number - interval = number - startPeriod = number + interval = optional(number) + retries = optional(number) + startPeriod = optional(number) + timeout = optional(number) }) description = "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)" default = null @@ -85,19 +194,20 @@ variable "working_directory" { default = null } -variable "container_environment" { +variable "environment" { type = list(object({ name = string value = string })) description = "The environment variables to pass to the container. This is a list of maps. map_environment overrides environment" - default = [] + default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HostEntry.html variable "extra_hosts" { type = list(object({ - ipAddress = string hostname = string + ipAddress = string })) description = "A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps" default = null @@ -109,16 +219,23 @@ variable "map_environment" { default = null } +variable "map_secrets" { + type = map(string) + description = "The secrets variables to pass to the container. This is a map of string: {key: value}. map_secrets overrides secrets" + default = null +} + # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_EnvironmentFile.html variable "environment_files" { type = list(object({ - value = string type = string + value = string })) description = "One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Secret.html variable "secrets" { type = list(object({ name = string @@ -137,24 +254,24 @@ variable "readonly_root_filesystem" { # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html variable "linux_parameters" { type = object({ - capabilities = object({ - add = list(string) - drop = list(string) - }) - devices = list(object({ + capabilities = optional(object({ + add = optional(list(string)) + drop = optional(list(string)) + })) + devices = optional(list(object({ containerPath = string hostPath = string - permissions = list(string) - })) - initProcessEnabled = bool - maxSwap = number - sharedMemorySize = number - swappiness = number - tmpfs = list(object({ + permissions = optional(list(string)) + }))) + initProcessEnabled = optional(bool) + maxSwap = optional(number) + sharedMemorySize = optional(number) + swappiness = optional(number) + tmpfs = optional(list(object({ containerPath = string - mountOptions = list(string) + mountOptions = optional(list(string)) size = number - })) + }))) }) 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" default = null @@ -162,7 +279,14 @@ variable "linux_parameters" { # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html variable "log_configuration" { - type = any + type = object({ + logDriver = string + options = optional(map(string)) + secretOptions = optional(list(object({ + name = string + valueFrom = string + }))) + }) description = "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" default = null } @@ -170,18 +294,22 @@ variable "log_configuration" { # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html variable "firelens_configuration" { type = object({ + options = optional(map(string)) type = string - options = map(string) }) description = "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" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_MountPoint.html variable "mount_points" { - type = list(any) - - description = "Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`. The `readOnly` key is optional." - default = [] + type = list(object({ + containerPath = optional(string) + readOnly = optional(bool) + sourceVolume = optional(string) + })) + description = "Container mount points. This is a list of maps, where each map should contain `containerPath`, `sourceVolume` and `readOnly`" + default = null } variable "dns_servers" { @@ -196,29 +324,34 @@ variable "dns_search_domains" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Ulimit.html variable "ulimits" { type = list(object({ - name = string hardLimit = number + name = string softLimit = number })) description = "Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\"" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RepositoryCredentials.html variable "repository_credentials" { - type = map(string) + type = object({ + credentialsParameter = string + }) 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" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_VolumeFrom.html variable "volumes_from" { type = list(object({ + readOnly = optional(bool) sourceContainer = string - readOnly = bool })) description = "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)" - default = [] + default = null } variable "links" { @@ -233,10 +366,11 @@ variable "user" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDependency.html variable "container_depends_on" { type = list(object({ - containerName = string condition = string + containerName = string })) description = "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. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY" default = null @@ -266,8 +400,12 @@ variable "privileged" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_SystemControl.html variable "system_controls" { - type = list(map(string)) + type = list(object({ + namespace = string + value = string + })) description = "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 = \"\"}" default = null } @@ -301,3 +439,13 @@ variable "docker_security_options" { description = "A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems." default = null } + +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ResourceRequirement.html +variable "resource_requirements" { + type = list(object({ + type = string + value = string + })) + description = "The type and amount of a resource to assign to a container. The only supported resource is a GPU." + default = null +} diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index 81ea840..c858991 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -1,5 +1,5 @@ terraform { - required_version = ">= 0.13.0" + required_version = ">= 0.15.0" required_providers { local = { diff --git a/main.tf b/main.tf index 39d77de..7186b34 100644 --- a/main.tf +++ b/main.tf @@ -1,57 +1,30 @@ locals { - # Sort environment variables so terraform will not try to recreate on each plan/apply - env_vars_keys = var.map_environment != null ? keys(var.map_environment) : var.environment != null ? [for m in var.environment : lookup(m, "name")] : [] - env_vars_values = var.map_environment != null ? values(var.map_environment) : var.environment != null ? [for m in var.environment : lookup(m, "value")] : [] - env_vars_as_map = zipmap(local.env_vars_keys, local.env_vars_values) - sorted_env_vars_keys = sort(local.env_vars_keys) + # Sort environment variables & secrets so terraform will not try to recreate on each plan/apply + env_as_map = var.map_environment != null ? var.map_environment : var.environment != null ? { for m in var.environment : m.name => m.value } : null + secrets_as_map = var.map_secrets != null ? var.map_secrets : var.secrets != null ? { for m in var.secrets : m.name => m.valueFrom } : null - sorted_environment_vars = [ - for key in local.sorted_env_vars_keys : + # https://www.terraform.io/docs/configuration/expressions.html#null + final_environment_vars = local.env_as_map != null ? [ + for k, v in local.env_as_map : { - name = key - value = lookup(local.env_vars_as_map, key) + name = k + value = v } - ] - - # Sort secrets so terraform will not try to recreate on each plan/apply - secrets_keys = var.map_secrets != null ? keys(var.map_secrets) : var.secrets != null ? [for m in var.secrets : lookup(m, "name")] : [] - secrets_values = var.map_secrets != null ? values(var.map_secrets) : var.secrets != null ? [for m in var.secrets : lookup(m, "valueFrom")] : [] - secrets_as_map = zipmap(local.secrets_keys, local.secrets_values) - sorted_secrets_keys = sort(local.secrets_keys) - - sorted_secrets_vars = [ - for key in local.sorted_secrets_keys : + ] : null + final_secrets_vars = local.secrets_as_map != null ? [ + for k, v in local.secrets_as_map : { - name = key - valueFrom = lookup(local.secrets_as_map, key) + name = k + valueFrom = v } - ] - - mount_points = length(var.mount_points) > 0 ? [ - for mount_point in var.mount_points : { - containerPath = lookup(mount_point, "containerPath") - sourceVolume = lookup(mount_point, "sourceVolume") - readOnly = tobool(lookup(mount_point, "readOnly", false)) - } - ] : var.mount_points + ] : null # https://www.terraform.io/docs/configuration/expressions.html#null final_environment_vars = length(local.sorted_environment_vars) > 0 ? local.sorted_environment_vars : [] final_secrets_vars = length(local.sorted_secrets_vars) > 0 ? local.sorted_secrets_vars : null - log_configuration_secret_options = var.log_configuration != null ? lookup(var.log_configuration, "secretOptions", null) : null - log_configuration_with_null = var.log_configuration == null ? null : { - logDriver = tostring(lookup(var.log_configuration, "logDriver")) - options = tomap(lookup(var.log_configuration, "options")) - secretOptions = local.log_configuration_secret_options == null ? null : [ - for secret_option in tolist(local.log_configuration_secret_options) : { - name = tostring(lookup(secret_option, "name")) - valueFrom = tostring(lookup(secret_option, "valueFrom")) - } - ] - } - log_configuration_without_null = local.log_configuration_with_null == null ? null : { - for k, v in local.log_configuration_with_null : + log_configuration_without_null = var.log_configuration == null ? null : { + for k, v in var.log_configuration : k => v if v != null } @@ -65,7 +38,7 @@ locals { command = var.command workingDirectory = var.working_directory readonlyRootFilesystem = var.readonly_root_filesystem - mountPoints = local.mount_points + mountPoints = var.mount_points dnsServers = var.dns_servers dnsSearchDomains = var.dns_search_domains ulimits = var.ulimits @@ -104,5 +77,6 @@ locals { k => v if v != null } - json_map = jsonencode(merge(local.container_definition_without_null, var.container_definition)) + final_container_definition = merge(local.container_definition_without_null, var.container_definition) + json_map = jsonencode(local.final_container_definition) } diff --git a/outputs.tf b/outputs.tf index 5937d36..956f8f0 100644 --- a/outputs.tf +++ b/outputs.tf @@ -10,7 +10,7 @@ output "json_map_encoded" { output "json_map_object" { description = "JSON map encoded container definition" - value = jsondecode(local.json_map) + value = local.final_container_definition } output "sensitive_json_map_encoded_list" { @@ -27,6 +27,6 @@ output "sensitive_json_map_encoded" { output "sensitive_json_map_object" { description = "JSON map encoded container definition (sensitive)" - value = jsondecode(local.json_map) + value = local.final_container_definition sensitive = true } diff --git a/variables.tf b/variables.tf index 44cb1ec..51e9ff4 100644 --- a/variables.tf +++ b/variables.tf @@ -20,32 +20,145 @@ variable "container_memory_reservation" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html variable "container_definition" { - type = map(any) + type = object({ + command = optional(list(string)) + cpu = optional(number) + dependsOn = optional(list(object({ + condition = string + containerName = string + }))) + disableNetworking = optional(bool) + dnsSearchDomains = optional(list(string)) + dnsServers = optional(list(string)) + dockerLabels = optional(map(string)) + dockerSecurityOptions = optional(list(string)) + entryPoint = optional(list(string)) + environment = optional(list(object({ + name = string + value = string + }))) + environmentFiles = optional(list(object({ + type = string + value = string + }))) + essential = optional(bool) + extraHosts = optional(list(object({ + hostname = string + ipAddress = string + }))) + firelensConfiguration = optional(object({ + options = optional(map(string)) + type = string + })) + healthCheck = optional(object({ + command = list(string) + interval = optional(number) + retries = optional(number) + startPeriod = optional(number) + timeout = optional(number) + })) + hostname = optional(string) + image = optional(string) + interactive = optional(bool) + links = optional(list(string)) + linuxParameters = optional(object({ + capabilities = optional(object({ + add = optional(list(string)) + drop = optional(list(string)) + })) + devices = optional(list(object({ + containerPath = string + hostPath = string + permissions = optional(list(string)) + }))) + initProcessEnabled = optional(bool) + maxSwap = optional(number) + sharedMemorySize = optional(number) + swappiness = optional(number) + tmpfs = optional(list(object({ + containerPath = string + mountOptions = optional(list(string)) + size = number + }))) + })) + logConfiguration = optional(object({ + logDriver = string + options = optional(map(string)) + secretOptions = optional(list(object({ + name = string + valueFrom = string + }))) + })) + memory = optional(number) + memoryReservation = optional(number) + mountPoints = optional(list(object({ + containerPath = optional(string) + readOnly = optional(bool) + sourceVolume = optional(string) + }))) + name = optional(string) + portMappings = optional(list(object({ + containerPort = number + hostPort = optional(number) + protocol = optional(string) + }))) + privileged = optional(bool) + pseudoTerminal = optional(bool) + readonlyRootFilesystem = optional(bool) + repositoryCredentials = optional(object({ + credentialsParameter = string + })) + resourceRequirements = optional(list(object({ + type = string + value = string + }))) + secrets = optional(list(object({ + name = string + valueFrom = string + }))) + startTimeout = optional(number) + stopTimeout = optional(number) + systemControls = optional(list(object({ + namespace = string + value = string + }))) + ulimits = optional(list(object({ + hardLimit = number + name = string + softLimit = number + }))) + user = optional(string) + volumesFrom = optional(list(object({ + readOnly = optional(bool) + sourceContainer = string + }))) + workingDirectory = optional(string) + }) description = "Container definition overrides which allows for extra keys or overriding existing keys." default = {} } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_PortMapping.html variable "port_mappings" { type = list(object({ containerPort = number - hostPort = number - protocol = string + hostPort = optional(number) + protocol = optional(string) })) - 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" - - default = [] + default = null } # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html variable "healthcheck" { type = object({ command = list(string) - retries = number - timeout = number - interval = number - startPeriod = number + interval = optional(number) + retries = optional(number) + startPeriod = optional(number) + timeout = optional(number) }) description = "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)" default = null @@ -87,13 +200,14 @@ variable "environment" { value = string })) description = "The environment variables to pass to the container. This is a list of maps. map_environment overrides environment" - default = [] + default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HostEntry.html variable "extra_hosts" { type = list(object({ - ipAddress = string hostname = string + ipAddress = string })) description = "A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps" default = null @@ -114,20 +228,21 @@ variable "map_secrets" { # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_EnvironmentFile.html variable "environment_files" { type = list(object({ - value = string type = string + value = string })) description = "One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Secret.html variable "secrets" { type = list(object({ name = string valueFrom = string })) description = "The secrets to pass to the container. This is a list of maps" - default = [] + default = null } variable "readonly_root_filesystem" { @@ -139,24 +254,24 @@ variable "readonly_root_filesystem" { # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html variable "linux_parameters" { type = object({ - capabilities = object({ - add = list(string) - drop = list(string) - }) - devices = list(object({ + capabilities = optional(object({ + add = optional(list(string)) + drop = optional(list(string)) + })) + devices = optional(list(object({ containerPath = string hostPath = string - permissions = list(string) - })) - initProcessEnabled = bool - maxSwap = number - sharedMemorySize = number - swappiness = number - tmpfs = list(object({ + permissions = optional(list(string)) + }))) + initProcessEnabled = optional(bool) + maxSwap = optional(number) + sharedMemorySize = optional(number) + swappiness = optional(number) + tmpfs = optional(list(object({ containerPath = string - mountOptions = list(string) + mountOptions = optional(list(string)) size = number - })) + }))) }) 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" default = null @@ -164,7 +279,14 @@ variable "linux_parameters" { # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html variable "log_configuration" { - type = any + type = object({ + logDriver = string + options = optional(map(string)) + secretOptions = optional(list(object({ + name = string + valueFrom = string + }))) + }) description = "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" default = null } @@ -172,22 +294,22 @@ variable "log_configuration" { # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html variable "firelens_configuration" { type = object({ + options = optional(map(string)) type = string - options = map(string) }) description = "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" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_MountPoint.html variable "mount_points" { type = list(object({ - containerPath = string - sourceVolume = string - readOnly = bool + containerPath = optional(string) + readOnly = optional(bool) + sourceVolume = optional(string) })) - description = "Container mount points. This is a list of maps, where each map should contain `containerPath`, `sourceVolume` and `readOnly`" - default = [] + default = null } variable "dns_servers" { @@ -202,29 +324,34 @@ variable "dns_search_domains" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Ulimit.html variable "ulimits" { type = list(object({ - name = string hardLimit = number + name = string softLimit = number })) description = "Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\"" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RepositoryCredentials.html variable "repository_credentials" { - type = map(string) + type = object({ + credentialsParameter = string + }) 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" default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_VolumeFrom.html variable "volumes_from" { type = list(object({ + readOnly = optional(bool) sourceContainer = string - readOnly = bool })) description = "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)" - default = [] + default = null } variable "links" { @@ -239,10 +366,11 @@ variable "user" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDependency.html variable "container_depends_on" { type = list(object({ - containerName = string condition = string + containerName = string })) description = "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. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY" default = null @@ -272,8 +400,12 @@ variable "privileged" { default = null } +# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_SystemControl.html variable "system_controls" { - type = list(map(string)) + type = list(object({ + namespace = string + value = string + })) description = "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 = \"\"}" default = null } diff --git a/versions.tf b/versions.tf index 450c502..f340cca 100644 --- a/versions.tf +++ b/versions.tf @@ -1,3 +1,13 @@ terraform { - required_version = ">= 0.13.0" + required_version = ">= 0.15.0" + + # https://www.terraform.io/language/expressions/type-constraints#experimental-optional-object-type-attributes + experiments = [module_variable_optional_attrs] + + required_providers { + local = { + source = "hashicorp/local" + version = ">= 1.2" + } + } }