Skip to content

Commit 4d1297f

Browse files
ghaddowmarcincuber
authored andcommitted
improve tag support and expose host port (#1)
* improve tag support and expose host port * fix formatting
1 parent e551bfa commit 4d1297f

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

main.tf

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ resource "aws_ecs_task_definition" "task" {
123123
cpu = var.task_definition_cpu
124124
memory = var.task_definition_memory
125125
task_role_arn = aws_iam_role.task.arn
126-
127-
container_definitions = <<EOF
126+
tags = merge(
127+
var.tags,
128+
{
129+
Name = var.container_name != "" ? var.container_name : var.name_prefix
130+
},
131+
)
132+
container_definitions = <<EOF
128133
[{
129134
"name": "${var.container_name != "" ? var.container_name : var.name_prefix}",
130135
"image": "${var.task_container_image}",
@@ -137,7 +142,7 @@ resource "aws_ecs_task_definition" "task" {
137142
"portMappings": [
138143
{
139144
"containerPort": ${var.task_container_port},
140-
"hostPort": ${var.task_container_port},
145+
"hostPort": ${var.task_host_port},
141146
"protocol":"tcp"
142147
}
143148
],
@@ -161,6 +166,7 @@ resource "aws_ecs_service" "service" {
161166
cluster = var.cluster_id
162167
task_definition = aws_ecs_task_definition.task.arn
163168
desired_count = var.desired_count
169+
propagate_tags = var.propogate_tags
164170
launch_type = "FARGATE"
165171
deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent
166172
deployment_maximum_percent = var.deployment_maximum_percent
@@ -190,6 +196,13 @@ resource "aws_ecs_service" "service" {
190196
container_name = var.container_name != "" ? var.container_name : var.name_prefix
191197
}
192198
}
199+
200+
tags = merge(
201+
var.tags,
202+
{
203+
Name = "${var.name_prefix}-service"
204+
},
205+
)
193206
}
194207

195208
# HACK: The workaround used in ecs/service does not work for some reason in this module, this fixes the following error:

variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ variable "task_container_assign_public_ip" {
4747
}
4848

4949
variable "task_container_port" {
50-
description = "Port that the container exposes."
50+
description = "The port number on the container that is bound to the user-specified or automatically assigned host port"
5151
type = number
5252
}
5353

54+
variable "task_host_port" {
55+
description = "The port number on the container instance to reserve for your container."
56+
type = number
57+
default = 0
58+
}
59+
5460
variable "task_container_protocol" {
5561
description = "Protocol that the container exposes."
5662
default = "HTTP"
@@ -140,3 +146,9 @@ variable "service_registry_arn" {
140146
description = "ARN of aws_service_discovery_service resource"
141147
type = string
142148
}
149+
150+
variable "propogate_tags" {
151+
type = string
152+
description = "Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION."
153+
default = "TASK_DEFINITION"
154+
}

0 commit comments

Comments
 (0)