github.com/loicalbertin/terraform@v0.6.15-0.20170626182346-8e2583055467/website/docs/internals/resource-addressing.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Internals: Resource Address"
     4  sidebar_current: "docs-internals-resource-addressing"
     5  description: |-
     6    Resource addressing is used to target specific resources in a larger
     7    infrastructure.
     8  ---
     9  
    10  # Resource Addressing
    11  
    12  A __Resource Address__ is a string that references a specific resource in a
    13  larger infrastructure. An address is made up of two parts:
    14  
    15  ```
    16  [module path][resource spec]
    17  ```
    18  
    19  __Module path__:
    20  
    21  A module path addresses a module within the tree of modules. It takes the form:
    22  
    23  ```
    24  module.A.module.B.module.C...
    25  ```
    26  
    27  Multiple modules in a path indicate nesting. If a module path is specified
    28  without a resource spec, the address applies to every resource within the
    29  module. If the module path is omitted, this addresses the root module.
    30  
    31  __Resource spec__:
    32  
    33  A resource spec addresses a specific resource in the config. It takes the form:
    34  
    35  ```
    36  resource_type.resource_name[N]
    37  ```
    38  
    39   * `resource_type` - Type of the resource being addressed.
    40   * `resource_name` - User-defined name of the resource.
    41   * `[N]` - where `N` is a `0`-based index into a resource with multiple
    42     instances specified by the `count` meta-parameter. Omitting an index when
    43     addressing a resource where `count > 1` means that the address references
    44     all instances.
    45  
    46  
    47  ## Examples
    48  
    49  Given a Terraform config that includes:
    50  
    51  ```hcl
    52  resource "aws_instance" "web" {
    53    # ...
    54    count = 4
    55  }
    56  ```
    57  
    58  An address like this:
    59  
    60  ```
    61  aws_instance.web[3]
    62  ```
    63  
    64  Refers to only the last instance in the config, and an address like this:
    65  
    66  ```
    67  aws_instance.web
    68  ```
    69  
    70  Refers to all four "web" instances.