A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/terraform/cli/v1.6.x/state/resource-addressing below:

Internals: Resource Address | Terraform

A resource address is a string that identifies zero or more resource instances in your overall configuration.

An address is made up of two parts:

[module path][resource spec]

In some contexts Terraform might allow for an incomplete resource address that only refers to a module as a whole, or that omits the index for a multi-instance resource. In those cases, the meaning depends on the context, so you'll need to refer to the documentation for the specific feature you are using which parses resource addresses.

A module path addresses a module within the tree of modules. It takes the form:

module.module_name[module index]

An address without a resource spec, i.e. module.foo applies to every resource within the module if a single module, or all instances of a module if a module has multiple instances. To address all resources of a particular module instance, include the module index in the address, such as module.foo[0].

If the module path is omitted, the address applies to the root module.

An example of the module keyword delineating between two modules that have multiple instances:

module.foo[0].module.bar["a"]

Module index only applies to modules in Terraform v0.13 or later. In earlier versions of Terraform, a module could not have multiple instances.

A resource spec addresses a specific resource instance in the selected module. It has the following syntax:

resource_type.resource_name[instance index]

In Terraform v0.12 and later, a resource spec without a module path prefix matches only resources in the root module. In earlier versions, a resource spec without a module path prefix would match resources with the same type and name in any descendent module.

The following specifications apply to index values on modules and resources with multiple instances:

count Example

Given a Terraform config that includes:

resource "aws_instance" "web" {
  # ...
  count = 4
}

An address like this:

Refers to only the last instance in the config, and an address like this:

Refers to all four "web" instances.

for_each Example

Given a Terraform config that includes:

resource "aws_instance" "web" {
  # ...
  for_each = {
    "terraform": "value1",
    "resource":  "value2",
    "indexing":  "value3",
    "example":   "value4",
  }
}

An address like this:

aws_instance.web["example"]

Refers to only the "example" instance in the config, and resolves to "value4".


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4