Skip to content

Commit a54b3cb

Browse files
committed
Don't allow egress by default
1 parent fcc690f commit a54b3cb

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

terraform/data_replication/network.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ resource "aws_subnet" "public_subnet" {
3939
}
4040

4141
resource "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

5354
resource "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

6365
resource "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

6972
resource "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

7579
resource "aws_route_table" "public" {

terraform/data_replication/variables.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,5 @@ locals {
129129
variable "allowed_egress_cidr_block" {
130130
type = string
131131
description = "CIDR block for the allowed outbound traffic from the data replication service."
132-
nullable = false
133-
default = "35.234.138.138/32"
132+
default = null
134133
}

0 commit comments

Comments
 (0)