Skip to content

Commit 093abc4

Browse files
mbarrienczimergebot
authored andcommitted
aws-ecs Add support for ordered_placement_strategy (#139)
[feature] aws-ecs Add support for ordered_placement_strategy
1 parent d832ad1 commit 093abc4

File tree

12 files changed

+96
-4
lines changed

12 files changed

+96
-4
lines changed

aws-ecs-job-fargate/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Since changing a service to use the new ARN requires destroying and recreating t
3535
| desired\_count | | number | n/a | yes |
3636
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
3737
| memory | Memory in megabytes for Fargate task. Used if task_definition provided, or for initial stub task if externally managed. | number | `512` | no |
38+
| ordered\_placement\_strategy | Placement strategy for the task instances. | list | `[]` | no |
3839
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
3940
| registry\_secretsmanager\_arn | ARN for AWS Secrets Manager secret for credentials to private registry | string | `null` | no |
4041
| security\_group\_ids | Security group to use for the Fargate task. | list | `<list>` | no |

aws-ecs-job-fargate/main.tf

+16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ resource "aws_ecs_service" "job" {
3333
security_groups = var.security_group_ids
3434
}
3535

36+
dynamic "ordered_placement_strategy" {
37+
for_each = var.ordered_placement_strategy
38+
content {
39+
type = ordered_placement_strategy.value.type
40+
field = ordered_placement_strategy.value.field
41+
}
42+
}
43+
3644
tags = var.tag_service ? local.tags : {}
3745
}
3846

@@ -53,6 +61,14 @@ resource "aws_ecs_service" "unmanaged-job" {
5361
security_groups = var.security_group_ids
5462
}
5563

64+
dynamic "ordered_placement_strategy" {
65+
for_each = var.ordered_placement_strategy
66+
content {
67+
type = ordered_placement_strategy.value.type
68+
field = ordered_placement_strategy.value.field
69+
}
70+
}
71+
5672
lifecycle {
5773
ignore_changes = [task_definition]
5874
}

aws-ecs-job-fargate/variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,10 @@ variable "tag_service" {
9494
description = "Apply cost tags to the ECS service. Only specify false for backwards compatibility with old ECS services."
9595
type = bool
9696
default = true
97-
}
97+
}
98+
99+
variable "ordered_placement_strategy" {
100+
type = list(object({ type = string, field = string }))
101+
default = []
102+
description = "Placement strategy for the task instances."
103+
}

aws-ecs-job/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ service = false` argument can be removed.
3434
| deployment\_minimum\_healthy\_percent | (Optional) The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment. | number | `100` | no |
3535
| desired\_count | | number | n/a | yes |
3636
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
37+
| ordered\_placement\_strategy | Placement strategy for the task instances. | list | `[]` | no |
3738
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
3839
| scheduling\_strategy | Scheduling strategy for the service: REPLICA or DAEMON. | string | `"REPLICA"` | no |
3940
| service | Service for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |

aws-ecs-job/main.tf

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ resource "aws_ecs_service" "job" {
2727
deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent
2828
scheduling_strategy = var.scheduling_strategy
2929

30+
dynamic "ordered_placement_strategy" {
31+
for_each = var.ordered_placement_strategy
32+
content {
33+
type = ordered_placement_strategy.value.type
34+
field = ordered_placement_strategy.value.field
35+
}
36+
}
37+
3038
tags = var.tag_service ? local.tags : {}
3139
}
3240

@@ -41,6 +49,14 @@ resource "aws_ecs_service" "unmanaged-job" {
4149
deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent
4250
scheduling_strategy = var.scheduling_strategy
4351

52+
dynamic "ordered_placement_strategy" {
53+
for_each = var.ordered_placement_strategy
54+
content {
55+
type = ordered_placement_strategy.value.type
56+
field = ordered_placement_strategy.value.field
57+
}
58+
}
59+
4460
lifecycle {
4561
ignore_changes = [task_definition]
4662
}

aws-ecs-job/variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ variable "tag_service" {
7575
description = "Apply cost tags to the ECS service. Only specify false for backwards compatibility with old ECS services."
7676
type = bool
7777
default = true
78-
}
78+
}
79+
80+
variable "ordered_placement_strategy" {
81+
type = list(object({ type = string, field = string }))
82+
default = []
83+
description = "Placement strategy for the task instances."
84+
}

aws-ecs-service-fargate/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ service = false` argument can be removed.
170170
| lb\_subnets | List of subnets in which to deploy the load balancer. | list | n/a | yes |
171171
| manage\_task\_definition | If false, Terraform will not touch the task definition for the ECS service after initial creation | bool | `true` | no |
172172
| memory | Memory in megabytes for Fargate task. Used if task_definition provided, or for initial stub task if externally managed. | number | `512` | no |
173+
| ordered\_placement\_strategy | Placement strategy for the task instances. | list | `[]` | no |
173174
| owner | Owner for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
174175
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
175176
| registry\_secretsmanager\_arn | ARN for AWS Secrets Manager secret for credentials to private registry | string | `null` | no |

