forked from GoogleCloudPlatform/professional-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure.tf
145 lines (117 loc) · 4.77 KB
/
azure.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
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
# Azure existing virtual network and subnet
data "azurerm_virtual_network" "azure_vnet" {
name = var.azure_vnet_name
resource_group_name = var.azure_resource_group
}
data "azurerm_subnet" "azure_gw_subnet" {
name = "GatewaySubnet"
resource_group_name = var.azure_resource_group
virtual_network_name = data.azurerm_virtual_network.azure_vnet.name
}
# Azure Public IP addresses
resource "azurerm_public_ip" "azure_vpn_gateway_public_ip_1" {
name = "azure-vpn-gateway-public-ip-1"
location = var.azure_region
resource_group_name = var.azure_resource_group
allocation_method = "Static"
sku = "Standard"
zones = contains(var.azure_vpn_allowed_az_skus, var.azure_vpn_sku) ? ["1", "2", "3"] : []
}
resource "azurerm_public_ip" "azure_vpn_gateway_public_ip_2" {
name = "azure-vpn-gateway-public-ip-2"
location = var.azure_region
resource_group_name = var.azure_resource_group
allocation_method = "Static"
sku = "Standard"
zones = contains(var.azure_vpn_allowed_az_skus, var.azure_vpn_sku) ? ["1", "2", "3"] : []
}
# Azure VPN Gateway and connections
resource "azurerm_virtual_network_gateway" "azure_vpn_gateway" {
name = "azure-vpn-gateway"
location = var.azure_region
resource_group_name = var.azure_resource_group
type = "Vpn"
vpn_type = "RouteBased"
active_active = true
enable_bgp = true
sku = var.azure_vpn_sku
ip_configuration {
name = "vnetGatewayConfig1"
private_ip_address_allocation = "Dynamic"
subnet_id = data.azurerm_subnet.azure_gw_subnet.id
public_ip_address_id = azurerm_public_ip.azure_vpn_gateway_public_ip_1.id
}
ip_configuration {
name = "vnetGatewayConfig2"
private_ip_address_allocation = "Dynamic"
subnet_id = data.azurerm_subnet.azure_gw_subnet.id
public_ip_address_id = azurerm_public_ip.azure_vpn_gateway_public_ip_2.id
}
bgp_settings {
asn = var.azure_bgp_asn
peer_weight = 100
peering_addresses {
ip_configuration_name = "vnetGatewayConfig1"
apipa_addresses = ["169.254.21.1"]
}
peering_addresses {
ip_configuration_name = "vnetGatewayConfig2"
apipa_addresses = ["169.254.22.1"]
}
}
}
resource "azurerm_local_network_gateway" "gcp_gw1" {
name = "gcp-local-network-gateway-1"
location = var.azure_region
resource_group_name = var.azure_resource_group
gateway_address = google_compute_ha_vpn_gateway.target_gateway.vpn_interfaces[0].ip_address
bgp_settings {
asn = var.gcp_bgp_asn
bgp_peering_address = google_compute_router_peer.router1_peer1.ip_address
}
}
resource "azurerm_local_network_gateway" "gcp_gw2" {
name = "gcp-local-network-gateway-2"
location = var.azure_region
resource_group_name = var.azure_resource_group
gateway_address = google_compute_ha_vpn_gateway.target_gateway.vpn_interfaces[1].ip_address
bgp_settings {
asn = var.gcp_bgp_asn
bgp_peering_address = google_compute_router_peer.router1_peer2.ip_address
}
}
resource "azurerm_virtual_network_gateway_connection" "vpn_connection1" {
name = "azure-to-gcp-vpn-connection-1"
location = var.azure_region
resource_group_name = var.azure_resource_group
type = "IPsec"
virtual_network_gateway_id = azurerm_virtual_network_gateway.azure_vpn_gateway.id
local_network_gateway_id = azurerm_local_network_gateway.gcp_gw1.id
shared_key = var.shared_secret
enable_bgp = true
}
resource "azurerm_virtual_network_gateway_connection" "vpn_connection2" {
name = "azure-to-gcp-vpn-connection-2"
location = var.azure_region
resource_group_name = var.azure_resource_group
type = "IPsec"
virtual_network_gateway_id = azurerm_virtual_network_gateway.azure_vpn_gateway.id
local_network_gateway_id = azurerm_local_network_gateway.gcp_gw2.id
shared_key = var.shared_secret
enable_bgp = true
}