Skip to content

Commit

Permalink
Rolling back changes to vpc_infra (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectormachin authored May 31, 2024
1 parent 9faf2e3 commit 30f66ea
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 28 deletions.
6 changes: 3 additions & 3 deletions modules/base_infra/vpc_infra/igw.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Creates Internet Gateway, with a public route table, and a default route
resource "aws_internet_gateway" "igw" {
vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id

tags = {
Name = "${local.name_prefix}-internet-gateway"
}
}

resource "aws_route_table" "public_route_table" {
vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id

tags = {
Name = "${local.name_prefix}-public-route-table"
Expand All @@ -22,7 +22,7 @@ resource "aws_route" "public_default_route" {
}

resource "aws_route_table_association" "public_route_table_associations" {
for_each = data.aws_subnet.public_subnets
for_each = aws_subnet.public_subnets

subnet_id = each.value.id
route_table_id = aws_route_table.public_route_table.id
Expand Down
18 changes: 9 additions & 9 deletions modules/base_infra/vpc_infra/ngw.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ resource "aws_eip" "eips" {
}

resource "aws_nat_gateway" "ngws" {
for_each = data.aws_subnet.public_subnets
for_each = aws_subnet.public_subnets

allocation_id = element(values(aws_eip.eips)[*].id, index(values(data.aws_subnet.public_subnets)[*].id, each.value.id))
allocation_id = element(values(aws_eip.eips)[*].id, index(values(aws_subnet.public_subnets)[*].id, each.value.id))
subnet_id = each.value.id
tags = {
Name = "${local.name_prefix}-nat-gateway-${each.value.id}"
Expand All @@ -23,9 +23,9 @@ resource "aws_nat_gateway" "ngws" {
# We need a different route table per subnet, because each subnet
# may point to a different NAT Gateway for high availability
resource "aws_route_table" "private_route_tables" {
for_each = data.aws_subnet.private_subnets
for_each = aws_subnet.private_subnets

vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id

tags = {
Name = "${local.name_prefix}-private-route-table-${each.value.id}"
Expand All @@ -35,10 +35,10 @@ resource "aws_route_table" "private_route_tables" {
}

resource "aws_route_table_association" "private_route_table_associations" {
for_each = data.aws_subnet.private_subnets
for_each = aws_subnet.private_subnets

subnet_id = each.value.id
route_table_id = element(values(aws_route_table.private_route_tables)[*].id, index(values(data.aws_subnet.private_subnets)[*].id, each.value.id))
route_table_id = element(values(aws_route_table.private_route_tables)[*].id, index(values(aws_subnet.private_subnets)[*].id, each.value.id))
}


Expand All @@ -47,9 +47,9 @@ resource "aws_route_table_association" "private_route_table_associations" {
# and the number of Public Subnets may not be equal to the number of Private Subnets.
# This means that the number of NAT Gateways may not be equal to the number of Private Route Tables.
resource "aws_route" "private_subnet_default_routes" {
for_each = data.aws_subnet.private_subnets
for_each = aws_subnet.private_subnets

route_table_id = element(values(aws_route_table.private_route_tables)[*].id, index(values(data.aws_subnet.private_subnets)[*].id, each.value.id))
nat_gateway_id = element(values(aws_nat_gateway.ngws)[*].id, index(values(data.aws_subnet.private_subnets)[*].id, each.value.id) % length(values(data.aws_subnet.public_subnets)[*].id))
route_table_id = element(values(aws_route_table.private_route_tables)[*].id, index(values(aws_subnet.private_subnets)[*].id, each.value.id))
nat_gateway_id = element(values(aws_nat_gateway.ngws)[*].id, index(values(aws_subnet.private_subnets)[*].id, each.value.id) % length(values(aws_subnet.public_subnets)[*].id))
destination_cidr_block = "0.0.0.0/0"
}
6 changes: 3 additions & 3 deletions modules/base_infra/vpc_infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ output "eip_ids" {

output "vpc_id" {
description = "FilmDrop VPC ID"
value = data.aws_vpc.filmdrop_vpc.id
value = aws_vpc.filmdrop_vpc.id
}

output "private_subnet_ids" {
description = "List of FilmDrop Private Subnet IDs"
value = values(data.aws_subnet.private_subnets)[*].id
value = values(aws_subnet.private_subnets)[*].id
}

output "public_subnet_ids" {
description = "List of FilmDrop Public Subnet IDs"
value = values(data.aws_subnet.public_subnets)[*].id
value = values(aws_subnet.public_subnets)[*].id
}

output "private_avaliability_zones" {
Expand Down
6 changes: 3 additions & 3 deletions modules/base_infra/vpc_infra/vpc_endpoints.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module "gateway_endpoints" {

for_each = toset(var.gateway_endpoints_list)

vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id
service_name = "com.amazonaws.${data.aws_region.current.name}.${each.value}"
route_table_ids = concat([aws_route_table.public_route_table.id], values(aws_route_table.private_route_tables)[*].id)
}
Expand All @@ -13,9 +13,9 @@ module "interface_endpoints" {

for_each = toset(var.interface_endpoints_list)

vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id
service_name = "com.amazonaws.${data.aws_region.current.name}.${each.value}"
security_group_ids = [aws_security_group.filmdrop_vpc_default_sg.id]
subnet_ids = values(data.aws_subnet.private_subnets)[*].id
subnet_ids = values(aws_subnet.private_subnets)[*].id
private_dns_enabled = true
}
2 changes: 1 addition & 1 deletion modules/base_infra/vpc_infra/vpc_security_group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resource "aws_security_group" "filmdrop_vpc_default_sg" {
name = "${local.name_prefix}-sg"
description = "Default Security Group for the FilmDrop ${var.project_name} ${var.environment} VPC"
vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id
}

# Allows any inbound traffic coming from within the FilmDrop VPC
Expand Down
39 changes: 30 additions & 9 deletions modules/base_infra/vpc_infra/vpc_subnets.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
data "aws_vpc" "filmdrop_vpc" {
cidr_block = var.vpc_cidr
resource "aws_vpc" "filmdrop_vpc" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true

tags = {
Name = "${local.name_prefix}-vpc"
}
}

data "aws_subnet" "public_subnets" {
resource "aws_subnet" "public_subnets" {
for_each = var.public_subnets_az_to_id_map
id = each.value

vpc_id = aws_vpc.filmdrop_vpc.id
cidr_block = each.value
availability_zone = each.key

tags = {
Name = "${local.name_prefix}-public-subnet-${each.key}"
}
}

data "aws_subnet" "private_subnets" {
resource "aws_subnet" "private_subnets" {
for_each = var.private_subnets_az_to_id_map
id = each.value

vpc_id = aws_vpc.filmdrop_vpc.id
cidr_block = each.value
availability_zone = each.key

tags = {
Name = "${local.name_prefix}-private-subnet-${each.key}"
}

}

# Set up default DHCP options for DNS resolution in FilmDrop VPC - defaults to AmazonProvidedDNS
Expand All @@ -19,7 +40,7 @@ resource "aws_vpc_dhcp_options" "vpc_dhcp_options" {
}

resource "aws_vpc_dhcp_options_association" "vpc_dhcp_options_association" {
vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id
dhcp_options_id = aws_vpc_dhcp_options.vpc_dhcp_options.id
}

Expand All @@ -31,10 +52,10 @@ resource "aws_flow_log" "filmdrop_vpc_flow_logs_to_s3" {
log_format = var.log_format
max_aggregation_interval = var.max_aggregation_interval
traffic_type = var.traffic_type
vpc_id = data.aws_vpc.filmdrop_vpc.id
vpc_id = aws_vpc.filmdrop_vpc.id

tags = {
Name = "${local.name_prefix}-flow-logs-${data.aws_vpc.filmdrop_vpc.id}"
Name = "${local.name_prefix}-flow-logs-${aws_vpc.filmdrop_vpc.id}"
}
}

Expand Down

0 comments on commit 30f66ea

Please sign in to comment.