Skip to content

Commit 449fdc1

Browse files
committed
Allow multiple CIDR blocks
1 parent 78c9ce8 commit 449fdc1

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

.github/workflows/data-replication-pipeline.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ on:
3232
required: false
3333
type: string
3434
egress_cidr:
35-
description: CIDR block to allow egress traffic (optional)
36-
required: false
35+
description: CIDR blocks to allow egress traffic.
3736
type: string
37+
required: true
38+
default: "[]"
3839

3940
env:
4041
aws_role: ${{ inputs.environment == 'production'
@@ -197,7 +198,7 @@ jobs:
197198
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
198199
terraform plan -var="image_digest=${{ env.DOCKER_DIGEST }}" -var="db_secret_arn=${{ env.DB_SECRET_ARN }}" \
199200
-var="imported_snapshot=${{ env.SNAPSHOT_ARN }}" -var-file="env/${{ inputs.environment }}.tfvars" \
200-
-var="allowed_egress_cidr_block=${{ inputs.egress_cidr }}" \
201+
-var="allowed_egress_cidr_blocks=${{ fromJSON(inputs.egress_cidr) }}" \
201202
-out ${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
202203
- name: Upload artifact
203204
uses: actions/upload-artifact@v4

terraform/data_replication/network.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +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
42+
count = min(length(var.allowed_egress_cidr_blocks), 1)
4343
vpc_id = aws_vpc.vpc.id
4444
tags = {
4545
Name = "data-replication-igw-${var.environment}"
@@ -52,7 +52,7 @@ resource "aws_eip" "nat_ip" {
5252
}
5353

5454
resource "aws_nat_gateway" "nat_gateway" {
55-
count = var.allowed_egress_cidr_block == null ? 0 : 1
55+
count = min(length(var.allowed_egress_cidr_blocks), 1)
5656
subnet_id = aws_subnet.public_subnet.id
5757
allocation_id = aws_eip.nat_ip.id
5858
connectivity_type = "public"
@@ -63,16 +63,16 @@ resource "aws_nat_gateway" "nat_gateway" {
6363
}
6464

6565
resource "aws_route" "private_to_public" {
66-
count = var.allowed_egress_cidr_block == null ? 0 : 1
66+
count = length(var.allowed_egress_cidr_blocks)
6767
route_table_id = aws_route_table.private.id
68-
destination_cidr_block = var.allowed_egress_cidr_block
68+
destination_cidr_block = var.allowed_egress_cidr_blocks[count.index]
6969
nat_gateway_id = aws_nat_gateway.nat_gateway[0].id
7070
}
7171

7272
resource "aws_route" "public_to_igw" {
73-
count = var.allowed_egress_cidr_block == null ? 0 : 1
73+
count = length(var.allowed_egress_cidr_blocks)
7474
route_table_id = aws_route_table.public.id
75-
destination_cidr_block = var.allowed_egress_cidr_block
75+
destination_cidr_block = var.allowed_egress_cidr_blocks[count.index]
7676
gateway_id = aws_internet_gateway.internet_gateway[0].id
7777
}
7878

terraform/data_replication/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ locals {
126126
]
127127
}
128128

129-
variable "allowed_egress_cidr_block" {
130-
type = string
131-
description = "CIDR block for the allowed outbound traffic from the data replication service."
132-
default = null
129+
variable "allowed_egress_cidr_blocks" {
130+
type = list(string)
131+
description = "CIDR blocks for the allowed outbound traffic from the data replication service."
132+
default = []
133133
}

0 commit comments

Comments
 (0)