# Retrieving subnet cidr from multiple vpcs

**URL:** <https://discuss.hashicorp.com/t/retrieving-subnet-cidr-from-multiple-vpcs/6259>\
**Category:** AWS\
**Created:** [February 25, 2020, 8:52am UTC](https://discuss.hashicorp.com/t/retrieving-subnet-cidr-from-multiple-vpcs/6259 "2020-02-25T08:52:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![noelmcgrath](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/noelmcgrath/32/4904_2.png) [@noelmcgrath](https://discuss.hashicorp.com/u/noelmcgrath)\
**Post date:** [February 25, 2020, 8:52am UTC](https://discuss.hashicorp.com/t/retrieving-subnet-cidr-from-multiple-vpcs/6259/1 "2020-02-25T08:52:30Z")

</div>

We have multiple VPC’s that connect to another shared VPC via peering.  
E.g. our Dev and QA VPCs share the DB VPC  
We need to create a security group rule where we specify the cidr\_blocks of the private subnets for each VPC(dev, qa).  
We could use data sources to retrieve this information but would be repeating this for each VPC e.g.

data aws\_vpc dev {  
filter {  
name = “name”  
values = [“dev”]  
}  
}

data aws\_subnet\_ids dev {  
vpc\_id = aws\_vpc.dev.vpc\_id

tags = {  
Tier = “private”  
}  
}

data aws\_subnet dev {  
for\_each = data.aws\_subnet\_ids.dev.ids  
id = each.value  
}

Is there a better way to do this?
