generated from equinix-labs/terraform-equinix-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
146 lines (119 loc) · 6.08 KB
/
main.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
locals {
az_resource_group_name = coalesce(var.az_resource_group_name, lower(format("rg-%s", random_string.this.result)))
az_location = var.az_create_resource_group ? azurerm_resource_group.this[0].location : data.azurerm_resource_group.this[0].location
az_exproute_location = coalesce(var.az_exproute_location, local.az_location)
az_exproute_regions = csvdecode(file("${path.module}/REGIONS.csv"))
az_exproute_peering_location = coalesce(var.az_exproute_equinix_peering_location, one([
for region in local.az_exproute_regions: region.peering_location
if region.cli_location == local.az_location
]))
az_exproute_peering_types = {
"PRIVATE" = "AzurePrivatePeering",
"MICROSOFT" = "MicrosoftPeering"
}
fabric_seller_metro_code = coalesce(var.fabric_destination_metro_code, one([
for region in local.az_exproute_regions: region.metro_code
if region.cli_location == local.az_location
]))
}
data "azurerm_resource_group" "this" {
count = var.az_create_resource_group ? 0 : 1
name = local.az_resource_group_name
}
resource "azurerm_resource_group" "this" {
count = var.az_create_resource_group ? 1 : 0
name = local.az_resource_group_name
location = var.az_region
tags = var.az_tags
}
resource "random_string" "this" {
length = 3
special = false
}
resource "azurerm_express_route_circuit" "this" {
name = coalesce(var.az_exproute_circuit_name, lower(format("xr-circuit-%s", random_string.this.result)))
resource_group_name = local.az_resource_group_name
location = local.az_location
service_provider_name = "Equinix"
peering_location = local.az_exproute_peering_location
bandwidth_in_mbps = var.fabric_speed
sku {
tier = var.az_exproute_sku.tier
family = var.az_exproute_sku.family
}
tags = var.az_tags
}
resource "azurerm_express_route_circuit_peering" "this" {
count = anytrue([var.az_exproute_configure_peering, var.network_edge_configure_bgp]) ? 1 : 0
express_route_circuit_name = azurerm_express_route_circuit.this.name
resource_group_name = local.az_resource_group_name
peering_type = lookup(local.az_exproute_peering_types, var.az_exproute_peering_type, "AzurePrivatePeering")
peer_asn = var.az_exproute_peering_customer_asn
primary_peer_address_prefix = var.az_exproute_peering_primary_address
secondary_peer_address_prefix = var.az_exproute_peering_secondary_address
vlan_id = var.az_exproute_peering_vlan_id
shared_key = var.az_exproute_peering_shared_key
dynamic "microsoft_peering_config" {
for_each = var.az_exproute_peering_type == "MICROSOFT" ? [1] : []
content {
advertised_public_prefixes = var.az_exproute_peering_msft_advertised_public_prefixes
customer_asn = var.az_exproute_peering_msft_customer_asn
routing_registry_name = var.az_exproute_peering_msft_routing_registry_name
}
}
}
module "equinix-fabric-connection" {
source = "equinix-labs/fabric-connection/equinix"
version = "0.4.0"
# required variables
notification_users = var.fabric_notification_users
# optional variables
name = var.fabric_connection_name
network_edge_id = var.network_edge_device_id
network_edge_interface_id = var.network_edge_device_interface_id
port_name = var.fabric_port_name
vlan_stag = var.fabric_vlan_stag
service_token_id = var.fabric_service_token_id
speed = var.fabric_speed
speed_unit = "MB"
purchase_order_number = var.fabric_purchase_order_number
seller_profile_name = "Azure ExpressRoute"
seller_metro_code = local.fabric_seller_metro_code
seller_authorization_key = azurerm_express_route_circuit.this.service_key
named_tag = var.az_exproute_peering_type
zside_vlan_ctag = var.az_exproute_peering_vlan_id
redundancy_type = var.redundancy_type
secondary_name = var.fabric_secondary_connection_name
secondary_port_name = var.fabric_secondary_port_name
secondary_vlan_stag = var.fabric_secondary_vlan_stag
secondary_service_token_id = var.fabric_secondary_service_token_id
network_edge_secondary_id = var.network_edge_secondary_device_id
network_edge_secondary_interface_id = var.network_edge_secondary_device_interface_id
depends_on = [
azurerm_express_route_circuit_peering.this[0]
]
}
resource "equinix_network_bgp" "primary" {
count = alltrue([var.network_edge_configure_bgp, var.network_edge_device_id != ""]) ? 1 : 0
connection_id = module.equinix-fabric-connection.primary_connection.uuid
local_ip_address = "${cidrhost(azurerm_express_route_circuit_peering.this[0].primary_peer_address_prefix, 1)}/30"
local_asn = azurerm_express_route_circuit_peering.this[0].peer_asn
remote_ip_address = cidrhost(azurerm_express_route_circuit_peering.this[0].primary_peer_address_prefix, 2)
remote_asn = azurerm_express_route_circuit_peering.this[0].azure_asn
authentication_key = var.az_exproute_peering_shared_key != "" ? var.az_exproute_peering_shared_key : null
depends_on = [
module.equinix-fabric-connection
]
}
resource "equinix_network_bgp" "secondary" {
count = alltrue([var.network_edge_configure_bgp, var.network_edge_device_id != "", var.redundancy_type == "REDUNDANT" ]) ? 1 : 0
connection_id = module.equinix-fabric-connection.secondary_connection.uuid
local_ip_address = "${cidrhost(azurerm_express_route_circuit_peering.this[0].secondary_peer_address_prefix, 1)}/30"
local_asn = azurerm_express_route_circuit_peering.this[0].peer_asn
remote_ip_address = cidrhost(azurerm_express_route_circuit_peering.this[0].secondary_peer_address_prefix, 2)
remote_asn = azurerm_express_route_circuit_peering.this[0].azure_asn
authentication_key = var.az_exproute_peering_shared_key != "" ? var.az_exproute_peering_shared_key : null
depends_on = [
module.equinix-fabric-connection
]
}