github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/website/source/docs/providers/aws/d/subnet_ids.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: aws_subnet_ids"
     4  sidebar_current: "docs-aws-datasource-subnet-ids"
     5  description: |-
     6      Provides a list of subnet Ids for a VPC
     7  ---
     8  
     9  # aws\_subnet\_ids
    10  
    11  `aws_subnet_ids` provides a list of ids for a vpc_id
    12  
    13  This resource can be useful for getting back a list of subnet ids for a vpc.
    14  
    15  ## Example Usage
    16  
    17  The following shows outputing all cidr blocks for every subnet id in a vpc.
    18  
    19  ```hcl
    20  data "aws_subnet_ids" "example" {
    21    vpc_id = "${var.vpc_id}"
    22  }
    23  
    24  data "aws_subnet" "example" {
    25    count = "${length(data.aws_subnet_ids.example.ids)}"
    26    id = "${data.aws_subnet_ids.example.ids[count.index]}"
    27  }
    28  
    29  output "subnet_cidr_blocks" {
    30    value = ["${data.aws_subnet.example.*.cidr_block}"]
    31  }
    32  ```
    33  
    34  The following example retrieves a list of all subnets in a VPC with a custom
    35  tag of `Tier` set to a value of "Private" so that the `aws_instance` resource
    36  can loop through the subnets, putting instances across availability zones.
    37  
    38  ```hcl
    39  data "aws_subnet_ids" "private" {
    40    vpc_id = "${var.vpc_id}"
    41    tags {
    42      Tier = "Private"
    43    }
    44  }
    45  
    46  resource "aws_instance" "app" {
    47    count         = "3"
    48    ami           = "${var.ami}"
    49    instance_type = "t2.micro"
    50    subnet_id     = "${element(data.aws_subnet_ids.private.ids, count.index)}"
    51  }
    52  ```
    53  
    54  ## Argument Reference
    55  
    56  * `vpc_id` - (Required) The VPC ID that you want to filter from.
    57  
    58  * `tags` - (Optional) A mapping of tags, each pair of which must exactly match
    59    a pair on the desired subnets.
    60  
    61  ## Attributes Reference
    62  
    63  * `ids` - Is a list of all the subnet ids found. If none found. This data source will fail out.