@@ -39,6 +39,7 @@ resource "aws_subnet" "public_subnet" {
3939}
4040
4141resource "aws_internet_gateway" "internet_gateway" {
42+ count = var. allowed_egress_cidr_block == null ? 0 : 1
4243 vpc_id = aws_vpc. vpc . id
4344 tags = {
4445 Name = " data-replication-igw-${ var . environment } "
@@ -51,6 +52,7 @@ resource "aws_eip" "nat_ip" {
5152}
5253
5354resource "aws_nat_gateway" "nat_gateway" {
55+ count = var. allowed_egress_cidr_block == null ? 0 : 1
5456 subnet_id = aws_subnet. public_subnet . id
5557 allocation_id = aws_eip. nat_ip . id
5658 connectivity_type = " public"
@@ -61,15 +63,17 @@ resource "aws_nat_gateway" "nat_gateway" {
6163}
6264
6365resource "aws_route" "private_to_public" {
66+ count = var. allowed_egress_cidr_block == null ? 0 : 1
6467 route_table_id = aws_route_table. private . id
6568 destination_cidr_block = var. allowed_egress_cidr_block
66- nat_gateway_id = aws_nat_gateway. nat_gateway . id
69+ nat_gateway_id = aws_nat_gateway. nat_gateway [ 0 ] . id
6770}
6871
6972resource "aws_route" "public_to_igw" {
73+ count = var. allowed_egress_cidr_block == null ? 0 : 1
7074 route_table_id = aws_route_table. public . id
7175 destination_cidr_block = var. allowed_egress_cidr_block
72- gateway_id = aws_internet_gateway. internet_gateway . id
76+ gateway_id = aws_internet_gateway. internet_gateway [ 0 ] . id
7377}
7478
7579resource "aws_route_table" "public" {
0 commit comments