From 6418f61458e7cb65626404a71b030f5911481791 Mon Sep 17 00:00:00 2001 From: Iaroslav Sheptykin Date: Wed, 12 Aug 2020 03:02:18 +0200 Subject: [PATCH] Document multi-container task definitions in container_definition_json (#70) Co-authored-by: nitro Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com> --- README.md | 20 +++++++++++++++++++- README.yaml | 18 ++++++++++++++++++ docs/terraform.md | 2 +- variables.tf | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ba862d5f..94c77da5 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,24 @@ For automated test of the complete example using `bats` and `Terratest`, see [te The `container_image` in the `container_definition` module is the Docker image used to start a container. +The `container_definition` is a string of JSON-encoded container definitions. Normally, you would place only one container definition here as the example +above demonstrates. However, there might be situations where more than one container per task is more appropriate such as optionally in +[Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/application_architecture.html#application_architecture_fargate) or in other cases +where sidecars may be required. With [cloudposse/terraform-aws-ecs-container-definition](https://github.com/cloudposse/terraform-aws-ecs-container-definition) +multi-container task definitions can be created using: +```hcl +module "ecs_alb_service_task" { + ... + container_definition_json = jsonencode([ + module.first_container.json_map_object, + module.second_container.json_map_object, + ]) + ... +} +``` +Refer to the [multiple definitions](https://github.com/cloudposse/terraform-aws-ecs-container-definition/blob/master/examples/multiple_definitions/main.tf) example +in cloudposse/terraform-aws-ecs-container-definition for details on defining multiple definitions. + This string is passed directly to the Docker daemon. Images in the Docker Hub registry are available by default. Other repositories are specified with either `repository-url/image:tag` or `repository-url/image@digest`. Up to 255 letters (uppercase and lowercase), numbers, hyphens, underscores, colons, periods, forward slashes, and number signs are allowed. @@ -222,7 +240,7 @@ Available targets: | assign\_public\_ip | Assign a public IP address to the ENI (Fargate launch type only). Valid values are `true` or `false`. Default `false` | `bool` | `false` | no | | attributes | Additional attributes (\_e.g.\_ "1") | `list(string)` | `[]` | no | | capacity\_provider\_strategies | The capacity provider strategies to use for the service. See `capacity_provider_strategy` configuration block: https://www.terraform.io/docs/providers/aws/r/ecs_service.html#capacity_provider_strategy |
list(object({
capacity_provider = string
weight = number
base = number
}))
| `[]` | no | -| container\_definition\_json | The JSON of the task container definition | `string` | n/a | yes | +| container\_definition\_json | A string containing a JSON-encoded array of container definitions (`"[{ "name": "container1", ... }, { "name": "container2", ... }]"`). See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html, https://github.com/cloudposse/terraform-aws-ecs-container-definition, or https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#container_definitions | `string` | n/a | yes | | container\_port | The port on the container to allow via the ingress security group | `number` | `80` | no | | delimiter | Delimiter between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no | | deployment\_controller\_type | Type of deployment controller. Valid values are `CODE_DEPLOY` and `ECS` | `string` | `"ECS"` | no | diff --git a/README.yaml b/README.yaml index 4d6ff73f..cc6e9186 100644 --- a/README.yaml +++ b/README.yaml @@ -140,6 +140,24 @@ usage: |2- ``` The `container_image` in the `container_definition` module is the Docker image used to start a container. + + The `container_definition` is a string of JSON-encoded container definitions. Normally, you would place only one container definition here as the example + above demonstrates. However, there might be situations where more than one container per task is more appropriate such as optionally in + [Fargate](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/application_architecture.html#application_architecture_fargate) or in other cases + where sidecars may be required. With [cloudposse/terraform-aws-ecs-container-definition](https://github.com/cloudposse/terraform-aws-ecs-container-definition) + multi-container task definitions can be created using: + ```hcl + module "ecs_alb_service_task" { + ... + container_definition_json = jsonencode([ + module.first_container.json_map_object, + module.second_container.json_map_object, + ]) + ... + } + ``` + Refer to the [multiple definitions](https://github.com/cloudposse/terraform-aws-ecs-container-definition/blob/master/examples/multiple_definitions/main.tf) example + in cloudposse/terraform-aws-ecs-container-definition for details on defining multiple definitions. This string is passed directly to the Docker daemon. Images in the Docker Hub registry are available by default. Other repositories are specified with either `repository-url/image:tag` or `repository-url/image@digest`. diff --git a/docs/terraform.md b/docs/terraform.md index 4729910a..04e14f41 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -22,7 +22,7 @@ | assign\_public\_ip | Assign a public IP address to the ENI (Fargate launch type only). Valid values are `true` or `false`. Default `false` | `bool` | `false` | no | | attributes | Additional attributes (\_e.g.\_ "1") | `list(string)` | `[]` | no | | capacity\_provider\_strategies | The capacity provider strategies to use for the service. See `capacity_provider_strategy` configuration block: https://www.terraform.io/docs/providers/aws/r/ecs_service.html#capacity_provider_strategy |
list(object({
capacity_provider = string
weight = number
base = number
}))
| `[]` | no | -| container\_definition\_json | The JSON of the task container definition | `string` | n/a | yes | +| container\_definition\_json | A string containing a JSON-encoded array of container definitions (`"[{ "name": "container1", ... }, { "name": "container2", ... }]"`). See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html, https://github.com/cloudposse/terraform-aws-ecs-container-definition, or https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#container_definitions | `string` | n/a | yes | | container\_port | The port on the container to allow via the ingress security group | `number` | `80` | no | | delimiter | Delimiter between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no | | deployment\_controller\_type | Type of deployment controller. Valid values are `CODE_DEPLOY` and `ECS` | `string` | `"ECS"` | no | diff --git a/variables.tf b/variables.tf index 12756962..6304ca73 100644 --- a/variables.tf +++ b/variables.tf @@ -74,7 +74,7 @@ variable "ecs_load_balancers" { variable "container_definition_json" { type = string - description = "The JSON of the task container definition" + description = "A string containing a JSON-encoded array of container definitions (`\"[{ \"name\": \"container1\", ... }, { \"name\": \"container2\", ... }]\"`). See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html, https://github.com/cloudposse/terraform-aws-ecs-container-definition, or https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#container_definitions" } variable "container_port" {