From 376db54084f0732481420657466636b743d8c697 Mon Sep 17 00:00:00 2001 From: nitro Date: Tue, 28 Jul 2020 15:36:16 -0400 Subject: [PATCH] Override container definitions (#60) * var.container_definition to override definition * Override the container_definition * Change var.container_definition to string * Updated README.md * Update variables.tf * Update README.md * Update terraform.md Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com> --- README.md | 1 + docs/terraform.md | 1 + main.tf | 7 ++++++- variables.tf | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a8549370..05d70114 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ Available targets: | codepipeline\_s3\_bucket\_force\_destroy | A boolean that indicates all objects should be deleted from the CodePipeline artifact store S3 bucket so that the bucket can be destroyed without error | `bool` | `false` | no | | command | The command that is passed to the container | `list(string)` | `null` | no | | container\_cpu | The vCPU setting to control cpu limits of container. (If FARGATE launch type is used below, this must be a supported vCPU size from the table here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html) | `number` | `256` | no | +| container\_definition | Override the main container\_definition | `string` | `""` | no | | container\_image | The default container image to use in container definition | `string` | `"cloudposse/default-backend"` | no | | container\_memory | The amount of RAM to allow container to use in MB. (If FARGATE launch type is used below, this must be a supported Memory size from the table here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html) | `number` | `512` | no | | container\_memory\_reservation | The amount of RAM (Soft Limit) to allow container to use in MB. This value must be less than `container_memory` if set | `number` | `128` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 31638235..4cfeff8d 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -77,6 +77,7 @@ | codepipeline\_s3\_bucket\_force\_destroy | A boolean that indicates all objects should be deleted from the CodePipeline artifact store S3 bucket so that the bucket can be destroyed without error | `bool` | `false` | no | | command | The command that is passed to the container | `list(string)` | `null` | no | | container\_cpu | The vCPU setting to control cpu limits of container. (If FARGATE launch type is used below, this must be a supported vCPU size from the table here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html) | `number` | `256` | no | +| container\_definition | Override the main container\_definition | `string` | `""` | no | | container\_image | The default container image to use in container definition | `string` | `"cloudposse/default-backend"` | no | | container\_memory | The amount of RAM to allow container to use in MB. (If FARGATE launch type is used below, this must be a supported Memory size from the table here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html) | `number` | `512` | no | | container\_memory\_reservation | The amount of RAM (Soft Limit) to allow container to use in MB. This value must be less than `container_memory` if set | `number` | `128` | no | diff --git a/main.tf b/main.tf index 4cbb9908..3992167f 100644 --- a/main.tf +++ b/main.tf @@ -120,6 +120,11 @@ locals { condition = init_container.condition } ] + + # override container_definition if var.container_definition is supplied + main_container_definition = coalesce(var.container_definition, module.container_definition.json_map) + # combine all container definitions + all_container_definitions = "[${join(",", concat(local.init_container_definitions, [local.main_container_definition]))}]" } module "ecs_alb_service_task" { @@ -132,7 +137,7 @@ module "ecs_alb_service_task" { use_alb_security_group = var.use_alb_security_group nlb_cidr_blocks = var.nlb_cidr_blocks use_nlb_cidr_blocks = var.use_nlb_cidr_blocks - container_definition_json = "[${join(",", concat(local.init_container_definitions, [module.container_definition.json_map]))}]" + container_definition_json = local.all_container_definitions desired_count = var.desired_count health_check_grace_period_seconds = var.health_check_grace_period_seconds task_cpu = coalesce(var.task_cpu, var.container_cpu) diff --git a/variables.tf b/variables.tf index 9b14bcbb..1c4c304e 100644 --- a/variables.tf +++ b/variables.tf @@ -878,6 +878,12 @@ variable "init_containers" { default = [] } +variable "container_definition" { + type = string + description = "Override the main container_definition" + default = "" +} + variable "cloudwatch_log_group_enabled" { type = bool description = "A boolean to disable cloudwatch log group creation"