From e7b16112d6f6070fdd8b596b98dc87b714b9a3d0 Mon Sep 17 00:00:00 2001 From: Nagarajan Govindarajan Date: Tue, 23 Jan 2024 12:50:25 +0800 Subject: [PATCH 1/2] Dynamic ECS service capacity providers --- main.tf | 3 +++ modules/service/main.tf | 11 +++++++++++ modules/service/variables.tf | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/main.tf b/main.tf index 16f2c2b..1201ce8 100644 --- a/main.tf +++ b/main.tf @@ -75,6 +75,9 @@ module "service" { enable_execute_command = var.enable_execute_command task_placement_constraints = var.task_placement_constraints + + capacity_provider_strategy = var.default_capacity_provider_strategy + } module "service_cpu_autoscaling_policy" { diff --git a/modules/service/main.tf b/modules/service/main.tf index 4a2bb60..0e41010 100644 --- a/modules/service/main.tf +++ b/modules/service/main.tf @@ -159,6 +159,17 @@ resource "aws_ecs_service" "this" { } } + dynamic "capacity_provider_strategy" { + for_each = var.capacity_provider_strategy != null ? var.capacity_provider_strategy : [] + + iterator = strategy + content { + capacity_provider = strategy.value["capacity_provider"] + weight = lookup(strategy.value, "weight", null) + base = lookup(strategy.value, "base", null) + } + } + tags = var.tags } diff --git a/modules/service/variables.tf b/modules/service/variables.tf index b4f05b8..88b38f6 100644 --- a/modules/service/variables.tf +++ b/modules/service/variables.tf @@ -131,6 +131,12 @@ variable "deployment_circuit_breaker" { default = {} } +variable "capacity_provider_strategy" { + description = "The capacity provider strategy to use by ecs service. Can be one or more." + type = list(map(any)) + default = [] +} + ################################################################################ # ECS Task Definition ################################################################################ From dba6e05e63ef45efdbfd0c1eaed3ff110cfa7c7a Mon Sep 17 00:00:00 2001 From: Nagarajan Govindarajan Date: Tue, 23 Jan 2024 13:08:54 +0800 Subject: [PATCH 2/2] Update README.md Add new variables --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dcc0a31..75efad8 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ No resources. | [service\_target\_cpu\_value](#input\_service\_target\_cpu\_value) | Autoscale when CPU Usage value over the specified value. Must be specified if `enable_cpu_based_autoscaling` is `true`. | `number` | `70` | no | | [service\_task\_execution\_role\_arn](#input\_service\_task\_execution\_role\_arn) | Default IAM role for ECS execution | `string` | `""` | no | | [service\_task\_role\_arn](#input\_service\_task\_role\_arn) | Default IAM role for ECS task | `string` | `""` | no | +| [capacity\_provider](#default\_capacity\_provider\_strategy) | Capacity providers for ECS Cluster | `list(string)` | `[]` | no | +| [default\_capacity\_provider\_strategy](#default\_capacity\_provider\_strategy) | Default capacity provider strategy for ECS Cluster | `list(map(any))` | `[]` | no | | [task\_placement\_constraints](#input\_task\_placement\_constraints) | The rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10 |
list(object({
type = string
expression = string
}))
| `[]` | no | ## Outputs