Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable containerDefinitions portMappings to use target_groups container_ports #59

Merged
merged 6 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-added-large-files
args: ['--maxkb=500']
Expand All @@ -17,9 +17,9 @@ repos:
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: trailing-whitespace
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.64.0
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.71.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terraform_tflint
- id: terraform_tflint
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
<a name="unreleased"></a>
## [Unreleased]

- removed whitespace
- added distinct function to prevent a port being used multiple times
- Added checks to ensure that errors are not generated when target_group ports mapping is used
- Updated variable name
- Updated file to prefer target_group ports if provided, else use task_container_port


<a name="6.4.2"></a>
## [6.4.2] - 2022-03-11

- Refactor examples to work with provider 4.0.0+ ([#53](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/53))
- fix: setting `task_health_command` to null ([#49](https://github.com/umotif-public/terraform-aws-ecs-fargate/issues/49))


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


[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.1...HEAD
[Unreleased]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.2...HEAD
[6.4.2]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.1...6.4.2
[6.4.1]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.4.0...6.4.1
[6.4.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.3.0...6.4.0
[6.3.0]: https://github.com/umotif-public/terraform-aws-ecs-fargate/compare/6.2.2...6.3.0
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ module "ecs-fargate" {

## Authors

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

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

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

## Providers

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

## Modules

Expand Down
3 changes: 1 addition & 2 deletions examples/multiple-target-groups/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module "fargate" {
target_groups = [
{
target_group_name = "external-alb"
container_port = 80
container_port = 443
},
{
target_group_name = "internal-alb"
Expand Down Expand Up @@ -186,4 +186,3 @@ resource "aws_security_group_rule" "test_sg_ingress" {
to_port = 3022
source_security_group_id = module.fargate.service_sg_id
}

11 changes: 11 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ locals {
value = v
}
]

target_group_portMaps = length(var.target_groups) > 0 ? distinct([
for tg in var.target_groups : {
containerPort = contains(keys(tg), "container_port") ? tg.container_port : var.task_container_port
protocol = contains(keys(tg), "protocol") ? lower(tg.protocol) : "tcp"
}
]) : []
}

resource "aws_ecs_task_definition" "task" {
Expand Down Expand Up @@ -168,6 +175,9 @@ resource "aws_ecs_task_definition" "task" {
},
%{~endif}
"essential": true,
%{if length(local.target_group_portMaps) > 0}
"portMappings": ${jsonencode(local.target_group_portMaps)},
%{else}
%{if var.task_container_port != 0 || var.task_host_port != 0~}
"portMappings": [
{
Expand All @@ -181,6 +191,7 @@ resource "aws_ecs_task_definition" "task" {
}
],
%{~endif}
%{~endif}
"logConfiguration": {
"logDriver": "awslogs",
"options": {
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ terraform {
required_version = ">= 0.13.7"

required_providers {
aws = ">= 3.34"
aws = ">= 4.0.0"
}
}