github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/aws/d/subnet.html.markdown (about)

     1  ---
     2  layout: "aws"
     3  page_title: "AWS: aws_subnet"
     4  sidebar_current: "docs-aws-datasource-subnet"
     5  description: |-
     6      Provides details about a specific VPC subnet
     7  ---
     8  
     9  # aws\_subnet
    10  
    11  `aws_subnet` provides details about a specific VPC subnet.
    12  
    13  This resource can prove useful when a module accepts a subnet id as
    14  an input variable and needs to, for example, determine the id of the
    15  VPC that the subnet belongs to.
    16  
    17  ## Example Usage
    18  
    19  The following example shows how one might accept a subnet id as a variable
    20  and use this data source to obtain the data necessary to create a security
    21  group that allows connections from hosts in that subnet.
    22  
    23  ```
    24  variable "subnet_id" {}
    25  
    26  data "aws_subnet" "selected" {
    27    id = "${var.subnet_id}"
    28  }
    29  
    30  resource "aws_security_group" "subnet" {
    31    vpc_id = "${data.aws_subnet.selected.vpc_id}"
    32  
    33    ingress {
    34      cidr_blocks = ["${data.aws_subnet.selected.cidr_block}"]
    35      from_port   = 80
    36      to_port     = 80
    37      protocol    = "tcp"
    38    }
    39  }
    40  ```
    41  
    42  ## Argument Reference
    43  
    44  The arguments of this data source act as filters for querying the available
    45  subnets in the current region. The given filters must match exactly one
    46  subnet whose data will be exported as attributes.
    47  
    48  * `availability_zone` - (Optional) The availability zone where the
    49    subnet must reside.
    50  
    51  * `cidr_block` - (Optional) The cidr block of the desired subnet.
    52  
    53  * `default_for_az` - (Optional) Boolean constraint for whether the desired
    54    subnet must be the default subnet for its associated availability zone.
    55  
    56  * `filter` - (Optional) Custom filter block as described below.
    57  
    58  * `id` - (Optional) The id of the specific subnet to retrieve.
    59  
    60  * `state` - (Optional) The state that the desired subnet must have.
    61  
    62  * `tags` - (Optional) A mapping of tags, each pair of which must exactly match
    63    a pair on the desired subnet.
    64  
    65  * `vpc_id` - (Optional) The id of the VPC that the desired subnet belongs to.
    66  
    67  More complex filters can be expressed using one or more `filter` sub-blocks,
    68  which take the following arguments:
    69  
    70  * `name` - (Required) The name of the field to filter by, as defined by
    71    [the underlying AWS API](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSubnets.html).
    72  
    73  * `values` - (Required) Set of values that are accepted for the given field.
    74    A subnet will be selected if any one of the given values matches.
    75  
    76  ## Attributes Reference
    77  
    78  All of the argument attributes except `filter` blocks are also exported as
    79  result attributes. This data source will complete the data by populating
    80  any fields that are not included in the configuration with the data for
    81  the selected subnet.