Skip to content

Commit a111e5d

Browse files
authored
feat: Add support for setting placement constraints separately between service and task definition (#93)
1 parent 148ef38 commit a111e5d

File tree

10 files changed

+70
-69
lines changed

10 files changed

+70
-69
lines changed

examples/complete/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Note that this example may create resources which will incur monetary charges on
4545
| <a name="module_ecs_cluster_disabled"></a> [ecs\_cluster\_disabled](#module\_ecs\_cluster\_disabled) | ../../modules/cluster | n/a |
4646
| <a name="module_ecs_disabled"></a> [ecs\_disabled](#module\_ecs\_disabled) | ../../ | n/a |
4747
| <a name="module_service_disabled"></a> [service\_disabled](#module\_service\_disabled) | ../../modules/service | n/a |
48-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
48+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
4949

5050
## Resources
5151

examples/complete/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ module "alb" {
227227

228228
module "vpc" {
229229
source = "terraform-aws-modules/vpc/aws"
230-
version = "~> 4.0"
230+
version = "~> 5.0"
231231

232232
name = local.name
233233
cidr = local.vpc_cidr

examples/ec2-autoscaling/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Note that this example may create resources which will incur monetary charges on
4545
| <a name="module_autoscaling_sg"></a> [autoscaling\_sg](#module\_autoscaling\_sg) | terraform-aws-modules/security-group/aws | ~> 4.0 |
4646
| <a name="module_ecs_cluster"></a> [ecs\_cluster](#module\_ecs\_cluster) | ../../modules/cluster | n/a |
4747
| <a name="module_ecs_service"></a> [ecs\_service](#module\_ecs\_service) | ../../modules/service | n/a |
48-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
48+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
4949

5050
## Resources
5151

examples/ec2-autoscaling/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ module "autoscaling_sg" {
320320

321321
module "vpc" {
322322
source = "terraform-aws-modules/vpc/aws"
323-
version = "~> 4.0"
323+
version = "~> 5.0"
324324

325325
name = local.name
326326
cidr = local.vpc_cidr

examples/fargate/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Note that this example may create resources which will incur monetary charges on
4343
| <a name="module_alb_sg"></a> [alb\_sg](#module\_alb\_sg) | terraform-aws-modules/security-group/aws | ~> 4.0 |
4444
| <a name="module_ecs_cluster"></a> [ecs\_cluster](#module\_ecs\_cluster) | ../../modules/cluster | n/a |
4545
| <a name="module_ecs_service"></a> [ecs\_service](#module\_ecs\_service) | ../../modules/service | n/a |
46-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
46+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
4747

4848
## Resources
4949

examples/fargate/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ module "alb" {
219219

220220
module "vpc" {
221221
source = "terraform-aws-modules/vpc/aws"
222-
version = "~> 4.0"
222+
version = "~> 5.0"
223223

224224
name = local.name
225225
cidr = local.vpc_cidr

modules/service/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ module "ecs_service" {
268268
| <a name="input_network_mode"></a> [network\_mode](#input\_network\_mode) | Docker networking mode to use for the containers in the task. Valid values are `none`, `bridge`, `awsvpc`, and `host` | `string` | `"awsvpc"` | no |
269269
| <a name="input_ordered_placement_strategy"></a> [ordered\_placement\_strategy](#input\_ordered\_placement\_strategy) | Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence | `any` | `{}` | no |
270270
| <a name="input_pid_mode"></a> [pid\_mode](#input\_pid\_mode) | Process namespace to use for the containers in the task. The valid values are `host` and `task` | `string` | `null` | no |
271-
| <a name="input_placement_constraints"></a> [placement\_constraints](#input\_placement\_constraints) | Configuration block for rules that are taken into consideration during task placement (up to max of 10) | `any` | `{}` | no |
271+
| <a name="input_placement_constraints"></a> [placement\_constraints](#input\_placement\_constraints) | Configuration block for rules that are taken into consideration during task placement (up to max of 10). This is set at the service, see `task_definition_placement_constraints` for setting at the task definition | `any` | `{}` | no |
272272
| <a name="input_platform_version"></a> [platform\_version](#input\_platform\_version) | Platform version on which to run your service. Only applicable for `launch_type` set to `FARGATE`. Defaults to `LATEST` | `string` | `null` | no |
273273
| <a name="input_propagate_tags"></a> [propagate\_tags](#input\_propagate\_tags) | Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are `SERVICE` and `TASK_DEFINITION` | `string` | `null` | no |
274274
| <a name="input_proxy_configuration"></a> [proxy\_configuration](#input\_proxy\_configuration) | Configuration block for the App Mesh proxy | `any` | `{}` | no |
@@ -288,6 +288,7 @@ module "ecs_service" {
288288
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | List of subnets to associate with the task or service | `list(string)` | `[]` | no |
289289
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
290290
| <a name="input_task_definition_arn"></a> [task\_definition\_arn](#input\_task\_definition\_arn) | Existing task definition ARN. Required when `create_task_definition` is `false` | `string` | `null` | no |
291+
| <a name="input_task_definition_placement_constraints"></a> [task\_definition\_placement\_constraints](#input\_task\_definition\_placement\_constraints) | Configuration block for rules that are taken into consideration during task placement (up to max of 10). This is set at the task definition, see `placement_constraints` for setting at the service | `any` | `{}` | no |
291292
| <a name="input_task_exec_iam_role_arn"></a> [task\_exec\_iam\_role\_arn](#input\_task\_exec\_iam\_role\_arn) | Existing IAM role ARN | `string` | `null` | no |
292293
| <a name="input_task_exec_iam_role_description"></a> [task\_exec\_iam\_role\_description](#input\_task\_exec\_iam\_role\_description) | Description of the role | `string` | `null` | no |
293294
| <a name="input_task_exec_iam_role_name"></a> [task\_exec\_iam\_role\_name](#input\_task\_exec\_iam\_role\_name) | Name to use on IAM role created | `string` | `null` | no |

modules/service/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ resource "aws_ecs_task_definition" "this" {
639639
pid_mode = var.pid_mode
640640

641641
dynamic "placement_constraints" {
642-
for_each = var.placement_constraints
642+
for_each = var.task_definition_placement_constraints
643643

644644
content {
645645
expression = try(placement_constraints.value.expression, null)

modules/service/variables.tf

+6-7
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ variable "ordered_placement_strategy" {
135135
}
136136

137137
variable "placement_constraints" {
138-
description = "Configuration block for rules that are taken into consideration during task placement (up to max of 10)"
138+
description = "Configuration block for rules that are taken into consideration during task placement (up to max of 10). This is set at the service, see `task_definition_placement_constraints` for setting at the task definition"
139139
type = any
140140
default = {}
141141
}
@@ -322,12 +322,11 @@ variable "pid_mode" {
322322
default = null
323323
}
324324

325-
# Shared between service and task definition
326-
# variable "placement_constraints" {
327-
# description = "Configuration block for rules that are taken into consideration during task placement (up to max of 10)"
328-
# type = any
329-
# default = {}
330-
# }
325+
variable "task_definition_placement_constraints" {
326+
description = "Configuration block for rules that are taken into consideration during task placement (up to max of 10). This is set at the task definition, see `placement_constraints` for setting at the service"
327+
type = any
328+
default = {}
329+
}
331330

332331
variable "proxy_configuration" {
333332
description = "Configuration block for the App Mesh proxy"

wrappers/service/main.tf

+55-54
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,61 @@ module "wrapper" {
33

44
for_each = var.items
55

6-
create = try(each.value.create, var.defaults.create, true)
7-
tags = try(each.value.tags, var.defaults.tags, {})
8-
ignore_task_definition_changes = try(each.value.ignore_task_definition_changes, var.defaults.ignore_task_definition_changes, false)
9-
alarms = try(each.value.alarms, var.defaults.alarms, {})
10-
capacity_provider_strategy = try(each.value.capacity_provider_strategy, var.defaults.capacity_provider_strategy, {})
11-
cluster_arn = try(each.value.cluster_arn, var.defaults.cluster_arn, "")
12-
deployment_circuit_breaker = try(each.value.deployment_circuit_breaker, var.defaults.deployment_circuit_breaker, {})
13-
deployment_controller = try(each.value.deployment_controller, var.defaults.deployment_controller, {})
14-
deployment_maximum_percent = try(each.value.deployment_maximum_percent, var.defaults.deployment_maximum_percent, 200)
15-
deployment_minimum_healthy_percent = try(each.value.deployment_minimum_healthy_percent, var.defaults.deployment_minimum_healthy_percent, 66)
16-
desired_count = try(each.value.desired_count, var.defaults.desired_count, 1)
17-
enable_ecs_managed_tags = try(each.value.enable_ecs_managed_tags, var.defaults.enable_ecs_managed_tags, true)
18-
enable_execute_command = try(each.value.enable_execute_command, var.defaults.enable_execute_command, false)
19-
force_new_deployment = try(each.value.force_new_deployment, var.defaults.force_new_deployment, true)
20-
health_check_grace_period_seconds = try(each.value.health_check_grace_period_seconds, var.defaults.health_check_grace_period_seconds, null)
21-
launch_type = try(each.value.launch_type, var.defaults.launch_type, "FARGATE")
22-
load_balancer = try(each.value.load_balancer, var.defaults.load_balancer, {})
23-
name = try(each.value.name, var.defaults.name, null)
24-
assign_public_ip = try(each.value.assign_public_ip, var.defaults.assign_public_ip, false)
25-
security_group_ids = try(each.value.security_group_ids, var.defaults.security_group_ids, [])
26-
subnet_ids = try(each.value.subnet_ids, var.defaults.subnet_ids, [])
27-
ordered_placement_strategy = try(each.value.ordered_placement_strategy, var.defaults.ordered_placement_strategy, {})
28-
placement_constraints = try(each.value.placement_constraints, var.defaults.placement_constraints, {})
29-
platform_version = try(each.value.platform_version, var.defaults.platform_version, null)
30-
propagate_tags = try(each.value.propagate_tags, var.defaults.propagate_tags, null)
31-
scheduling_strategy = try(each.value.scheduling_strategy, var.defaults.scheduling_strategy, null)
32-
service_connect_configuration = try(each.value.service_connect_configuration, var.defaults.service_connect_configuration, {})
33-
service_registries = try(each.value.service_registries, var.defaults.service_registries, {})
34-
timeouts = try(each.value.timeouts, var.defaults.timeouts, {})
35-
triggers = try(each.value.triggers, var.defaults.triggers, {})
36-
wait_for_steady_state = try(each.value.wait_for_steady_state, var.defaults.wait_for_steady_state, null)
37-
create_iam_role = try(each.value.create_iam_role, var.defaults.create_iam_role, true)
38-
iam_role_arn = try(each.value.iam_role_arn, var.defaults.iam_role_arn, null)
39-
iam_role_name = try(each.value.iam_role_name, var.defaults.iam_role_name, null)
40-
iam_role_use_name_prefix = try(each.value.iam_role_use_name_prefix, var.defaults.iam_role_use_name_prefix, true)
41-
iam_role_path = try(each.value.iam_role_path, var.defaults.iam_role_path, null)
42-
iam_role_description = try(each.value.iam_role_description, var.defaults.iam_role_description, null)
43-
iam_role_permissions_boundary = try(each.value.iam_role_permissions_boundary, var.defaults.iam_role_permissions_boundary, null)
44-
iam_role_tags = try(each.value.iam_role_tags, var.defaults.iam_role_tags, {})
45-
iam_role_statements = try(each.value.iam_role_statements, var.defaults.iam_role_statements, {})
46-
create_task_definition = try(each.value.create_task_definition, var.defaults.create_task_definition, true)
47-
task_definition_arn = try(each.value.task_definition_arn, var.defaults.task_definition_arn, null)
48-
container_definitions = try(each.value.container_definitions, var.defaults.container_definitions, {})
49-
container_definition_defaults = try(each.value.container_definition_defaults, var.defaults.container_definition_defaults, {})
50-
cpu = try(each.value.cpu, var.defaults.cpu, 1024)
51-
ephemeral_storage = try(each.value.ephemeral_storage, var.defaults.ephemeral_storage, {})
52-
family = try(each.value.family, var.defaults.family, null)
53-
inference_accelerator = try(each.value.inference_accelerator, var.defaults.inference_accelerator, {})
54-
ipc_mode = try(each.value.ipc_mode, var.defaults.ipc_mode, null)
55-
memory = try(each.value.memory, var.defaults.memory, 2048)
56-
network_mode = try(each.value.network_mode, var.defaults.network_mode, "awsvpc")
57-
pid_mode = try(each.value.pid_mode, var.defaults.pid_mode, null)
58-
proxy_configuration = try(each.value.proxy_configuration, var.defaults.proxy_configuration, {})
59-
requires_compatibilities = try(each.value.requires_compatibilities, var.defaults.requires_compatibilities, ["FARGATE"])
6+
create = try(each.value.create, var.defaults.create, true)
7+
tags = try(each.value.tags, var.defaults.tags, {})
8+
ignore_task_definition_changes = try(each.value.ignore_task_definition_changes, var.defaults.ignore_task_definition_changes, false)
9+
alarms = try(each.value.alarms, var.defaults.alarms, {})
10+
capacity_provider_strategy = try(each.value.capacity_provider_strategy, var.defaults.capacity_provider_strategy, {})
11+
cluster_arn = try(each.value.cluster_arn, var.defaults.cluster_arn, "")
12+
deployment_circuit_breaker = try(each.value.deployment_circuit_breaker, var.defaults.deployment_circuit_breaker, {})
13+
deployment_controller = try(each.value.deployment_controller, var.defaults.deployment_controller, {})
14+
deployment_maximum_percent = try(each.value.deployment_maximum_percent, var.defaults.deployment_maximum_percent, 200)
15+
deployment_minimum_healthy_percent = try(each.value.deployment_minimum_healthy_percent, var.defaults.deployment_minimum_healthy_percent, 66)
16+
desired_count = try(each.value.desired_count, var.defaults.desired_count, 1)
17+
enable_ecs_managed_tags = try(each.value.enable_ecs_managed_tags, var.defaults.enable_ecs_managed_tags, true)
18+
enable_execute_command = try(each.value.enable_execute_command, var.defaults.enable_execute_command, false)
19+
force_new_deployment = try(each.value.force_new_deployment, var.defaults.force_new_deployment, true)
20+
health_check_grace_period_seconds = try(each.value.health_check_grace_period_seconds, var.defaults.health_check_grace_period_seconds, null)
21+
launch_type = try(each.value.launch_type, var.defaults.launch_type, "FARGATE")
22+
load_balancer = try(each.value.load_balancer, var.defaults.load_balancer, {})
23+
name = try(each.value.name, var.defaults.name, null)
24+
assign_public_ip = try(each.value.assign_public_ip, var.defaults.assign_public_ip, false)
25+
security_group_ids = try(each.value.security_group_ids, var.defaults.security_group_ids, [])
26+
subnet_ids = try(each.value.subnet_ids, var.defaults.subnet_ids, [])
27+
ordered_placement_strategy = try(each.value.ordered_placement_strategy, var.defaults.ordered_placement_strategy, {})
28+
placement_constraints = try(each.value.placement_constraints, var.defaults.placement_constraints, {})
29+
platform_version = try(each.value.platform_version, var.defaults.platform_version, null)
30+
propagate_tags = try(each.value.propagate_tags, var.defaults.propagate_tags, null)
31+
scheduling_strategy = try(each.value.scheduling_strategy, var.defaults.scheduling_strategy, null)
32+
service_connect_configuration = try(each.value.service_connect_configuration, var.defaults.service_connect_configuration, {})
33+
service_registries = try(each.value.service_registries, var.defaults.service_registries, {})
34+
timeouts = try(each.value.timeouts, var.defaults.timeouts, {})
35+
triggers = try(each.value.triggers, var.defaults.triggers, {})
36+
wait_for_steady_state = try(each.value.wait_for_steady_state, var.defaults.wait_for_steady_state, null)
37+
create_iam_role = try(each.value.create_iam_role, var.defaults.create_iam_role, true)
38+
iam_role_arn = try(each.value.iam_role_arn, var.defaults.iam_role_arn, null)
39+
iam_role_name = try(each.value.iam_role_name, var.defaults.iam_role_name, null)
40+
iam_role_use_name_prefix = try(each.value.iam_role_use_name_prefix, var.defaults.iam_role_use_name_prefix, true)
41+
iam_role_path = try(each.value.iam_role_path, var.defaults.iam_role_path, null)
42+
iam_role_description = try(each.value.iam_role_description, var.defaults.iam_role_description, null)
43+
iam_role_permissions_boundary = try(each.value.iam_role_permissions_boundary, var.defaults.iam_role_permissions_boundary, null)
44+
iam_role_tags = try(each.value.iam_role_tags, var.defaults.iam_role_tags, {})
45+
iam_role_statements = try(each.value.iam_role_statements, var.defaults.iam_role_statements, {})
46+
create_task_definition = try(each.value.create_task_definition, var.defaults.create_task_definition, true)
47+
task_definition_arn = try(each.value.task_definition_arn, var.defaults.task_definition_arn, null)
48+
container_definitions = try(each.value.container_definitions, var.defaults.container_definitions, {})
49+
container_definition_defaults = try(each.value.container_definition_defaults, var.defaults.container_definition_defaults, {})
50+
cpu = try(each.value.cpu, var.defaults.cpu, 1024)
51+
ephemeral_storage = try(each.value.ephemeral_storage, var.defaults.ephemeral_storage, {})
52+
family = try(each.value.family, var.defaults.family, null)
53+
inference_accelerator = try(each.value.inference_accelerator, var.defaults.inference_accelerator, {})
54+
ipc_mode = try(each.value.ipc_mode, var.defaults.ipc_mode, null)
55+
memory = try(each.value.memory, var.defaults.memory, 2048)
56+
network_mode = try(each.value.network_mode, var.defaults.network_mode, "awsvpc")
57+
pid_mode = try(each.value.pid_mode, var.defaults.pid_mode, null)
58+
task_definition_placement_constraints = try(each.value.task_definition_placement_constraints, var.defaults.task_definition_placement_constraints, {})
59+
proxy_configuration = try(each.value.proxy_configuration, var.defaults.proxy_configuration, {})
60+
requires_compatibilities = try(each.value.requires_compatibilities, var.defaults.requires_compatibilities, ["FARGATE"])
6061
runtime_platform = try(each.value.runtime_platform, var.defaults.runtime_platform, {
6162
operating_system_family = "LINUX"
6263
cpu_architecture = "X86_64"

0 commit comments

Comments
 (0)