Skip to content

Commit ac2b6ce

Browse files
networkprogrammerBobin JosephAbdul Wahid
authored
Enable containerDefinitions portMappings to use target_groups container_ports (#59)
* Updated file to prefer target_group ports if provided, else use task_container_port * Updated variable name * Added checks to ensure that errors are not generated when target_group ports mapping is used * added distinct function to prevent a port being used multiple times * removed whitespace * Clean up + updates to documentation & examples Co-authored-by: Bobin Joseph <[email protected]> Co-authored-by: Abdul Wahid <[email protected]>
1 parent 88dfdde commit ac2b6ce

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.1.0
3+
rev: v4.2.0
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=500']
@@ -17,9 +17,9 @@ repos:
1717
- id: detect-aws-credentials
1818
args: ['--allow-missing-credentials']
1919
- id: trailing-whitespace
20-
- repo: git://github.com/antonbabenko/pre-commit-terraform
21-
rev: v1.64.0
20+
- repo: https://github.com/antonbabenko/pre-commit-terraform
21+
rev: v1.71.0
2222
hooks:
2323
- id: terraform_fmt
2424
- id: terraform_docs
25-
- id: terraform_tflint
25+
- id: terraform_tflint

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
<a name="unreleased"></a>
66
## [Unreleased]
77

8+
- removed whitespace
9+
- added distinct function to prevent a port being used multiple times
10+
- Added checks to ensure that errors are not generated when target_group ports mapping is used
11+
- Updated variable name
12+
- Updated file to prefer target_group ports if provided, else use task_container_port
13+
14+
15+
<a name="6.4.2"></a>
16+
## [6.4.2] - 2022-03-11
17+
18+
- Refactor examples to work with provider 4.0.0+ ([#53](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/53))
819
- fix: setting `task_health_command` to null ([#49](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/49))
920

1021

@@ -224,7 +235,8 @@ All notable changes to this project will be documented in this file.
224235
- Initial commit
225236

226237

227-
[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.1...HEAD
238+
[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.2...HEAD
239+
[6.4.2]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.1...6.4.2
228240
[6.4.1]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.0...6.4.1
229241
[6.4.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.3.0...6.4.0
230242
[6.3.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.2.2...6.3.0

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ module "ecs-fargate" {
7777

7878
## Authors
7979

80-
Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](https://www.linkedin.com/in/marcincuber/).
80+
Module managed by [Abdul Wahid](https://github.com/Ohid25) [LinkedIn](https://www.linkedin.com/in/abdulwahid/).
8181

8282
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8383
## Requirements
8484

8585
| Name | Version |
8686
|------|---------|
8787
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.7 |
88-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.34 |
88+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0 |
8989

9090
## Providers
9191

9292
| Name | Version |
9393
|------|---------|
94-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.34 |
94+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0.0 |
9595

9696
## Modules
9797

examples/multiple-target-groups/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ module "fargate" {
136136
target_groups = [
137137
{
138138
target_group_name = "external-alb"
139-
container_port = 80
139+
container_port = 443
140140
},
141141
{
142142
target_group_name = "internal-alb"
@@ -186,4 +186,3 @@ resource "aws_security_group_rule" "test_sg_ingress" {
186186
to_port = 3022
187187
source_security_group_id = module.fargate.service_sg_id
188188
}
189-

main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ locals {
140140
value = v
141141
}
142142
]
143+
144+
target_group_portMaps = length(var.target_groups) > 0 ? distinct([
145+
for tg in var.target_groups : {
146+
containerPort = contains(keys(tg), "container_port") ? tg.container_port : var.task_container_port
147+
protocol = contains(keys(tg), "protocol") ? lower(tg.protocol) : "tcp"
148+
}
149+
]) : []
143150
}
144151

145152
resource "aws_ecs_task_definition" "task" {
@@ -168,6 +175,9 @@ resource "aws_ecs_task_definition" "task" {
168175
},
169176
%{~endif}
170177
"essential": true,
178+
%{if length(local.target_group_portMaps) > 0}
179+
"portMappings": ${jsonencode(local.target_group_portMaps)},
180+
%{else}
171181
%{if var.task_container_port != 0 || var.task_host_port != 0~}
172182
"portMappings": [
173183
{
@@ -181,6 +191,7 @@ resource "aws_ecs_task_definition" "task" {
181191
}
182192
],
183193
%{~endif}
194+
%{~endif}
184195
"logConfiguration": {
185196
"logDriver": "awslogs",
186197
"options": {

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ terraform {
22
required_version = ">= 0.13.7"
33

44
required_providers {
5-
aws = ">= 3.34"
5+
aws = ">= 4.0.0"
66
}
77
}

0 commit comments

Comments
 (0)