Skip to content

Instantly share code, notes, and snippets.

@thepatrick
Last active July 7, 2020 11:00
Show Gist options
  • Save thepatrick/7e7939f78939271653cd4e0a25cd3f16 to your computer and use it in GitHub Desktop.
Save thepatrick/7e7939f78939271653cd4e0a25cd3f16 to your computer and use it in GitHub Desktop.
cidrsubnet magic
module "anvil" {
source = "./subnets"
cidr_block = "10.192.12.0/22"
subnet_mask = 24
}
output "size" {
value = "${module.anvil.size}"
}
output "subnets" {
value = "${module.anvil.subnets}"
}
variable "cidr_block" {
}
variable "subnet_mask" {
default = 24
}
locals {
child_subnet_mask = "${var.subnet_mask - (element(split("/", var.cidr_block), 1))}"
}
output "size" {
value = "${local.child_subnet_mask}"
}
output "subnets" {
value = "${list(
cidrsubnet(var.cidr_block, local.child_subnet_mask, 0),
cidrsubnet(var.cidr_block, local.child_subnet_mask, 1),
cidrsubnet(var.cidr_block, local.child_subnet_mask, 2)
)}"
}
@vadirajks
Copy link

change "module.anvil.anvil_subnet" to "module.anvil.subnets". Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment