-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
39 lines (32 loc) · 2.04 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
data "azurerm_virtual_network" "vnet_1" {
for_each = { for i, p in var.peerings : i => p }
name = each.value.source.vnet_name
resource_group_name = each.value.source.resource_group_name
}
data "azurerm_virtual_network" "vnet_2" {
for_each = { for i, p in var.peerings : i => p }
name = each.value.destination.vnet_name
resource_group_name = each.value.destination.resource_group_name
}
resource "azurerm_virtual_network_peering" "vnet_peering_1" {
for_each = { for i, p in var.peerings : i => p }
name = format("peer-%s-%s", each.value.source.vnet_name, each.value.destination.vnet_name)
resource_group_name = each.value.source.resource_group_name
virtual_network_name = each.value.source.vnet_name
remote_virtual_network_id = data.azurerm_virtual_network.vnet_2[each.key].id
allow_virtual_network_access = lookup(each.value.source, "allow_virtual_network_access", null)
allow_forwarded_traffic = lookup(each.value.source, "allow_forwarded_traffic", null)
allow_gateway_transit = lookup(each.value.source, "allow_gateway_transit", null)
use_remote_gateways = lookup(each.value.source, "use_remote_gateways", null)
}
resource "azurerm_virtual_network_peering" "vnet_peering_2" {
for_each = { for i, p in var.peerings : i => p }
name = format("peer-%s-%s", each.value.destination.vnet_name, each.value.source.vnet_name)
resource_group_name = each.value.destination.resource_group_name
virtual_network_name = each.value.destination.vnet_name
remote_virtual_network_id = data.azurerm_virtual_network.vnet_1[each.key].id
allow_virtual_network_access = lookup(each.value.destination, "allow_virtual_network_access", null)
allow_forwarded_traffic = lookup(each.value.destination, "allow_forwarded_traffic", null)
allow_gateway_transit = lookup(each.value.destination, "allow_gateway_transit", null)
use_remote_gateways = lookup(each.value.destination, "use_remote_gateways", null)
}