-
Notifications
You must be signed in to change notification settings - Fork 0
/
09-conn-branch3.tf
143 lines (127 loc) · 4.41 KB
/
09-conn-branch3.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
####################################################
# branch3
####################################################
# router
locals {
branch3_nva_route_map_name_nh = "NEXT-HOP"
branch3_nva_init = templatefile("../../scripts/cisco-branch.sh", {
LOCAL_ASN = local.branch3_nva_asn
LOOPBACK0 = local.branch3_nva_loopback0
LOOPBACKS = {}
EXT_ADDR = local.branch3_nva_ext_addr
VPN_PSK = local.psk
ROUTE_MAPS = [
{
name = local.branch3_nva_route_map_name_nh
action = "permit"
rule = 100
commands = [
"match ip address prefix-list all",
"set as-path prepend ${local.branch3_nva_asn} ${local.branch3_nva_asn} ${local.branch3_nva_asn}"
]
}
]
TUNNELS = [
{
ike = {
name = "Tunnel0"
address = cidrhost(local.branch3_nva_tun_range0, 1)
mask = cidrnetmask(local.branch3_nva_tun_range0)
source = local.branch3_nva_ext_addr
dest = local.vhub2_vpngw_public_ip0
},
ipsec = {
peer_ip = local.vhub2_vpngw_public_ip0
psk = local.psk
}
},
{
ike = {
name = "Tunnel1"
address = cidrhost(local.branch3_nva_tun_range1, 1)
mask = cidrnetmask(local.branch3_nva_tun_range1)
source = local.branch3_nva_ext_addr
dest = local.vhub2_vpngw_public_ip1
},
ipsec = {
peer_ip = local.vhub2_vpngw_public_ip1
psk = local.psk
}
},
]
STATIC_ROUTES = [
{ network = "0.0.0.0", mask = "0.0.0.0", next_hop = local.branch3_ext_default_gw },
{ network = local.vhub2_vpngw_bgp_ip0, mask = "255.255.255.255", next_hop = "Tunnel0" },
{ network = local.vhub2_vpngw_bgp_ip1, mask = "255.255.255.255", next_hop = "Tunnel1" },
{
network = cidrhost(local.branch3_subnets["${local.branch3_prefix}main"].address_prefixes[0], 0)
mask = cidrnetmask(local.branch3_subnets["${local.branch3_prefix}main"].address_prefixes[0])
next_hop = local.branch3_int_default_gw
},
]
BGP_SESSIONS = [
{
peer_asn = local.vhub2_bgp_asn,
peer_ip = local.vhub2_vpngw_bgp_ip0,
source_loopback = true
ebgp_multihop = true
route_map = {}
},
{
peer_asn = local.vhub2_bgp_asn
peer_ip = local.vhub2_vpngw_bgp_ip1
source_loopback = true
ebgp_multihop = true
route_map = {}
},
]
BGP_ADVERTISED_NETWORKS = [
{
network = cidrhost(local.branch3_subnets["${local.branch3_prefix}main"].address_prefixes[0], 0)
mask = cidrnetmask(local.branch3_subnets["${local.branch3_prefix}main"].address_prefixes[0])
},
]
})
}
# vm
module "branch3_nva" {
source = "../../modules/csr-branch"
resource_group = azurerm_resource_group.rg.name
name = "${local.branch3_prefix}nva"
location = local.branch3_location
enable_ip_forwarding = true
enable_public_ip = true
subnet_ext = module.branch3.subnets["${local.branch3_prefix}ext"].id
subnet_int = module.branch3.subnets["${local.branch3_prefix}int"].id
private_ip_ext = local.branch3_nva_ext_addr
private_ip_int = local.branch3_nva_int_addr
public_ip = azurerm_public_ip.branch3_nva_pip.id
storage_account = module.common.storage_accounts["region2"]
admin_username = local.username
admin_password = local.password
custom_data = base64encode(local.branch3_nva_init)
}
# udr
module "branch3_udr_main" {
source = "../../modules/udr"
resource_group = azurerm_resource_group.rg.name
prefix = "${local.branch3_prefix}-main"
location = local.branch3_location
subnet_id = module.branch3.subnets["${local.branch3_prefix}main"].id
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = local.branch3_nva_int_addr
destinations = ["10.0.0.0/8"]
}
####################################################
# output files
####################################################
locals {
branch3_files = {
"output/branch3-nva.sh" = local.branch3_nva_init
}
}
resource "local_file" "branch3_files" {
for_each = local.branch3_files
filename = each.key
content = each.value
}