-
Notifications
You must be signed in to change notification settings - Fork 4
/
s2s-vpn-aws.tf
164 lines (129 loc) · 5.29 KB
/
s2s-vpn-aws.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# --------------------------------------------------------------------------------------------------
# CREATE VPC
# --------------------------------------------------------------------------------------------------
resource "aws_vpc" "aws-vpc" {
cidr_block = var.aws_vnet_prefix
tags = {
Name = "VPC1"
}
}
# --------------------------------------------------------------------------------------------------
# CREATE IG - Needed for AWS Test VM Internet connectivity
# --------------------------------------------------------------------------------------------------
resource "aws_internet_gateway" "ig-test-aws-vm" {
vpc_id = aws_vpc.aws-vpc.id
tags = {
Name = "ig-test-aws-vm"
}
}
# --------------------------------------------------------------------------------------------------
# CREATE ROUTE TABLE
# --------------------------------------------------------------------------------------------------
resource "aws_route_table" "vpn-route-table" {
vpc_id = aws_vpc.aws-vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.ig-test-aws-vm.id
}
tags = {
Name = "vpn-route-table"
}
}
# --------------------------------------------------------------------------------------------------
# CREATE SUBNET FOR AWS TESTING VM
# --------------------------------------------------------------------------------------------------
resource "aws_subnet" "vpn-subnet" {
vpc_id = aws_vpc.aws-vpc.id
cidr_block = var.aws_vm_subnet_prefix
map_public_ip_on_launch = true
tags = {
Name = "vpn-test-subnet"
}
}
resource "aws_route_table_association" "vpn-route-table-asoc" {
subnet_id = aws_subnet.vpn-subnet.id
route_table_id = aws_route_table.vpn-route-table.id
}
# --------------------------------------------------------------------------------------------------
# PROPAGATE BGP ROUTES INTO ROUTE TABLE
# --------------------------------------------------------------------------------------------------
resource "aws_vpn_gateway_route_propagation" "vpc-route-propagation" {
vpn_gateway_id = aws_vpn_gateway.vpn-gw.id
route_table_id = aws_route_table.vpn-route-table.id
}
# --------------------------------------------------------------------------------------------------
# CREATE AWS VPN GATEWAY
# --------------------------------------------------------------------------------------------------
resource "aws_vpn_gateway" "vpn-gw" {
vpc_id = aws_vpc.aws-vpc.id
tags = {
Name = "vpn-gw"
}
}
# --------------------------------------------------------------------------------------------------
# CREATE AWS CUSTOMER GATEWAYS
# --------------------------------------------------------------------------------------------------
resource "aws_customer_gateway" "ToAzureInstance0" {
bgp_asn = var.azure_vpn_gateway_asn
ip_address = azurerm_public_ip.VNet1GWpip.ip_address
type = "ipsec.1"
tags = {
Name = "ToAzureInstance0"
}
}
resource "aws_customer_gateway" "ToAzureInstance1" {
bgp_asn = var.azure_vpn_gateway_asn
ip_address = azurerm_public_ip.VNet1GWpip2.ip_address
type = "ipsec.1"
tags = {
Name = "ToAzureInstance1"
}
}
# --------------------------------------------------------------------------------------------------
# CREATE AWS VPN CONENCTIONS
# --------------------------------------------------------------------------------------------------
resource "aws_vpn_connection" "ToAzureInstance0" {
vpn_gateway_id = aws_vpn_gateway.vpn-gw.id
customer_gateway_id = aws_customer_gateway.ToAzureInstance0.id
type = "ipsec.1"
static_routes_only = false
tunnel1_preshared_key = random_password.AWSTunnel1ToInstance0-PSK.result
tunnel2_preshared_key = random_password.AWSTunnel2ToInstance0-PSK.result
tunnel1_inside_cidr = var.bgp_apipa_cidr_1
tunnel2_inside_cidr = var.bgp_apipa_cidr_2
tags = {
Name = "ToAzureInstance0"
}
}
resource "aws_vpn_connection" "ToAzureInstance1" {
vpn_gateway_id = aws_vpn_gateway.vpn-gw.id
customer_gateway_id = aws_customer_gateway.ToAzureInstance1.id
type = "ipsec.1"
static_routes_only = false
tunnel1_preshared_key = random_password.AWSTunnel1ToInstance1-PSK.result
tunnel2_preshared_key = random_password.AWSTunnel2ToInstance1-PSK.result
tunnel1_inside_cidr = var.bgp_apipa_cidr_3
tunnel2_inside_cidr = var.bgp_apipa_cidr_4
tags = {
Name = "ToAzureInstance1"
}
}
# --------------------------------------------------------------------------------------------------
# OUTPUTS
# --------------------------------------------------------------------------------------------------
output "ToAzureInstance0_Tunnel1_IP" {
description = "To AzureInstance0 Tunnel 1 Outside IP address"
value = aws_vpn_connection.ToAzureInstance0.tunnel1_address
}
output "ToAzureInstance0_Tunnel2_IP" {
description = "To AzureInstance0 Tunnel 2 Outside IP address"
value = aws_vpn_connection.ToAzureInstance0.tunnel2_address
}
output "ToAzureInstance1_Tunnel1_IP" {
description = "To AzureInstance2 Tunnel 1 Outside IP address"
value = aws_vpn_connection.ToAzureInstance1.tunnel1_address
}
output "ToAzureInstance1_Tunnel2_IP" {
description = "To AzureInstance1 Tunnel 2 Outside IP address"
value = aws_vpn_connection.ToAzureInstance1.tunnel2_address
}