Last active
July 7, 2020 11:00
-
-
Save thepatrick/7e7939f78939271653cd4e0a25cd3f16 to your computer and use it in GitHub Desktop.
cidrsubnet magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
)}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change "module.anvil.anvil_subnet" to "module.anvil.subnets". Thanks