Skip to content

Instantly share code, notes, and snippets.

@gswallow
Created August 7, 2020 18:47
Show Gist options
  • Save gswallow/8465d78a54899e1084240d4c4763c449 to your computer and use it in GitHub Desktop.
Save gswallow/8465d78a54899e1084240d4c4763c449 to your computer and use it in GitHub Desktop.
VPC locals for terraform
locals {
vpc_name = lower(format("%s-%s-%s", var.org, var.env, replace(replace(var.cidr_block, ".", "_"), "/", "-")))
az_names = length(data.aws_availability_zones.available.names) < var.subnet_count ? data.aws_availability_zones.available.names : slice(data.aws_availability_zones.available.names, 0, var.subnet_count)
public_subnet_cidrs = [
for i in range(length(local.az_names)):
cidrsubnet(var.cidr_block, var.subnet_cidr_mask - split("/", var.cidr_block)[1], i)
]
private_subnet_cidrs = [
for i in range(length(local.az_names), length(local.az_names) + length(local.az_names)):
cidrsubnet(var.cidr_block, var.subnet_cidr_mask - split("/", var.cidr_block)[1], i)
]
tags = merge({
Environment = var.env
Organization = var.org
}, var.tags)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment