github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/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-x"
     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  ```hcl
    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  * `ipv6_cidr_block` - (Optional) The Ipv6 cidr block of the desired subnet
    54  
    55  * `default_for_az` - (Optional) Boolean constraint for whether the desired
    56    subnet must be the default subnet for its associated availability zone.
    57  
    58  * `filter` - (Optional) Custom filter block as described below.
    59  
    60  * `id` - (Optional) The id of the specific subnet to retrieve.
    61  
    62  * `state` - (Optional) The state that the desired subnet must have.
    63  
    64  * `tags` - (Optional) A mapping of tags, each pair of which must exactly match
    65    a pair on the desired subnet.
    66  
    67  * `vpc_id` - (Optional) The id of the VPC that the desired subnet belongs to.
    68  
    69  More complex filters can be expressed using one or more `filter` sub-blocks,
    70  which take the following arguments:
    71  
    72  * `name` - (Required) The name of the field to filter by, as defined by
    73    [the underlying AWS API](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSubnets.html).
    74  
    75  * `values` - (Required) Set of values that are accepted for the given field.
    76    A subnet will be selected if any one of the given values matches.
    77  
    78  ## Attributes Reference
    79  
    80  All of the argument attributes except `filter` blocks are also exported as
    81  result attributes. This data source will complete the data by populating
    82  any fields that are not included in the configuration with the data for
    83  the selected subnet.