Last active
March 18, 2019 19:24
-
-
Save magickatt/b130df92bd66c54cc9aeb2539ac8fca2 to your computer and use it in GitHub Desktop.
How to retrieve CIDR ranges
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
# 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