2024-12-10 15:09:03 +00:00
|
|
|
locals {
|
|
|
|
ranges = {
|
|
|
|
"low" = {
|
|
|
|
"min" = 18
|
|
|
|
"max" = 31
|
|
|
|
}
|
|
|
|
"high" = {
|
|
|
|
"min" = 128
|
|
|
|
"max" = 255
|
|
|
|
}
|
|
|
|
}
|
2024-11-26 09:50:53 +00:00
|
|
|
}
|
2024-12-10 15:09:03 +00:00
|
|
|
resource "random_integer" "subnet_ip_octet" {
|
|
|
|
for_each = local.ranges
|
|
|
|
min = local.ranges[each.key].min
|
|
|
|
max = local.ranges[each.key].max
|
2024-11-26 09:50:53 +00:00
|
|
|
}
|
2024-12-10 15:09:03 +00:00
|
|
|
|
2024-11-26 09:50:53 +00:00
|
|
|
locals {
|
|
|
|
// Generate a subnet
|
2024-12-10 15:09:03 +00:00
|
|
|
subnet = var.subnet != null ? var.subnet : "172.${random_integer.subnet_ip_octet["high"].result}.${random_integer.subnet_ip_octet["low"].result}.0/24"
|
2024-11-26 09:50:53 +00:00
|
|
|
// Calculate the gateway from the subnet
|
|
|
|
gateway = cidrhost(local.subnet, 1)
|
|
|
|
}
|