Add router BGP peers

This commit is contained in:
Julio Diez 2023-03-06 18:02:50 +01:00
parent 02707eb275
commit e835730665
1 changed files with 42 additions and 0 deletions

View File

@ -14,6 +14,20 @@
* limitations under the License.
*/
locals {
spoke_vms = flatten([
for spoke_key, spoke in var.spokes : [
for nva in spoke.nvas : {
ip = nva.ip
vm = nva.vm
vm_name = element(split("/", nva.vm), length(split("/", nva.vm)) - 1)
spoke_key = spoke_key
spoke = spoke
}
]
])
}
resource "google_network_connectivity_hub" "ncc-hub" {
project = var.project_id
name = var.name
@ -84,3 +98,31 @@ resource "google_compute_router_interface" "ncc-cr-if2" {
private_ip_address = each.value.router.ip2
redundant_interface = google_compute_router_interface.ncc-cr-if1[each.key].name
}
resource "google_compute_router_peer" "ncc-cr-peer1" {
for_each = {
for entry in local.spoke_vms : entry.ip => entry
}
project = var.project_id
name = "peer1-${each.value.vm_name}"
router = google_compute_router.ncc-cr[each.value.spoke_key].name
region = each.value.spoke.region
interface = google_compute_router_interface.ncc-cr-if1[each.value.spoke_key].name
peer_asn = each.value.spoke.router.peer_asn
peer_ip_address = each.key
router_appliance_instance = each.value.vm
}
resource "google_compute_router_peer" "ncc-cr-peer2" {
for_each = {
for entry in local.spoke_vms : entry.ip => entry
}
project = var.project_id
name = "peer2-${each.value.vm_name}"
router = google_compute_router.ncc-cr[each.value.spoke_key].name
region = each.value.spoke.region
interface = google_compute_router_interface.ncc-cr-if2[each.value.spoke_key].name
peer_asn = each.value.spoke.router.peer_asn
peer_ip_address = each.key
router_appliance_instance = each.value.vm
}