CIDR 到 IP 范围以便在不理解 CIDR 的防火墙定义中使用(如 azurerm_sql_firewall_rule)?

CIDR to IP range in order to use in a firewall definition, that does not understand CIDRs (like azurerm_sql_firewall_rule)?

我有一堆 CIDR 需要提供给 azurerm_sql_firewall_rule。不幸的是,后者需要 <start IP, end IP> 对。

有没有办法在 terraform 中做到这一点?

想通了:

locals {
  cidr = "10.12.127.0/20"
  bits = 32 - split("/", local.cidr)[1]
  x = cidrhost(local.cidr, 0)
  y = cidrhost(local.cidr, pow(2, local.bits) - 1)
}

output "x" {
    value = local.x
}

output "y" {
    value = local.y
}

运行它:

Outputs:

x = 10.12.112.0
y = 10.12.127.255