Skip to content

Commit

Permalink
Feat: add container port mappings (#44)
Browse files Browse the repository at this point in the history
* Feat: add container port mappings

* Doc: add usage example

Co-authored-by: Lars Tobias Skjong-Børsting <[email protected]>
  • Loading branch information
mhd999 and larstobi authored Apr 13, 2021
1 parent 3452015 commit 0195dec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
8 changes: 8 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ module "fargate" {
// port, default protocol is HTTP
task_container_port = 8000

task_container_port_mappings = [
{
containerPort = 9000
hostPort = 9000
protocol = "tcp"
}
]

task_container_environment = {
TEST_VARIABLE = "TEST_VALUE"
}
Expand Down
16 changes: 9 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ resource "aws_ecs_task_definition" "task" {
"secrets": ${jsonencode(var.task_container_secrets)},
%{~endif}
"essential": true,
"portMappings": [
{
"containerPort": ${var.task_container_port},
"hostPort": ${var.task_container_port},
"protocol":"tcp"
}
],
"portMappings":
${jsonencode(concat(
var.task_container_port_mappings,
[{
"containerPort" : var.task_container_port,
"hostPort" : var.task_container_port,
"protocol" : "tcp"
}]
))},
"logConfiguration": {
"logDriver": "awslogs",
"options": {
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ variable "task_container_port" {
type = number
}

variable "task_container_port_mappings" {
description = "List of port objects that the container exposes in addition to the task_container_port."
type = list(object({
containerPort = number
hostPort = number
protocol = string
}))
default = []
}

variable "task_container_protocol" {
description = "Protocol that the container exposes."
default = "HTTP"
Expand Down

0 comments on commit 0195dec

Please sign in to comment.