title: Terraform: How to get the VPC CIDR from VPC id?
body: <p>I'm trying to source the <strong>PIV4_CIDR</strong> for a given VPC, using the aws_vpcs data-source to identify the VPC first and get the CIDR from ID - is it possible?</p>
  
  <p>Just a bit of background, for some design reason, we have services in different VPC. Say, eg. I have three VPCs: <code>xxxprod-n</code>, <code>xxxprod-l</code> and <code>xxxprod-h</code> and I want to add a SG rule for the entire subnet to allow access to a specific port. This is what I tried:</p>
  
  <pre><code>data "aws_vpcs" "prod" {
    tags = {
      Name = "${var.project}prd-*"
    }
  }
  
  resource "aws_security_group_rule" "pa-allow" {
    count             = length(data.aws_vpcs.prod.ids)
    type              = "ingress"
    from_port         = 8140
    to_port           = 8140
    protocol          = "tcp"
    cidr_blocks       = [sort(data.aws_vpcs.prod.ids)[count.index].cidr_block]
    security_group_id = aws_security_group.secg.id
    description       = "allow from ${sort(data.aws_vpcs.prod.ids)[count.index]}"
  }
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>Error: Unsupported attribute</p>
    
    <p>on ../../modules/mgt/ec2.tf line 42, in resource
    "aws_security_group_rule" "pa-allow":   42:   cidr_blocks       =
    [sort(data.aws_vpcs.prod.ids)[count.index].cidr_block]</p>
    
    <p>This value does not have any attributes.</p>
  </blockquote>
  
  <p>I tried that, based on this page: <code>https://www.terraform.io/docs/providers/aws/d/vpc.html</code>, thinking <em>aws_vpc</em> and <em>aws_vpcs</em> will do similar sort of thing but it seem doesn't. Any idea how do I do that?</p>