Skip to content

Commit d263bbc

Browse files
authored
feat: Setting Default AWS VPN Tunnel Options (#5)
* feat: Setting Default AWS VPN Tunnel Options This addresses the known issue described in the Google docs for creating an HA VPN Connection with AWS https://cloud.google.com/network-connectivity/docs/vpn/how-to/creating-ha-vpn * feat: updating defaults Updating the default tunnel settings. To be slightly more robust. * feat: update DH group to 18 This is the max supported DH group on GCP currently * docs: update docs with correct DH group
1 parent 1c5896c commit d263bbc

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

HEADER.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Overview of high-level configurations steps to set up HA VPN with Amazon Web Ser
44
* Create the HA VPN gateway and a Cloud Router. This creates 2 public IP addresses on the GCP side.
55
* Create two AWS Virtual Private Gateways. This creates 4 public addresses on the AWS side.
66
* Create two AWS Site-to-Site VPN connections and customer gateways, one for each AWS Virtual Private Gateway. Specify a non-overlapping link-local Tunnel IP Range for each tunnel, 4 total. For example, 169.254.1.4/30.
7+
* Configure AES-256, SHA-2 and DH group 18, [as a combination of single Phase 1 and Phase 2 encryption algorithms, integrity algorithms, and DH group numbers.](https://cloud.google.com/network-connectivity/docs/vpn/how-to/creating-ha-vpn)
78
* Download the AWS configuration files for the generic device type.
89
* Create four VPN tunnels on the HA VPN gateway.
910
* Configure BGP sessions on the Cloud Router using the BGP IP addresses from the downloaded AWS configuration files.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Overview of high-level configurations steps to set up HA VPN with Amazon Web Ser
44
* Create the HA VPN gateway and a Cloud Router. This creates 2 public IP addresses on the GCP side.
55
* Create two AWS Virtual Private Gateways. This creates 4 public addresses on the AWS side.
66
* Create two AWS Site-to-Site VPN connections and customer gateways, one for each AWS Virtual Private Gateway. Specify a non-overlapping link-local Tunnel IP Range for each tunnel, 4 total. For example, 169.254.1.4/30.
7+
* Configure AES-256, SHA-2 and DH group 18, [as a combination of single Phase 1 and Phase 2 encryption algorithms, integrity algorithms, and DH group numbers.](https://cloud.google.com/network-connectivity/docs/vpn/how-to/creating-ha-vpn)
78
* Download the AWS configuration files for the generic device type.
89
* Create four VPN tunnels on the HA VPN gateway.
910
* Configure BGP sessions on the Cloud Router using the BGP IP addresses from the downloaded AWS configuration files.
@@ -61,6 +62,7 @@ https://cloud.google.com/vpn/docs/how-to/creating-ha-vpn
6162
|------|-------------|------|---------|:--------:|
6263
| transit\_gateway\_id | AWS Transit Gateway ID | `string` | n/a | yes |
6364
| amazon\_side\_asn | BGP ASN Number for the AWS side of the VPN | `number` | `64512` | no |
65+
| aws\_vpn\_configs | AWS Tunnels Configs for aws\_vpn\_connection. This addresses this [known issue](https://cloud.google.com/network-connectivity/docs/vpn/how-to/creating-ha-vpn). | `map(any)` | <pre>{<br> "dh_group_numbers": [<br> "18"<br> ],<br> "encryption_algorithms": [<br> "AES256"<br> ],<br> "integrity_algorithms": [<br> "SHA2-256"<br> ]<br>}</pre> | no |
6466
| google\_network | Google VPN Network name, can be either a name or a self\_link | `string` | `"default"` | no |
6567
| google\_side\_asn | BGP ASN Number for the Google side of the VPN | `number` | `65534` | no |
6668
| router\_advertise\_config | Router custom advertisement configuration, ip\_ranges is a map of address ranges and descriptions. More info can be found here https://www.terraform.io/docs/providers/google/r/compute_router.html#bgp (Default: null) | <pre>object({<br> groups = list(string)<br> ip_ranges = map(string)<br> mode = string<br> })</pre> | `null` | no |

main.tf

+36-12
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ resource "google_compute_ha_vpn_gateway" "gateway" {
6969
network = var.google_network
7070
}
7171

72-
# Can't loop the cgw because TF erros with : Terraform value depends on resource attributes that cannot be determined
72+
# Can't loop the cgw because TF errors with : Terraform value depends on resource attributes that cannot be determined
7373
# until apply, so Terraform cannot predict how many instances will be created.
7474
# We know for each GW there will always be 2 interfaces so maybe a map of alpha/beta if we want a loop. For now
75-
# I'm leaving as seperate resources.
75+
# I'm leaving as separate resources.
7676

7777
resource "aws_customer_gateway" "cgw-alpha" {
7878
bgp_asn = var.google_side_asn
@@ -97,19 +97,43 @@ resource "aws_customer_gateway" "cgw-beta" {
9797
// TODO Track this Issue and implement when ready https://github.com/terraform-providers/terraform-provider-aws/issues/11584
9898

9999
resource "aws_vpn_connection" "vpn-alpha" {
100-
customer_gateway_id = aws_customer_gateway.cgw-alpha.id
101-
transit_gateway_id = var.transit_gateway_id
102-
type = aws_customer_gateway.cgw-alpha.type
100+
customer_gateway_id = aws_customer_gateway.cgw-alpha.id
101+
transit_gateway_id = var.transit_gateway_id
102+
type = aws_customer_gateway.cgw-alpha.type
103+
tunnel1_phase1_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
104+
tunnel2_phase1_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
105+
tunnel1_phase1_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
106+
tunnel2_phase1_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
107+
tunnel1_phase1_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
108+
tunnel2_phase1_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
109+
tunnel1_phase2_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
110+
tunnel2_phase2_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
111+
tunnel1_phase2_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
112+
tunnel2_phase2_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
113+
tunnel1_phase2_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
114+
tunnel2_phase2_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
103115

104116
tags = {
105117
"Name" = "vpn-to-google-alpha-${local.suffix}"
106118
}
107119
}
108120

109121
resource "aws_vpn_connection" "vpn-beta" {
110-
customer_gateway_id = aws_customer_gateway.cgw-beta.id
111-
transit_gateway_id = var.transit_gateway_id
112-
type = aws_customer_gateway.cgw-beta.type
122+
customer_gateway_id = aws_customer_gateway.cgw-beta.id
123+
transit_gateway_id = var.transit_gateway_id
124+
type = aws_customer_gateway.cgw-beta.type
125+
tunnel1_phase1_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
126+
tunnel2_phase1_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
127+
tunnel1_phase1_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
128+
tunnel2_phase1_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
129+
tunnel1_phase1_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
130+
tunnel2_phase1_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
131+
tunnel1_phase2_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
132+
tunnel2_phase2_encryption_algorithms = var.aws_vpn_configs.encryption_algorithms
133+
tunnel1_phase2_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
134+
tunnel2_phase2_integrity_algorithms = var.aws_vpn_configs.integrity_algorithms
135+
tunnel1_phase2_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
136+
tunnel2_phase2_dh_group_numbers = var.aws_vpn_configs.dh_group_numbers
113137

114138
tags = {
115139
"Name" = "vpn-to-google-beta-${local.suffix}"
@@ -174,7 +198,7 @@ resource "google_compute_vpn_tunnel" "tunnels" {
174198
description = "Tunnel to AWS - HA VPN interface ${each.key} to AWS interface ${each.value.tunnel_address}"
175199
router = google_compute_router.router.self_link
176200
ike_version = 2
177-
shared_secret = each.value.shared_secret #local.external_vpn_gateway_interfaces[0].shared_secret #aws_vpn_connection.vpn-alpha.tunnel1_preshared_key
201+
shared_secret = each.value.shared_secret
178202
vpn_gateway = google_compute_ha_vpn_gateway.gateway.self_link
179203
vpn_gateway_interface = each.value.vpn_gateway_interface
180204
peer_external_gateway = google_compute_external_vpn_gateway.external_gateway.self_link
@@ -186,7 +210,7 @@ resource "google_compute_router_interface" "interfaces" {
186210
for_each = local.external_vpn_gateway_interfaces
187211
name = "interface${each.key}-${google_compute_router.router.name}"
188212
router = google_compute_router.router.name
189-
ip_range = each.value.cgw_inside_address #"${aws_vpn_connection.vpn-alpha.tunnel1_cgw_inside_address}/30" #"169.254.0.1/30"
213+
ip_range = each.value.cgw_inside_address
190214
vpn_tunnel = google_compute_vpn_tunnel.tunnels[each.key].name
191215
}
192216

@@ -195,7 +219,7 @@ resource "google_compute_router_peer" "router_peers" {
195219
for_each = local.external_vpn_gateway_interfaces
196220
name = "peer${each.key}-${google_compute_router.router.name}"
197221
router = google_compute_router.router.name
198-
peer_ip_address = each.value.vgw_inside_address #aws_vpn_connection.vpn-alpha.tunnel1_vgw_inside_address #"169.254.0.2"
199-
peer_asn = each.value.asn #aws_vpn_connection.vpn-alpha.tunnel1_bgp_asn # aws_customer_gateway.cgw-alpha.bgp_asn #aws_vpn_connection.vpn-alpha.tunnel1_bgp_asn #64515
222+
peer_ip_address = each.value.vgw_inside_address
223+
peer_asn = each.value.asn
200224
interface = google_compute_router_interface.interfaces[each.key].name
201225
}

variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ variable "amazon_side_asn" {
2929
description = "BGP ASN Number for the AWS side of the VPN"
3030
}
3131

32+
variable "aws_vpn_configs" {
33+
type = map(any)
34+
description = "AWS Tunnels Configs for aws_vpn_connection. This addresses this [known issue](https://cloud.google.com/network-connectivity/docs/vpn/how-to/creating-ha-vpn)."
35+
default = {
36+
encryption_algorithms = ["AES256"]
37+
integrity_algorithms = ["SHA2-256"]
38+
dh_group_numbers = ["18"]
39+
}
40+
}
41+
3242
variable "google_side_asn" {
3343
type = number
3444
default = 65534

0 commit comments

Comments
 (0)