Skip to content

Commit

Permalink
Update vpc_dmz to use 0 instead of count.index
Browse files Browse the repository at this point in the history
  • Loading branch information
aloftus23 committed May 9, 2024
1 parent 3978099 commit 9ecb68b
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions infrastructure/vpc-dmz.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resource "aws_vpc" "crossfeed_vpc" {
resource "aws_subnet" "db_1" {
count = var.is_dmz ? 1 : 0
availability_zone = data.aws_availability_zones.available.names[0]
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id
cidr_block = "10.0.1.0/28"

tags = {
Expand All @@ -22,7 +22,7 @@ resource "aws_subnet" "db_1" {
resource "aws_subnet" "db_2" {
count = var.is_dmz ? 1 : 0
availability_zone = data.aws_availability_zones.available.names[1]
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id
cidr_block = "10.0.1.16/28"

tags = {
Expand All @@ -33,7 +33,7 @@ resource "aws_subnet" "db_2" {
resource "aws_subnet" "backend" {
count = var.is_dmz ? 1 : 0
availability_zone = data.aws_availability_zones.available.names[1]
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id
cidr_block = "10.0.2.0/24"

tags = {
Expand All @@ -44,7 +44,7 @@ resource "aws_subnet" "backend" {
resource "aws_subnet" "worker" {
count = var.is_dmz ? 1 : 0
availability_zone = data.aws_availability_zones.available.names[1]
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id
cidr_block = "10.0.3.0/24"

tags = {
Expand All @@ -56,7 +56,7 @@ resource "aws_subnet" "worker" {
resource "aws_subnet" "es_1" {
count = var.is_dmz ? 1 : 0
availability_zone = data.aws_availability_zones.available.names[0]
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id
cidr_block = "10.0.4.0/28"

tags = {
Expand All @@ -67,7 +67,7 @@ resource "aws_subnet" "es_1" {
resource "aws_subnet" "matomo_1" {
count = var.is_dmz ? 1 : 0
availability_zone = data.aws_availability_zones.available.names[0]
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id
cidr_block = "10.0.5.0/28"

tags = {
Expand All @@ -77,7 +77,7 @@ resource "aws_subnet" "matomo_1" {

resource "aws_route_table" "r" {
count = var.is_dmz ? 1 : 0
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id

tags = {
Project = var.project
Expand All @@ -87,10 +87,10 @@ resource "aws_route_table" "r" {

resource "aws_route_table" "r2" {
count = var.is_dmz ? 1 : 0
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id

route {
nat_gateway_id = aws_nat_gateway.nat[count.index].id
nat_gateway_id = aws_nat_gateway.nat[0].id
cidr_block = "0.0.0.0/0"
}

Expand All @@ -102,10 +102,10 @@ resource "aws_route_table" "r2" {

resource "aws_route_table" "worker" {
count = var.is_dmz ? 1 : 0
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id

route {
gateway_id = aws_internet_gateway.gw[count.index].id
gateway_id = aws_internet_gateway.gw[0].id
cidr_block = "0.0.0.0/0"
}

Expand All @@ -117,37 +117,37 @@ resource "aws_route_table" "worker" {

resource "aws_route_table_association" "r_assoc_db_1" {
count = var.is_dmz ? 1 : 0
route_table_id = aws_route_table.r[count.index].id
subnet_id = aws_subnet.db_1[count.index].id
route_table_id = aws_route_table.r[0].id
subnet_id = aws_subnet.db_1[0].id
}

resource "aws_route_table_association" "r_assoc_db_2" {
count = var.is_dmz ? 1 : 0
route_table_id = aws_route_table.r[count.index].id
subnet_id = aws_subnet.db_2[count.index].id
route_table_id = aws_route_table.r[0].id
subnet_id = aws_subnet.db_2[0].id
}

resource "aws_route_table_association" "r_assoc_backend" {
count = var.is_dmz ? 1 : 0
route_table_id = aws_route_table.r2[count.index].id
subnet_id = aws_subnet.backend[count.index].id
route_table_id = aws_route_table.r2[0].id
subnet_id = aws_subnet.backend[0].id
}

resource "aws_route_table_association" "r_assoc_matomo" {
count = var.is_dmz ? 1 : 0
route_table_id = aws_route_table.r2[count.index].id
subnet_id = aws_subnet.matomo_1[count.index].id
route_table_id = aws_route_table.r2[0].id
subnet_id = aws_subnet.matomo_1[0].id
}

resource "aws_route_table_association" "r_assoc_worker" {
count = var.is_dmz ? 1 : 0
route_table_id = aws_route_table.worker[count.index].id
subnet_id = aws_subnet.worker[count.index].id
route_table_id = aws_route_table.worker[0].id
subnet_id = aws_subnet.worker[0].id
}

resource "aws_internet_gateway" "gw" {
count = var.is_dmz ? 1 : 0
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id

tags = {
Project = var.project
Expand All @@ -164,8 +164,8 @@ resource "aws_eip" "nat_eip" {

resource "aws_nat_gateway" "nat" {
count = var.is_dmz ? 1 : 0
allocation_id = aws_eip.nat_eip[count.index].id
subnet_id = aws_subnet.worker[count.index].id
allocation_id = aws_eip.nat_eip[0].id
subnet_id = aws_subnet.worker[0].id

tags = {
Project = var.project
Expand All @@ -177,14 +177,14 @@ resource "aws_security_group" "allow_internal" {
count = var.is_dmz ? 1 : 0
name = "allow-internal"
description = "Allow All VPC Internal Traffic"
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id

ingress {
description = "All Lambda Subnet"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [aws_vpc.crossfeed_vpc[count.index].id]
cidr_blocks = [aws_vpc.crossfeed_vpc[0].id]
}

egress {
Expand All @@ -207,13 +207,13 @@ resource "aws_security_group" "backend" {
count = var.is_dmz ? 1 : 0
name = "backend"
description = "Backend"
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [aws_vpc.crossfeed_vpc[count.index].id]
cidr_blocks = [aws_vpc.crossfeed_vpc[0].id]
}

tags = {
Expand All @@ -227,7 +227,7 @@ resource "aws_security_group" "worker" {
count = var.is_dmz ? 1 : 0
name = "worker"
description = "Worker"
vpc_id = aws_vpc.crossfeed_vpc[count.index].id
vpc_id = aws_vpc.crossfeed_vpc[0].id

egress {
from_port = 0
Expand Down

0 comments on commit 9ecb68b

Please sign in to comment.