aws-ecs-service-fargate/service.tf

+16
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ resource "aws_ecs_service" "job" {
6666
}
6767
}
6868

69+
dynamic "ordered_placement_strategy" {
70+
for_each = var.ordered_placement_strategy
71+
content {
72+
type = ordered_placement_strategy.value.type
73+
field = ordered_placement_strategy.value.field
74+
}
75+
}
76+
6977
tags = var.tag_service ? local.tags : {}
7078

7179
depends_on = [aws_lb.service]
@@ -99,6 +107,14 @@ resource "aws_ecs_service" "unmanaged-job" {
99107
}
100108
}
101109

110+
dynamic "ordered_placement_strategy" {
111+
for_each = var.ordered_placement_strategy
112+
content {
113+
type = ordered_placement_strategy.value.type
114+
field = ordered_placement_strategy.value.field
115+
}
116+
}
117+
102118
# This lifecycle block is the only difference between job and unmanaged-job
103119
lifecycle {
104120
ignore_changes = [task_definition]

aws-ecs-service-fargate/variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,10 @@ variable "tag_service" {
195195
description = "Apply cost tags to the ECS service. Only specify false for backwards compatibility with old ECS services."
196196
type = bool
197197
default = true
198-
}
198+
}
199+
200+
variable "ordered_placement_strategy" {
201+
type = list(object({ type = string, field = string }))
202+
default = []
203+
description = "Placement strategy for the task instances."
204+
}

aws-ecs-service/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ service = false` argument can be removed.
160160
| lb\_ingress\_security\_group\_ids | | list | `<list>` | no |
161161
| lb\_subnets | List of subnets in which to deploy the load balancer. | list | n/a | yes |
162162
| manage\_task\_definition | If false, Terraform will not touch the task definition for the ECS service after initial creation | bool | `true` | no |
163+
| ordered\_placement\_strategy | Placement strategy for the task instances. | list | `[]` | no |
163164
| owner | Owner for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
164165
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
165166
| registry\_secretsmanager\_arn | ARN for AWS Secrets Manager secret for credentials to private registry | string | `null` | no |

aws-ecs-service/service.tf

+16
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ resource "aws_ecs_service" "job" {
6969
}
7070
}
7171

72+
dynamic "ordered_placement_strategy" {
73+
for_each = var.ordered_placement_strategy
74+
content {
75+
type = ordered_placement_strategy.value.type
76+
field = ordered_placement_strategy.value.field
77+
}
78+
}
79+
7280
tags = var.tag_service ? local.tags : {}
7381

7482
depends_on = [aws_lb.service]
@@ -104,6 +112,14 @@ resource "aws_ecs_service" "unmanaged-job" {
104112
}
105113
}
106114

115+
dynamic "ordered_placement_strategy" {
116+
for_each = var.ordered_placement_strategy
117+
content {
118+
type = ordered_placement_strategy.value.type
119+
field = ordered_placement_strategy.value.field
120+
}
121+
}
122+
107123
# This lifecycle block is the only difference between job and unmanaged-job
108124
lifecycle {
109125
ignore_changes = [task_definition]

aws-ecs-service/variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,10 @@ variable "tag_service" {
189189
description = "Apply cost tags to the ECS service. Only specify false for backwards compatibility with old ECS services."
190190
type = bool
191191
default = true
192-
}
192+
}
193+
194+
variable "ordered_placement_strategy" {
195+
type = list(object({ type = string, field = string }))
196+
default = []
197+
description = "Placement strategy for the task instances."
198+
}

0 commit comments

Comments
 (0)