I’m working to create a mesh of Azure VNets using VNet Peering, meaning every VNet needs to be peered to every other VNet, but not to itself.
I thought I could take a set of VNets and “setproduct” it against itself, like this:
locals {
vnets = ["vnet-1", "vnet-2", "vnet-3"]
vnet_peers = setproduct(local.vnets, local.vnets)
}
Unfortunately (and as I’d expect from setproduct) the result includes sets where both items are the same, as seen below:
local.vnet_peers
[
[
"vnet-1",
"vnet-1",
],
[
"vnet-1",
"vnet-2",
],
[
"vnet-1",
"vnet-3",
],
[
"vnet-2",
"vnet-1",
],
[
"vnet-2",
"vnet-2",
],
[
"vnet-2",
"vnet-3",
],
[
"vnet-3",
"vnet-1",
],
[
"vnet-3",
"vnet-2",
],
[
"vnet-3",
"vnet-3",
],
]
My goal here is to get a result that doesn’t include sets where both items are the same. I need a result that doesn’t include items like the following:
BAD - I need a result without sets like this where both items are the same:
[
"vnet-1",
"vnet-1",
]
GOOD - Both are different:
[
"vnet-1",
"vnet-2",
]
Any suggestions?