Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@magickatt
Last active March 18, 2019 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magickatt/b130df92bd66c54cc9aeb2539ac8fca2 to your computer and use it in GitHub Desktop.
Save magickatt/b130df92bd66c54cc9aeb2539ac8fca2 to your computer and use it in GitHub Desktop.
How to retrieve CIDR ranges
# Fetch the VPC as a Data Source
data "aws_vpc" "vpc" {
filter {
name = "tag:Name"
values = ["vpc-name"]
}
}
# Fetch the Subnet IDs from the VPC
data "aws_subnet_ids" "public" {
vpc_id = "${data.aws_vpc.vpc.id}"
tags = {
another-arbitrary-tag = "public"
}
}
# Fetch the Subnets themselves using their IDs
data "aws_subnet" "public" {
count = "${length(data.aws_subnet_ids.public.ids)}"
id = "${data.aws_subnet_ids.public.ids[count.index]}"
}
# Output the values from the Subnets as necessary
output "public_subnet_cidr_blocks" {
value = ["${data.aws_subnet.public.*.cidr_block}"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment