Skip to content

Commit

Permalink
Modify networking slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
devsjc committed Nov 10, 2023
1 parent db5ca06 commit 1cdd92c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
14 changes: 10 additions & 4 deletions terraform/modules/networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resource "aws_eip" "nat_eip" {
/* NAT */
resource "aws_nat_gateway" "nat" {
allocation_id = aws_eip.nat_eip.id
subnet_id = element(aws_subnet.public_subnet.*.id, 0)
subnet_id = element(aws_subnet.public_subnets.*.id, 0)
depends_on = [aws_internet_gateway.ig]
tags = {
name = "nat"
Expand All @@ -45,17 +45,23 @@ resource "aws_nat_gateway" "nat" {

/* Public subnet */

resource "aws_subnet" "public_subnet" {
// Create a public subnet for each CIDR in the list
resource "aws_subnet" "public_subnets" {
vpc_id = aws_vpc.vpc.id
count = length(var.public_subnets_cidr)
cidr_block = element(var.public_subnets_cidr, count.index)
availability_zone = element(var.availability_zones, count.index)
map_public_ip_on_launch = true
tags = {
name = "${var.environment}-${element(var.availability_zones, count.index)}-public-subnet"
name = "${var.environment}-${element(var.availability_zones, count.index)}-public-subnet"
}
}

moved {
from = "aws_subnet.public_subnet"
to = "aws_subnet.public_subnets"
}

/* Private subnet */

resource "aws_subnet" "private_subnet" {
Expand Down Expand Up @@ -107,7 +113,7 @@ resource "aws_route" "private_nat_gateway" {

/* Route table associations */
resource "aws_route_table_association" "public" {
for_each = aws_subnet.public_subnet
for_each = toset(aws_subnet.public_subnets)
subnet_id = each.value.id
route_table_id = aws_route_table.public.id
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/networking/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ output "vpc_id" {

output "public_subnet_ids" {
value = [
for subnet in aws_subnet.public_subnet : subnet.id
for subnet in aws_subnet.public_subnets : subnet.id
]
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/services/api/eb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ resource "aws_elastic_beanstalk_environment" "eb-api-env" {
name = "Subnets"
# value = "${join(",", var.subnets)}"
# value = var.subnets
value = var.subnet_ids[0]
value = var.subnet_id
resource = ""
}
setting {
Expand Down
6 changes: 3 additions & 3 deletions terraform/modules/services/api/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ variable "vpc_id" {
}


variable "subnet_ids" {
description = "List of subnet ids where this application will run"
type = list(any)
variable "subnet_id" {
description = "Subnet id where this application will run"
type = string
}
# the type is any, as the subnets are terraform resources

Expand Down
2 changes: 1 addition & 1 deletion terraform/nowcasting/development/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module "api" {
region = var.region
environment = var.environment
vpc_id = module.networking.vpc_id
subnet_ids = module.networking.public_subnet_ids[0]
subnet_id = module.networking.public_subnet_ids[0]
docker_version = var.api_version
database_forecast_secret_url = module.database.forecast-database-secret-url
database_pv_secret_url = module.database.pv-database-secret-url
Expand Down

0 comments on commit 1cdd92c

Please sign in to comment.