diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 41408bd..c6f0ebe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: - id: terraform_docs - id: terraform_fmt repo: https://github.com/antonbabenko/pre-commit-terraform.git - rev: v1.11.0 + rev: v1.46.0 - hooks: - id: go-fmt diff --git a/README.md b/README.md index c35873f..d70238c 100644 --- a/README.md +++ b/README.md @@ -64,14 +64,14 @@ Invoking the commands defined below creates an ECS task definition with the foll [ { "command": null, - "cpu": null, + "cpu": 256, "disableNetworking": false, "dnsSearchDomains": null, "dnsServers": null, "dockerLabels": null, "dockerSecurityOptions": null, "entryPoint": null, - "environment": null, + "environment": [], "essential": true, "extraHosts": null, "healthCheck": null, @@ -81,9 +81,10 @@ Invoking the commands defined below creates an ECS task definition with the foll "links": null, "linuxParameters": null, "logConfiguration": null, + "firelensConfiguration": null, "memory": 512, "memoryReservation": null, - "mountPoints": null, + "mountPoints": [], "name": "mongo", "portMappings": [{"containerPort":27017}], "privileged": false, @@ -95,7 +96,7 @@ Invoking the commands defined below creates an ECS task definition with the foll "systemControls": null, "ulimits": null, "user": null, - "volumesFrom": null, + "volumesFrom": [], "workingDirectory": null } ] @@ -106,6 +107,12 @@ Invoking the commands defined below creates an ECS task definition with the foll By default, this module creates a task definition with a single container definition. To create a task definition with multiple container definitions, refer to the documentation of the [`merge`](modules/merge) module. +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 0.12 | + ## Providers | Name | Version | @@ -116,9 +123,9 @@ By default, this module creates a task definition with a single container defini ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|------|---------|:-----:| +|------|-------------|------|---------|:--------:| | command | The command that is passed to the container | `list(string)` | `[]` | no | -| cpu | The number of cpu units reserved for the container | `number` | `0` | no | +| cpu | The number of cpu units reserved for the container | `number` | `256` | no | | disableNetworking | When this parameter is true, networking is disabled within the container | `bool` | `false` | no | | dnsSearchDomains | A list of DNS search domains that are presented to the container | `list(string)` | `[]` | no | | dnsServers | A list of DNS servers that are presented to the container | `list(string)` | `[]` | no | @@ -128,23 +135,24 @@ By default, this module creates a task definition with a single container defini | environment | The environment variables to pass to a container | `list(map(string))` | `[]` | no | | essential | If the essential parameter of a container is marked as true, and that container fails or stops for any reason, all other containers that are part of the task are stopped | `bool` | `true` | no | | execution\_role\_arn | The Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume | `string` | `""` | no | -| extraHosts | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container | `list(string)` | `[]` | no | +| extraHosts | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container |
list(object({
ipAddress = string
hostname = string
})) | `[]` | no |
| family | You must specify a family for a task definition, which allows you to track multiple versions of the same task definition | `any` | n/a | yes |
+| firelensConfiguration | The FireLens configuration for the container | `any` | `{}` | no |
| healthCheck | The health check command and associated configuration parameters for the container | `any` | `{}` | no |
| hostname | The hostname to use for your container | `string` | `""` | no |
| image | The image used to start a container | `string` | `""` | no |
| interactive | When this parameter is true, this allows you to deploy containerized applications that require stdin or a tty to be allocated | `bool` | `false` | no |
-| ipc\_mode | The IPC resource namespace to use for the containers in the task | `string` | `"host"` | no |
+| ipc\_mode | The IPC resource namespace to use for the containers in the task | `any` | `null` | no |
| links | The link parameter allows containers to communicate with each other without the need for port mappings | `list(string)` | `[]` | no |
| linuxParameters | Linux-specific modifications that are applied to the container, such as Linux KernelCapabilities | `any` | `{}` | no |
| logConfiguration | The log configuration specification for the container | `any` | `{}` | no |
-| memory | The hard limit (in MiB) of memory to present to the container | `number` | `0` | no |
+| memory | The hard limit (in MiB) of memory to present to the container | `number` | `512` | no |
| memoryReservation | The soft limit (in MiB) of memory to reserve for the container | `number` | `0` | no |
| mountPoints | The mount points for data volumes in your container | `list(any)` | `[]` | no |
| name | The name of a container | `string` | `""` | no |
| network\_mode | The Docker networking mode to use for the containers in the task | `string` | `"bridge"` | no |
-| pid\_mode | The process namespace to use for the containers in the task | `string` | `"host"` | no |
-| placement\_constraints | An array of placement constraint objects to use for the task | `list(string)` | `[]` | no |
+| pid\_mode | The process namespace to use for the containers in the task | `any` | `null` | no |
+| placement\_constraints | An array of placement constraint objects to use for the task | list(object({
type = string
expression = string
})) | `[]` | no |
| portMappings | The list of port mappings for the container | `list(any)` | `[]` | no |
| 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 |
| pseudoTerminal | When this parameter is true, a TTY is allocated | `bool` | `false` | no |
@@ -153,14 +161,14 @@ By default, this module creates a task definition with a single container defini
| repositoryCredentials | The private repository authentication credentials to use | `map(string)` | `{}` | no |
| requires\_compatibilities | The launch type required by the task | `list(string)` | `[]` | no |
| resourceRequirements | The type and amount of a resource to assign to a container | `list(string)` | `[]` | no |
-| secrets | The secrets to pass to the container | `list(string)` | `[]` | no |
+| secrets | The secrets to pass to the container | `list(map(string))` | `[]` | no |
| systemControls | A list of namespaced kernel parameters to set in the container | `list(string)` | `[]` | no |
| tags | The metadata that you apply to the task definition to help you categorize and organize them | `map(string)` | `{}` | no |
| task\_role\_arn | The short name or full Amazon Resource Name (ARN) of the IAM role that containers in this task can assume | `string` | `""` | no |
| ulimits | A list of ulimits to set in the container | `list(any)` | `[]` | no |
| user | The user name to use inside the container | `string` | `""` | no |
| volumes | A list of volume definitions in JSON format that containers in your task may use | `list(any)` | `[]` | no |
-| volumesFrom | Data volumes to mount from another container | `list(string)` | `[]` | no |
+| volumesFrom | Data volumes to mount from another container | list(object({
readOnly = bool
sourceContainer = string
})) | `[]` | no |
| workingDirectory | The working directory in which to run commands inside the container | `string` | `""` | no |
## Outputs
diff --git a/main.tf b/main.tf
index 887ea2d..b9a4921 100644
--- a/main.tf
+++ b/main.tf
@@ -53,7 +53,8 @@ locals {
"$1",
)
- logConfiguration = jsonencode(var.logConfiguration)
+ logConfiguration = jsonencode(var.logConfiguration)
+ firelensConfiguration = jsonencode(var.firelensConfiguration)
mountPoints = replace(
replace(jsonencode(var.mountPoints), "/\"1\"/", "true"),
@@ -92,14 +93,14 @@ data "template_file" "container_definition" {
vars = {
command = local.command == "[]" ? "null" : local.command
- cpu = var.cpu == 0 ? "null" : var.cpu
+ cpu = var.cpu
disableNetworking = var.disableNetworking ? true : false
dnsSearchDomains = local.dnsSearchDomains == "[]" ? "null" : local.dnsSearchDomains
dnsServers = local.dnsServers == "[]" ? "null" : local.dnsServers
dockerLabels = local.dockerLabels == "{}" ? "null" : local.dockerLabels
dockerSecurityOptions = local.dockerSecurityOptions == "[]" ? "null" : local.dockerSecurityOptions
entryPoint = local.entryPoint == "[]" ? "null" : local.entryPoint
- environment = local.environment == "[]" ? "null" : local.environment
+ environment = local.environment == "[]" ? "[]" : local.environment
essential = var.essential ? true : false
extraHosts = local.extraHosts == "[]" ? "null" : local.extraHosts
healthCheck = local.healthCheck == "{}" ? "null" : local.healthCheck
@@ -109,21 +110,24 @@ data "template_file" "container_definition" {
links = local.links == "[]" ? "null" : local.links
linuxParameters = local.linuxParameters == "{}" ? "null" : local.linuxParameters
logConfiguration = local.logConfiguration == "{}" ? "null" : local.logConfiguration
+ firelensConfiguration = local.firelensConfiguration == "{}" ? "null" : local.firelensConfiguration
memory = var.memory == 0 ? "null" : var.memory
memoryReservation = var.memoryReservation == 0 ? "null" : var.memoryReservation
- mountPoints = local.mountPoints == "[]" ? "null" : local.mountPoints
+ mountPoints = local.mountPoints == "[]" ? "[]" : local.mountPoints
name = var.name == "" ? "null" : var.name
- portMappings = local.portMappings == "[]" ? "null" : local.portMappings
+ portMappings = local.portMappings == "[]" ? "[]" : local.portMappings
privileged = var.privileged ? true : false
pseudoTerminal = var.pseudoTerminal ? true : false
readonlyRootFilesystem = var.readonlyRootFilesystem ? true : false
repositoryCredentials = local.repositoryCredentials == "{}" ? "null" : local.repositoryCredentials
resourceRequirements = local.resourceRequirements == "[]" ? "null" : local.resourceRequirements
secrets = local.secrets == "[]" ? "null" : local.secrets
+ startTimeout = var.startTimeout
+ stopTimeout = var.stopTimeout
systemControls = local.systemControls == "[]" ? "null" : local.systemControls
ulimits = local.ulimits == "[]" ? "null" : local.ulimits
user = var.user == "" ? "null" : var.user
- volumesFrom = local.volumesFrom == "[]" ? "null" : local.volumesFrom
+ volumesFrom = local.volumesFrom == "[]" ? "[]" : local.volumesFrom
workingDirectory = var.workingDirectory == "" ? "null" : var.workingDirectory
}
}
diff --git a/modules/merge/README.md b/modules/merge/README.md
index 2d42b7b..a83a579 100644
--- a/modules/merge/README.md
+++ b/modules/merge/README.md
@@ -115,6 +115,10 @@ resource "aws_ecs_task_definition" "hello_world" {
**Note:** The `register_task_definition` flag for both task definitions is required; otherwise a task definition containing a single container definition is registered created for both the `wordpress` and `mysql` services.
+## Requirements
+
+No requirements.
+
## Providers
No provider.
@@ -122,7 +126,7 @@ No provider.
## Inputs
| Name | Description | Type | Default | Required |
-|------|-------------|------|---------|:-----:|
+|------|-------------|------|---------|:--------:|
| container\_definitions | A list of container definitions in JSON format that describe the different containers that make up your task | `list` | `[]` | no |
## Outputs
diff --git a/modules/merge/outputs.tf b/modules/merge/outputs.tf
index 398255f..240ca50 100644
--- a/modules/merge/outputs.tf
+++ b/modules/merge/outputs.tf
@@ -1,4 +1,4 @@
output "container_definitions" {
description = "A list of container definitions in JSON format that describe the different containers that make up your task"
- value = "${format("[%s]", join(",", var.container_definitions))}"
+ value = format("[%s]", join(",", var.container_definitions))
}
diff --git a/templates/container-definition.json.tpl b/templates/container-definition.json.tpl
index 4932f23..758761b 100644
--- a/templates/container-definition.json.tpl
+++ b/templates/container-definition.json.tpl
@@ -17,6 +17,7 @@
"links": ${links},
"linuxParameters": ${linuxParameters},
"logConfiguration": ${logConfiguration},
+ "firelensConfiguration": ${firelensConfiguration},
"memory": ${memory},
"memoryReservation": ${memoryReservation},
"mountPoints": ${mountPoints},
@@ -32,5 +33,7 @@
"ulimits": ${ulimits},
"user": "${user}",
"volumesFrom": ${volumesFrom},
- "workingDirectory": "${workingDirectory}"
+ "workingDirectory": "${workingDirectory}",
+ "startTimeout": ${startTimeout},
+ "stopTimeout": ${stopTimeout}
}
diff --git a/test/fixtures/multiple.json b/test/fixtures/multiple.json
index 649dd25..27d5580 100644
--- a/test/fixtures/multiple.json
+++ b/test/fixtures/multiple.json
@@ -8,7 +8,7 @@
"dockerLabels": null,
"dockerSecurityOptions": null,
"entryPoint": null,
- "environment": null,
+ "environment": [],
"essential": true,
"extraHosts": null,
"healthCheck": null,
@@ -18,9 +18,10 @@
"links": null,
"linuxParameters": null,
"logConfiguration": null,
+ "firelensConfiguration": null,
"memory": 512,
"memoryReservation": null,
- "mountPoints": null,
+ "mountPoints": [],
"name": "mongodb",
"portMappings": [
{
@@ -37,7 +38,7 @@
"systemControls": null,
"ulimits": null,
"user": null,
- "volumesFrom": null,
+ "volumesFrom": [],
"workingDirectory": null
},
{
@@ -49,7 +50,7 @@
"dockerLabels": null,
"dockerSecurityOptions": null,
"entryPoint": null,
- "environment": null,
+ "environment": [],
"essential": true,
"extraHosts": null,
"healthCheck": null,
@@ -65,9 +66,10 @@
"awslogs-region": "us-east-1"
}
},
+ "firelensConfiguration": null,
"memory": 512,
"memoryReservation": null,
- "mountPoints": null,
+ "mountPoints": [],
"name": "redis",
"portMappings": [
{
@@ -84,7 +86,7 @@
"systemControls": null,
"ulimits": null,
"user": null,
- "volumesFrom": null,
+ "volumesFrom": [],
"workingDirectory": null
}
]
diff --git a/test/fixtures/single.json b/test/fixtures/single.json
index 03b9eb4..9814edb 100644
--- a/test/fixtures/single.json
+++ b/test/fixtures/single.json
@@ -68,6 +68,7 @@
"awslogs-region": "us-east-1"
}
},
+ "firelensConfiguration": null,
"memory": 512,
"memoryReservation": 512,
"mountPoints": [
@@ -100,7 +101,7 @@
}
],
"user": "root",
- "volumesFrom": null,
+ "volumesFrom": [],
"workingDirectory": "~/project"
}
]
diff --git a/variables.tf b/variables.tf
index b34b1f2..5737e34 100644
--- a/variables.tf
+++ b/variables.tf
@@ -122,6 +122,12 @@ variable "logConfiguration" {
type = any
}
+variable "firelensConfiguration" {
+ default = {}
+ description = "The FireLens configuration for the container"
+ type = any
+}
+
variable "memory" {
default = 512
description = "The hard limit (in MiB) of memory to present to the container"
@@ -213,6 +219,17 @@ variable "secrets" {
type = list(map(string))
}
+variable "startTimeout" {
+ default = 60
+ description = "Time duration (in seconds) to wait before giving up on resolving dependencies for a container."
+}
+
+variable "stopTimeout" {
+ default = 30
+ description = "Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own."
+}
+
+
variable "systemControls" {
default = []
description = "A list of namespaced kernel parameters to set in the container"