Skip to content

fix: Make secretOptions optional #83

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 12 commits into from
Jun 23, 2020
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ No provider.
| 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) | <pre>object({<br> command = list(string)<br> retries = number<br> timeout = number<br> interval = number<br> startPeriod = number<br> })</pre> | `null` | no |
| links | List of container names this container can communicate with without port mappings | `list(string)` | `null` | no |
| 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 | <pre>object({<br> capabilities = object({<br> add = list(string)<br> drop = list(string)<br> })<br> devices = list(object({<br> containerPath = string<br> hostPath = string<br> permissions = list(string)<br> }))<br> initProcessEnabled = bool<br> maxSwap = number<br> sharedMemorySize = number<br> swappiness = number<br> tmpfs = list(object({<br> containerPath = string<br> mountOptions = list(string)<br> size = number<br> }))<br> })</pre> | `null` | no |
| 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 | <pre>object({<br> logDriver = string<br> options = map(string)<br> secretOptions = list(object({<br> name = string<br> valueFrom = string<br> }))<br> })</pre> | <pre>{<br> "logDriver": null,<br> "options": {},<br> "secretOptions": []<br>}</pre> | no |
| 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 |
| mount\_points | Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`. The `readOnly` key is optional. | `list` | `[]` | no |
| 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 | <pre>list(object({<br> containerPort = number<br> hostPort = number<br> protocol = string<br> }))</pre> | `[]` | no |
| 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 |
Expand Down
2 changes: 1 addition & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ No provider.
| 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) | <pre>object({<br> command = list(string)<br> retries = number<br> timeout = number<br> interval = number<br> startPeriod = number<br> })</pre> | `null` | no |
| links | List of container names this container can communicate with without port mappings | `list(string)` | `null` | no |
| 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 | <pre>object({<br> capabilities = object({<br> add = list(string)<br> drop = list(string)<br> })<br> devices = list(object({<br> containerPath = string<br> hostPath = string<br> permissions = list(string)<br> }))<br> initProcessEnabled = bool<br> maxSwap = number<br> sharedMemorySize = number<br> swappiness = number<br> tmpfs = list(object({<br> containerPath = string<br> mountOptions = list(string)<br> size = number<br> }))<br> })</pre> | `null` | no |
| 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 | <pre>object({<br> logDriver = string<br> options = map(string)<br> secretOptions = list(object({<br> name = string<br> valueFrom = string<br> }))<br> })</pre> | <pre>{<br> "logDriver": null,<br> "options": {},<br> "secretOptions": []<br>}</pre> | no |
| 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 |
| mount\_points | Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`. The `readOnly` key is optional. | `list` | `[]` | no |
| 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 | <pre>list(object({<br> containerPort = number<br> hostPort = number<br> protocol = string<br> }))</pre> | `[]` | no |
| 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 |
Expand Down
209 changes: 191 additions & 18 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
variable "region" {
type = string
description = "AWS region in which to provision the AWS resources"
}

variable "container_name" {
type = string
description = "The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, _ allowed)"
Expand All @@ -16,11 +11,19 @@ variable "container_image" {
variable "container_memory" {
type = number
description = "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"
default = null
}

variable "container_memory_reservation" {
type = number
description = "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"
default = null
}

variable "container_definition" {
type = map
description = "Container definition overrides which allows for extra keys or overriding existing keys."
default = {}
}

variable "port_mappings" {
Expand All @@ -31,16 +34,51 @@ variable "port_mappings" {
}))

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 = []
}

# 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
})
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
}

variable "container_cpu" {
type = number
description = "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"
default = 0
}

variable "essential" {
type = bool
description = "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"
default = true
}

variable "entrypoint" {
type = list(string)
description = "The entry point that is passed to the container"
default = null
}

variable "command" {
type = list(string)
description = "The command that is passed to the container"
default = null
}

variable "working_directory" {
type = string
description = "The working directory to run commands inside the container"
default = null
}

variable "environment" {
Expand All @@ -49,36 +87,171 @@ variable "environment" {
value = string
}))
description = "The environment variables to pass to the container. This is a list of maps"
default = []
}

variable "extra_hosts" {
type = list(object({
ipAddress = string
hostname = 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
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_EnvironmentFile.html
variable "environment_files" {
type = list(object({
value = string
type = 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
}

variable "secrets" {
type = list(object({
name = string
valueFrom = string
}))
description = "The secrets to pass to the container. This is a list of maps"
default = null
}

variable "readonly_root_filesystem" {
type = bool
description = "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"
default = false
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html
variable "log_configuration" {
# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html
variable "linux_parameters" {
type = object({
logDriver = string
options = map(string)
secretOptions = list(object({
name = string
valueFrom = string
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
}))
})
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
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html
variable "log_configuration" {
# type = map
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
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html
variable "firelens_configuration" {
type = object({
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
}

variable "mount_points" {
type = list

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 = []
}

variable "dns_servers" {
type = list(string)
description = "Container DNS servers. This is a list of strings specifying the IP addresses of the DNS servers"
default = null
}

variable "ulimits" {
type = list(object({
name = string
hardLimit = number
softLimit = number
}))
description = "Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\""
default = null
}

variable "repository_credentials" {
type = map(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
}

variable "volumes_from" {
type = list(object({
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 = []
}

variable "links" {
type = list(string)
description = "List of container names this container can communicate with without port mappings"
default = null
}

variable "user" {
type = string
description = "The user to run as inside the container. Can be any of these formats: user, user:group, uid, uid:gid, user:gid, uid:group"
default = "0"
}

variable "container_depends_on" {
type = list(object({
containerName = string
condition = 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
}

variable "docker_labels" {
type = map(string)
description = "The configuration options to send to the `docker_labels`"
default = null
}

variable "start_timeout" {
type = number
description = "Time duration (in seconds) to wait before giving up on resolving dependencies for a container"
default = null
}

variable "stop_timeout" {
type = number
description = "Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own"
default = null
}

variable "privileged" {
type = bool
description = "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."
default = null
}

variable "extra_hosts" {
type = list(object({
ipAddress = string
hostname = 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"
variable "system_controls" {
type = list(map(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
}
19 changes: 18 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ locals {
}
] : var.mount_points

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 :
k => v
if v != null
}

# This strange-looking variable is needed because terraform (currently) does not support explicit `null` in ternary operator,
# so this does not work: final_environment_vars = length(local.sorted_environment_vars) > 0 ? local.sorted_environment_vars : null
null_value = var.environment == null ? var.environment : null
Expand Down Expand Up @@ -51,7 +68,7 @@ locals {
healthCheck = var.healthcheck
firelensConfiguration = var.firelens_configuration
linuxParameters = var.linux_parameters
logConfiguration = var.log_configuration
logConfiguration = local.log_configuration_without_null
memory = var.container_memory
memoryReservation = var.container_memory_reservation
cpu = var.container_cpu
Expand Down
15 changes: 2 additions & 13 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,9 @@ variable "linux_parameters" {

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html
variable "log_configuration" {
type = object({
logDriver = string
options = map(string)
secretOptions = list(object({
name = string
valueFrom = string
}))
})
# type = map
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 = {
logDriver = null
options = {}
secretOptions = []
}
default = null
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html
Expand Down