Skip to content

Commit fcc690f

Browse files
committed
Enable PDS lookups from data-replication stack
* This PR adds the necessary infrastructure for outgoing connections from the data-replication service. Only requests to the NHS API IP address are routed through to the internet.
1 parent 88309f1 commit fcc690f

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

terraform/data_replication/network.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ resource "aws_vpc" "vpc" {
22
cidr_block = "10.0.0.0/16"
33
enable_dns_hostnames = true
44
enable_dns_support = true
5+
tags = {
6+
Name = "data-replication-vpc-${var.environment}"
7+
}
58
}
69

710
resource "aws_subnet" "subnet_a" {
@@ -18,6 +21,9 @@ resource "aws_subnet" "subnet_b" {
1821

1922
resource "aws_route_table" "private" {
2023
vpc_id = aws_vpc.vpc.id
24+
tags = {
25+
Name = "data-replication-private-rt-${var.environment}"
26+
}
2127
}
2228

2329
resource "aws_route_table_association" "private" {
@@ -26,6 +32,58 @@ resource "aws_route_table_association" "private" {
2632
subnet_id = local.subnet_list[count.index]
2733
}
2834

35+
resource "aws_subnet" "public_subnet" {
36+
vpc_id = aws_vpc.vpc.id
37+
cidr_block = "10.0.3.0/24"
38+
availability_zone = "${var.region}a"
39+
}
40+
41+
resource "aws_internet_gateway" "internet_gateway" {
42+
vpc_id = aws_vpc.vpc.id
43+
tags = {
44+
Name = "data-replication-igw-${var.environment}"
45+
}
46+
}
47+
48+
resource "aws_eip" "nat_ip" {
49+
domain = "vpc"
50+
depends_on = [aws_internet_gateway.internet_gateway]
51+
}
52+
53+
resource "aws_nat_gateway" "nat_gateway" {
54+
subnet_id = aws_subnet.public_subnet.id
55+
allocation_id = aws_eip.nat_ip.id
56+
connectivity_type = "public"
57+
depends_on = [aws_internet_gateway.internet_gateway]
58+
tags = {
59+
Name = "data-replication-nat-gateway-${var.environment}"
60+
}
61+
}
62+
63+
resource "aws_route" "private_to_public" {
64+
route_table_id = aws_route_table.private.id
65+
destination_cidr_block = var.allowed_egress_cidr_block
66+
nat_gateway_id = aws_nat_gateway.nat_gateway.id
67+
}
68+
69+
resource "aws_route" "public_to_igw" {
70+
route_table_id = aws_route_table.public.id
71+
destination_cidr_block = var.allowed_egress_cidr_block
72+
gateway_id = aws_internet_gateway.internet_gateway.id
73+
}
74+
75+
resource "aws_route_table" "public" {
76+
vpc_id = aws_vpc.vpc.id
77+
tags = {
78+
Name = "data-replication-public-rt-${var.environment}"
79+
}
80+
}
81+
82+
resource "aws_route_table_association" "public" {
83+
route_table_id = aws_route_table.public.id
84+
subnet_id = aws_subnet.public_subnet.id
85+
}
86+
2987
locals {
3088
vpc_endpoints = tomap(
3189
{

terraform/data_replication/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,10 @@ locals {
125125
}
126126
]
127127
}
128+
129+
variable "allowed_egress_cidr_block" {
130+
type = string
131+
description = "CIDR block for the allowed outbound traffic from the data replication service."
132+
nullable = false
133+
default = "35.234.138.138/32"
134+
}

0 commit comments

Comments
 (0)