-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc_peering.tf
executable file
·34 lines (33 loc) · 1.76 KB
/
vpc_peering.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
locals {
_peerings = flatten([for vpc_network in local.vpc_networks :
[for i, v in coalesce(vpc_network.peerings, []) :
merge(v, {
create = coalesce(v.create, true)
project_id = coalesce(v.project_id, vpc_network.project_id, var.project_id)
name = coalesce(v.name, "peering-${i}")
peer_project_id = coalesce(v.peer_project_id, v.project_id, vpc_network.project_id, var.project_id)
peer_network_name = coalesce(v.peer_network_name, "default")
network_name = vpc_network.name
})
]
])
peerings = [for i, v in local._peerings :
merge(v, {
# If peer network link not provided, we can generate it using their project ID and network name
network = "projects/${v.project_id}/global/networks/${v.network_name}"
peer_network = coalesce(v.peer_network_link, "projects/${v.peer_project_id}/global/networks/${v.peer_network_name}")
index_key = "${v.project_id}/${v.network_name}/${v.name}"
}) if v.create == true
]
}
resource "google_compute_network_peering" "default" {
for_each = { for k, v in local.peerings : v.index_key => v }
name = each.value.name
network = each.value.network
peer_network = each.value.peer_network
import_custom_routes = each.value.import_custom_routes
export_custom_routes = each.value.export_custom_routes
import_subnet_routes_with_public_ip = each.value.import_subnet_routes_with_public_ip
export_subnet_routes_with_public_ip = each.value.export_subnet_routes_with_public_ip
depends_on = [google_compute_network.default]
}