Skip to content
Open
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
5 changes: 3 additions & 2 deletions .modules/webservice/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ resource "aws_ecs_service" "webservice" {
launch_type = var.launch_type

network_configuration {
subnets = data.tfe_outputs.infrastructure.values[var.region].private_subnets
security_groups = [aws_security_group.container_sg.id]
subnets = var.public_task ? data.tfe_outputs.infrastructure.values[var.region].public_subnets : data.tfe_outputs.infrastructure.values[var.region].private_subnets
security_groups = [aws_security_group.container_sg.id]
assign_public_ip = var.public_task
}

depends_on = [
Expand Down
13 changes: 7 additions & 6 deletions .modules/webservice/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ resource "aws_security_group" "container_sg" {
}

ingress {
description = "Web traffic"
from_port = var.port
protocol = "tcp"
to_port = var.port
cidr_blocks = ["0.0.0.0/0"]
description = var.public_task ? "Web traffic from ALB only" : "Web traffic"
from_port = var.port
protocol = "tcp"
to_port = var.port
security_groups = var.public_task ? [aws_security_group.lb_sg.id] : []
cidr_blocks = var.public_task ? [] : ["0.0.0.0/0"]
}

tags = {
Region = var.region
Zone = "private"
Zone = var.public_task ? "public" : "private"
}
}

Expand Down
6 changes: 6 additions & 0 deletions .modules/webservice/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ variable "rolling_updates" {
default = false
type = bool
}

variable "public_task" {
description = "Run the Fargate task in a public subnet with a public IP, removing the need for a NAT gateway"
default = false
type = bool
}
9 changes: 5 additions & 4 deletions infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ provider "aws" {
}

module "us_east_1" {
source = "./region"
region = "us-east-1"
ecs_policy = aws_iam_instance_profile.ecs_instance_profile.arn
network_cidr = var.network_cidr["us-east-1"]
source = "./region"
region = "us-east-1"
ecs_policy = aws_iam_instance_profile.ecs_instance_profile.arn
network_cidr = var.network_cidr["us-east-1"]
enable_nat_gateway = false
}
6 changes: 3 additions & 3 deletions infrastructure/region/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resource "aws_route_table" "public" {
}

resource "aws_eip" "nat" {
count = 2
count = var.enable_nat_gateway ? 2 : 0

vpc = true

Expand All @@ -42,7 +42,7 @@ resource "aws_eip" "nat" {
}

resource "aws_nat_gateway" "gw_nat" {
count = 2
count = var.enable_nat_gateway ? 2 : 0

allocation_id = aws_eip.nat[count.index].id
subnet_id = aws_subnet.public[count.index].id
Expand All @@ -53,7 +53,7 @@ resource "aws_nat_gateway" "gw_nat" {
}

resource "aws_route_table" "private" {
count = 2
count = var.enable_nat_gateway ? 2 : 0

vpc_id = aws_vpc.network.id

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/region/subnet.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "aws_route_table_association" "public" {
}

resource "aws_route_table_association" "private" {
count = 2
count = var.enable_nat_gateway ? 2 : 0

subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private[count.index].id
Expand Down
6 changes: 6 additions & 0 deletions infrastructure/region/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ variable "ecs_policy" {
description = "The name attribute of the IAM instance profile"
type = string
}

variable "enable_nat_gateway" {
description = "Create NAT gateways and route private subnets through them. Set to false when all services use public_task = true."
type = bool
default = true
}
1 change: 1 addition & 0 deletions service_hub_bots/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module "webservice_service_hub_bots" {
port = 5000
healthcheck_path = "/__heartbeat__"
rolling_updates = true
public_task = true

container_definitions = {
"command" : [
Expand Down
Loading