github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/resources.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Resources - Configuration Language"
     4  sidebar_current: "docs-config-resources"
     5  description: |-
     6    Resources are the most important element in a Terraform configuration.
     7    Each resource corresponds to an infrastructure object, such as a virtual
     8    network or compute instance.
     9  ---
    10  
    11  # Resources
    12  
    13  -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
    14  earlier, see
    15  [0.11 Configuration Language: Resources](../configuration-0-11/resources.html).
    16  
    17  _Resources_ are the most important element in the Terraform language.
    18  Each resource block describes one or more infrastructure objects, such
    19  as virtual networks, compute instances, or higher-level components such
    20  as DNS records.
    21  
    22  ## Resource Syntax
    23  
    24  Resource declarations can include a number of advanced features, but only
    25  a small subset are required for initial use. More advanced syntax features,
    26  such as single resource declarations that produce multiple similar remote
    27  objects, are described later in this page.
    28  
    29  ```hcl
    30  resource "aws_instance" "web" {
    31    ami           = "ami-a1b2c3d4"
    32    instance_type = "t2.micro"
    33  }
    34  ```
    35  
    36  A `resource` block declares a resource of a given type ("aws_instance")
    37  with a given local name ("web"). The name is used to refer to this resource
    38  from elsewhere in the same Terraform module, but has no significance outside
    39  of the scope of a module.
    40  
    41  The resource type and name together serve as an identifier for a given
    42  resource and so must be unique within a module.
    43  
    44  Within the block body (between `{` and `}`) are the configuration arguments
    45  for the resource itself. Most arguments in this section depend on the
    46  resource type, and indeed in this example both `ami` and `instance_type` are
    47  arguments defined specifically for [the `aws_instance` resource type](/docs/providers/aws/r/instance.html).
    48  
    49  -> **Note:** Resource names must start with a letter or underscore, and may
    50  contain only letters, digits, underscores, and dashes.
    51  
    52  ## Resource Types and Arguments
    53  
    54  Each resource is associated with a single _resource type_, which determines
    55  the kind of infrastructure object it manages and what arguments and other
    56  attributes the resource supports.
    57  
    58  Each resource type in turn belongs to a [provider](./providers.html),
    59  which is a plugin for Terraform that offers a collection of resource types. A
    60  provider usually provides resources to manage a single cloud or on-premises
    61  infrastructure platform.
    62  
    63  Most of the items within the body of a `resource` block are specific to the
    64  selected resource type. These arguments can make full use of
    65  [expressions](./expressions.html) and other dynamic Terraform
    66  language features.
    67  
    68  There are also some _meta-arguments_ that are defined by Terraform itself
    69  and apply across all resource types. (See [Meta-Arguments](#meta-arguments) below.)
    70  
    71  ### Documentation for Resource Types
    72  
    73  [Terraform's provider documentation][providers] is the primary place to
    74  learn which resource types are available and which arguments to use for each
    75  resource type. Once you understand Terraform's basic syntax, the provider
    76  documentation will be where you spend the majority of your time on this website.
    77  
    78  The "[Providers][]" link at the top level of the navigation sidebar will take
    79  you to an alphabetical list of all of the providers distributed by HashiCorp.
    80  You can find a specific provider in this master list, or choose a category from
    81  the navigation sidebar to browse a more focused list of providers.
    82  
    83  You can also search GitHub or other sources for third-party providers, which can
    84  be installed as plugins to enable an even broader selection of resource types.
    85  
    86  [providers]: /docs/providers/index.html
    87  
    88  ## Resource Behavior
    89  
    90  A `resource` block describes your intent for a particular infrastructure object
    91  to exist with the given settings. If you are writing a new configuration for
    92  the first time, the resources it defines will exist _only_ in the configuration,
    93  and will not yet represent real infrastructure objects in the target platform.
    94  
    95  _Applying_ a Terraform configuration is the process of creating, updating,
    96  and destroying real infrastructure objects in order to make their settings
    97  match the configuration.
    98  
    99  When Terraform creates a new infrastructure object represented by a `resource`
   100  block, the identifier for that real object is saved in Terraform's
   101  [state](/docs/state/index.html), allowing it to be updated and destroyed
   102  in response to future changes. For resource blocks that already have an
   103  associated infrastructure object in the state, Terraform compares the
   104  actual configuration of the object with the arguments given in the
   105  configuration and, if necessary, updates the object to match the configuration.
   106  
   107  This general behavior applies for all resources, regardless of type. The
   108  details of what it means to create, update, or destroy a resource are different
   109  for each resource type, but this standard set of verbs is common across them
   110  all.
   111  
   112  The meta-arguments within `resource` blocks, documented in the
   113  sections below, allow some details of this standard resource behavior to be
   114  customized on a per-resource basis.
   115  
   116  ### Resource Dependencies
   117  
   118  Most resources in a configuration don't have any particular relationship, and
   119  Terraform can make changes to several unrelated resources in parallel.
   120  
   121  However, some resources must be processed after other specific resources;
   122  sometimes this is because of how the resource works, and sometimes the
   123  resource's configuration just requires information generated by another
   124  resource.
   125  
   126  Most resource dependencies are handled automatically. Terraform analyses any
   127  [expressions](./expressions.html) within a `resource` block to find references
   128  to other objects, and treats those references as implicit ordering requirements
   129  when creating, updating, or destroying resources. Since most resources with
   130  behavioral dependencies on other resources also refer to those resources' data,
   131  it's usually not necessary to manually specify dependencies between resources.
   132  
   133  However, some dependencies cannot be recognized implicitly in configuration. For
   134  example, if Terraform must manage access control policies _and_ take actions
   135  that require those policies to be present, there is a hidden dependency between
   136  the access policy and a resource whose creation depends on it. In these rare
   137  cases, [the `depends_on` meta-argument][inpage-depend] can explicitly specify a
   138  dependency.
   139  
   140  ## Meta-Arguments
   141  
   142  Terraform CLI defines the following meta-arguments, which can be used with
   143  any resource type to change the behavior of resources:
   144  
   145  - [`depends_on`, for specifying hidden dependencies][inpage-depend]
   146  - [`count`, for creating multiple resource instances according to a count][inpage-count]
   147  - [`for_each`, to create multiple instances according to a map, or set of strings][inpage-for_each]
   148  - [`provider`, for selecting a non-default provider configuration][inpage-provider]
   149  - [`lifecycle`, for lifecycle customizations][inpage-lifecycle]
   150  - [`provisioner` and `connection`, for taking extra actions after resource creation][inpage-provisioner]
   151  
   152  These arguments often have additional restrictions on what language features can
   153  be used with them, which are described in each
   154  
   155  ### `depends_on`: Explicit Resource Dependencies
   156  
   157  [inpage-depend]: #depends_on-explicit-resource-dependencies
   158  
   159  Use the `depends_on` meta-argument to handle hidden resource dependencies that
   160  Terraform can't automatically infer.
   161  
   162  Explicitly specifying a dependency is only necessary when a resource relies on
   163  some other resource's behavior but _doesn't_ access any of that resource's data
   164  in its arguments.
   165  
   166  This argument is available in all `resource` blocks, regardless of resource
   167  type. For example:
   168  
   169  ```hcl
   170  resource "aws_iam_role" "example" {
   171    name = "example"
   172  
   173    # assume_role_policy is omitted for brevity in this example. See the
   174    # documentation for aws_iam_role for a complete example.
   175    assume_role_policy = "..."
   176  }
   177  
   178  resource "aws_iam_instance_profile" "example" {
   179    # Because this expression refers to the role, Terraform can infer
   180    # automatically that the role must be created first.
   181    role = aws_iam_role.example.name
   182  }
   183  
   184  resource "aws_iam_role_policy" "example" {
   185    name   = "example"
   186    role   = aws_iam_role.example.name
   187    policy = jsonencode({
   188      "Statement" = [{
   189        # This policy allows software running on the EC2 instance to
   190        # access the S3 API.
   191        "Action" = "s3:*",
   192        "Effect" = "Allow",
   193      }],
   194    })
   195  }
   196  
   197  resource "aws_instance" "example" {
   198    ami           = "ami-a1b2c3d4"
   199    instance_type = "t2.micro"
   200  
   201    # Terraform can infer from this that the instance profile must
   202    # be created before the EC2 instance.
   203    iam_instance_profile = aws_iam_instance_profile.example
   204  
   205    # However, if software running in this EC2 instance needs access
   206    # to the S3 API in order to boot properly, there is also a "hidden"
   207    # dependency on the aws_iam_role_policy that Terraform cannot
   208    # automatically infer, so it must be declared explicitly:
   209    depends_on = [
   210      aws_iam_role_policy.example,
   211    ]
   212  }
   213  ```
   214  
   215  The `depends_on` meta-argument, if present, must be a list of references
   216  to other resources in the same module. Arbitrary expressions are not allowed
   217  in the `depends_on` argument value, because its value must be known before
   218  Terraform knows resource relationships and thus before it can safely
   219  evaluate expressions.
   220  
   221  The `depends_on` argument should be used only as a last resort. When using it,
   222  always include a comment explaining why it is being used, to help future
   223  maintainers understand the purpose of the additional dependency.
   224  
   225  ### `count`: Multiple Resource Instances By Count
   226  
   227  [inpage-count]: #count-multiple-resource-instances-by-count
   228  
   229  -> **Note:** A given resource block cannot use both `count` and `for_each`.
   230  
   231  By default, a `resource` block configures one real infrastructure object.
   232  However, sometimes you want to manage several similar objects, such as a fixed
   233  pool of compute instances. Terraform has two ways to do this:
   234  `count` and [`for_each`][inpage-for_each].
   235  
   236  The `count` meta-argument accepts a whole number, and creates that many
   237  instances of the resource. Each instance has a distinct infrastructure object
   238  associated with it (as described above in
   239  [Resource Behavior](#resource-behavior)), and each is separately created,
   240  updated, or destroyed when the configuration is applied.
   241  
   242  ```hcl
   243  resource "aws_instance" "server" {
   244    count = 4 # create four similar EC2 instances
   245  
   246    ami           = "ami-a1b2c3d4"
   247    instance_type = "t2.micro"
   248  
   249    tags = {
   250      Name = "Server ${count.index}"
   251    }
   252  }
   253  ```
   254  
   255  #### The `count` Object
   256  
   257  In resource blocks where `count` is set, an additional `count` object is
   258  available in expressions, so you can modify the configuration of each instance.
   259  This object has one attribute:
   260  
   261  - `count.index` — The distinct index number (starting with `0`) corresponding
   262    to this instance.
   263  
   264  #### Referring to Instances
   265  
   266  When `count` is set, Terraform distinguishes between the resource block itself
   267  and the multiple _resource instances_ associated with it. Instances are
   268  identified by an index number, starting with `0`.
   269  
   270  - `<TYPE>.<NAME>` (for example, `aws_instance.server`) refers to the resource block.
   271  - `<TYPE>.<NAME>[<INDEX>]` (for example, `aws_instance.server[0]`,
   272    `aws_instance.server[1]`, etc.) refers to individual instances.
   273  
   274  This is different from resources without `count` or `for_each`, which can be
   275  referenced without an index or key.
   276  
   277  -> **Note:** Within nested `provisioner` or `connection` blocks, the special
   278  `self` object refers to the current _resource instance,_ not the resource block
   279  as a whole.
   280  
   281  #### Using Expressions in `count`
   282  
   283  The `count` meta-argument accepts numeric [expressions](./expressions.html).
   284  However, unlike most resource arguments, the `count` value must be known
   285  _before_ Terraform performs any remote resource actions. This means `count`
   286  can't refer to any resource attributes that aren't known until after a
   287  configuration is applied (such as a unique ID generated by the remote API when
   288  an object is created).
   289  
   290  #### When to Use `for_each` Instead of `count`
   291  
   292  If your resource instances are almost identical, `count` is appropriate. If some
   293  of their arguments need distinct values that can't be directly derived from an
   294  integer, it's safer to use `for_each`.
   295  
   296  Before `for_each` was available, it was common to derive `count` from the
   297  length of a list and use `count.index` to look up the original list value:
   298  
   299  ```hcl
   300  variable "subnet_ids" {
   301    type = list(string)
   302  }
   303  
   304  resource "aws_instance" "server" {
   305    # Create one instance for each subnet
   306    count = length(var.subnet_ids)
   307  
   308    ami           = "ami-a1b2c3d4"
   309    instance_type = "t2.micro"
   310    subnet_id     = var.subnet_ids[count.index]
   311  
   312    tags = {
   313      Name = "Server ${count.index}"
   314    }
   315  }
   316  ```
   317  
   318  This was fragile, because the resource instances were still identified by their
   319  _index_ instead of the string values in the list. If an element was removed from
   320  the middle of the list, every instance _after_ that element would see its
   321  `subnet_id` value change, resulting in more remote object changes than intended.
   322  Using `for_each` gives the same flexibility without the extra churn.
   323  
   324  ### `for_each`: Multiple Resource Instances Defined By a Map, or Set of Strings
   325  
   326  [inpage-for_each]: #for_each-multiple-resource-instances-defined-by-a-map-or-set-of-strings
   327  
   328  -> **Version note:** `for_each` was added in Terraform 0.12.6.
   329  
   330  -> **Note:** A given resource block cannot use both `count` and `for_each`.
   331  
   332  By default, a `resource` block configures one real infrastructure object.
   333  However, sometimes you want to manage several similar objects, such as a fixed
   334  pool of compute instances. Terraform has two ways to do this:
   335  [`count`][inpage-count] and `for_each`.
   336  
   337  The `for_each` meta-argument accepts a map or a set of strings, and creates an
   338  instance for each item in that map or set. Each instance has a distinct
   339  infrastructure object associated with it (as described above in
   340  [Resource Behavior](#resource-behavior)), and each is separately created,
   341  updated, or destroyed when the configuration is applied.
   342  
   343  -> **Note:** The keys of the map (or all the values in the case of a set of strings) must
   344  be _known values_, or you will get an error message that `for_each` has dependencies
   345  that cannot be determined before apply, and a `-target` may be needed. `for_each` keys
   346  cannot be the result (or rely on the result of) of impure functions, including `uuid`, `bcrypt`,
   347  or `timestamp`, as their evaluation is deferred resource during evaluation.
   348  
   349  ```hcl
   350  resource "azurerm_resource_group" "rg" {
   351    for_each = {
   352      a_group = "eastus"
   353      another_group = "westus2"
   354    }
   355    name     = each.key
   356    location = each.value
   357  }
   358  ```
   359  
   360  #### The `each` Object
   361  
   362  In resource blocks where `for_each` is set, an additional `each` object is
   363  available in expressions, so you can modify the configuration of each instance.
   364  This object has two attributes:
   365  
   366  - `each.key` — The map key (or set member) corresponding to this instance.
   367  - `each.value` — The map value corresponding to this instance. (If a set was
   368    provided, this is the same as `each.key`.)
   369  
   370  #### Referring to Instances
   371  
   372  When `for_each` is set, Terraform distinguishes between the resource block itself
   373  and the multiple _resource instances_ associated with it. Instances are
   374  identified by a map key (or set member) from the value provided to `for_each`.
   375  
   376  - `<TYPE>.<NAME>` (for example, `azurerm_resource_group.rg`) refers to the resource block.
   377  - `<TYPE>.<NAME>[<KEY>]` (for example, `azurerm_resource_group.rg["a_group"]`,
   378    `azurerm_resource_group.rg["another_group"]`, etc.) refers to individual instances.
   379  
   380  This is different from resources without `count` or `for_each`, which can be
   381  referenced without an index or key.
   382  
   383  -> **Note:** Within nested `provisioner` or `connection` blocks, the special
   384  `self` object refers to the current _resource instance,_ not the resource block
   385  as a whole.
   386  
   387  #### Using Sets
   388  
   389  The Terraform language doesn't have a literal syntax for
   390  [sets](./types.html#collection-types), but you can use the `toset` function to
   391  convert a list of strings to a set:
   392  
   393  ```hcl
   394  variable "subnet_ids" {
   395    type = list(string)
   396  }
   397  
   398  resource "aws_instance" "server" {
   399    for_each = toset(var.subnet_ids)
   400  
   401    ami           = "ami-a1b2c3d4"
   402    instance_type = "t2.micro"
   403    subnet_id     = each.key # note: each.key and each.value are the same for a set
   404  
   405    tags = {
   406      Name = "Server ${each.key}"
   407    }
   408  }
   409  ```
   410  
   411  #### Using Expressions in `for_each`
   412  
   413  The `for_each` meta-argument accepts map or set [expressions](./expressions.html).
   414  However, unlike most resource arguments, the `for_each` value must be known
   415  _before_ Terraform performs any remote resource actions. This means `for_each`
   416  can't refer to any resource attributes that aren't known until after a
   417  configuration is applied (such as a unique ID generated by the remote API when
   418  an object is created).
   419  
   420  The `for_each` value must be a map or set with one element per desired
   421  resource instance. If you need to declare resource instances based on a nested
   422  data structure or combinations of elements from multiple data structures you
   423  can use Terraform expressions and functions to derive a suitable value.
   424  For some common examples of such situations, see the
   425  [`flatten`](/docs/configuration/functions/flatten.html)
   426  and
   427  [`setproduct`](/docs/configuration/functions/setproduct.html)
   428  functions.
   429  
   430  ### `provider`: Selecting a Non-default Provider Configuration
   431  
   432  [inpage-provider]: #provider-selecting-a-non-default-provider-configuration
   433  
   434  As described in [the Providers page](./providers.html),
   435  Terraform optionally allows the definition of multiple alternative ("aliased")
   436  configurations for a single provider, to allow management of resources
   437  in different regions in multi-region services, etc.
   438  The `provider` meta-argument overrides Terraform's default behavior of
   439  selecting a provider configuration based on the resource type name.
   440  
   441  By default, Terraform takes the initial word in the resource type name
   442  (separated by underscores) and selects the default configuration for that
   443  named provider. For example, the resource type `google_compute_instance`
   444  is associated automatically with the default configuration for the provider
   445  named `google`.
   446  
   447  By using the `provider` meta-argument, an aliased provider configuration
   448  can be selected:
   449  
   450  ```hcl
   451  # default configuration
   452  provider "google" {
   453    region = "us-central1"
   454  }
   455  
   456  # alternative, aliased configuration
   457  provider "google" {
   458    alias  = "europe"
   459    region = "europe-west1"
   460  }
   461  
   462  resource "google_compute_instance" "example" {
   463    # This "provider" meta-argument selects the google provider
   464    # configuration whose alias is "europe", rather than the
   465    # default configuration.
   466    provider = google.europe
   467  
   468    # ...
   469  }
   470  ```
   471  
   472  A resource always has an implicit dependency on its associated provider, to
   473  ensure that the provider is fully configured before any resource actions
   474  are taken.
   475  
   476  The `provider` meta-argument expects [a `<PROVIDER>.<ALIAS>` reference](./providers.html#referring-to-alternate-providers), which
   477  does not need to be quoted. Arbitrary expressions are not permitted for
   478  `provider` because it must be resolved while Terraform is constructing the
   479  dependency graph, before it is safe to evaluate expressions.
   480  
   481  ### `lifecycle`: Lifecycle Customizations
   482  
   483  [inpage-lifecycle]: #lifecycle-lifecycle-customizations
   484  
   485  The general lifecycle for resources is described above in the
   486  [Resource Behavior](#resource-behavior) section. Some details of that behavior
   487  can be customized using the special nested `lifecycle` block within a resource
   488  block body:
   489  
   490  ```
   491  resource "azurerm_resource_group" "example" {
   492    # ...
   493  
   494    lifecycle {
   495      create_before_destroy = true
   496    }
   497  }
   498  ```
   499  
   500  The `lifecycle` block and its contents are meta-arguments, available
   501  for all `resource` blocks regardless of type. The following lifecycle
   502  meta-arguments are supported:
   503  
   504  * `create_before_destroy` (bool) - By default, when Terraform must make a
   505    change to a resource argument that cannot be updated in-place due to
   506    remote API limitations, Terraform will instead destroy the existing object
   507    and then create a new replacement object with the new configured arguments.
   508  
   509      The `create_before_destroy` meta-argument changes this behavior so that
   510      the new replacement object is created _first,_ and then the prior object
   511      is destroyed only once the replacement is created.
   512  
   513      This is an opt-in behavior because many remote object types have unique
   514      name requirements or other constraints that must be accommodated for
   515      both a new and an old object to exist concurrently. Some resource types
   516      offer special options to append a random suffix onto each object name to
   517      avoid collisions, for example. Terraform CLI cannot automatically activate
   518      such features, so you must understand the constraints for each resource
   519      type before using `create_before_destroy` with it.
   520  
   521  * `prevent_destroy` (bool) - This meta-argument, when set to `true`, will
   522    cause Terraform to reject with an error any plan that would destroy the
   523    infrastructure object associated with the resource, as long as the argument
   524    remains present in the configuration.
   525  
   526      This can be used as a measure of safety against the accidental replacement
   527      of objects that may be costly to reproduce, such as database instances.
   528      However, it will make certain configuration changes impossible to apply,
   529      and will prevent the use of the `terraform destroy` command once such
   530      objects are created, and so this option should be used sparingly.
   531  
   532      Since this argument must be present in configuration for the protection to
   533      apply, note that this setting does not prevent the remote object from
   534      being destroyed if the `resource` block were removed from configuration
   535      entirely: in that case, the `prevent_destroy` setting is removed along
   536      with it, and so Terraform will allow the destroy operation to succeed.
   537  
   538  * `ignore_changes` (list of attribute names) - By default, Terraform detects
   539    any difference in the current settings of a real infrastructure object
   540    and plans to update the remote object to match configuration.
   541  
   542      In some rare cases, settings of a remote object are modified by processes
   543      outside of Terraform, which Terraform would then attempt to "fix" on the
   544      next run. In order to make Terraform share management responsibilities
   545      of a single object with a separate process, the `ignore_changes`
   546      meta-argument specifies resource attributes that Terraform should ignore
   547      when planning updates to the associated remote object.
   548  
   549      The arguments corresponding to the given attribute names are considered
   550      when planning a _create_ operation, but are ignored when planning an
   551      _update_.
   552  
   553      ```hcl
   554      resource "aws_instance" "example" {
   555        # ...
   556  
   557        lifecycle {
   558          ignore_changes = [
   559            # Ignore changes to tags, e.g. because a management agent
   560            # updates these based on some ruleset managed elsewhere.
   561            tags,
   562          ]
   563        }
   564      }
   565      ```
   566  
   567      You can also ignore specific map elements by writing references like
   568      `tags["Name"]` in the `ignore_changes` list, though with an important
   569      caveat: the ignoring applies only to in-place updates to an existing
   570      key. Adding or removing a key is treated by Terraform as a change to the
   571      containing map itself rather than to the individual key, and so if you
   572      wish to ignore changes to a particular tag made by an external system
   573      you must ensure that the Terraform configuration creates a placeholder
   574      element for that tag name so that the external system changes will be
   575      understood as an in-place edit of that key:
   576  
   577      ```hcl
   578      resource "aws_instance" "example" {
   579        # ...
   580  
   581        tags = {
   582          # Initial value for Name is overridden by our automatic scheduled
   583          # re-tagging process; changes to this are ignored by ignore_changes
   584          # below.
   585          Name = "placeholder"
   586        }
   587  
   588        lifecycle {
   589          ignore_changes = [
   590            tags["Name"],
   591          ]
   592        }
   593      }
   594      ```
   595  
   596      Instead of a list, the special keyword `all` may be used to instruct
   597      Terraform to ignore _all_ attributes, which means that Terraform can
   598      create and destroy the remote object but will never propose updates to it.
   599  
   600      Only attributes defined by the resource type can be ignored.
   601      `ignore_changes` cannot be applied to itself or to any other meta-arguments.
   602  
   603  The `lifecycle` settings all effect how Terraform constructs and traverses
   604  the dependency graph. As a result, only literal values can be used because
   605  the processing happens too early for arbitrary expression evaluation.
   606  
   607  ### `provisioner` and `connection`: Resource Provisioners
   608  
   609  [inpage-provisioner]: #provisioner-and-connection-resource-provisioners
   610  
   611  Some infrastructure objects require some special actions to be taken after they
   612  are created before they can become fully functional. For example, compute
   613  instances may require configuration to be uploaded or a configuration management
   614  program to be run before they can begin their intended operation.
   615  
   616  Create-time actions like these can be described using _resource provisioners_.
   617  A provisioner is another type of plugin supported by Terraform, and each
   618  provisioner takes a different kind of action in the context of a resource
   619  being created.
   620  
   621  Provisioning steps should be used sparingly, since they represent
   622  non-declarative actions taken during the creation of a resource and so
   623  Terraform is not able to model changes to them as it can for the declarative
   624  portions of the Terraform language.
   625  
   626  Provisioners can also be defined to run when a resource is _destroyed_, with
   627  certain limitations.
   628  
   629  The `provisioner` and `connection` block types within `resource` blocks are
   630  meta-arguments available across all resource types. Provisioners and their
   631  usage are described in more detail in
   632  [the Provisioners section](/docs/provisioners/index.html).
   633  
   634  ## Local-only Resources
   635  
   636  While most resource types correspond to an infrastructure object type that
   637  is managed via a remote network API, there are certain specialized resource
   638  types that operate only within Terraform itself, calculating some results and
   639  saving those results in the state for future use.
   640  
   641  For example, local-only resource types exist for
   642  [generating private keys](/docs/providers/tls/r/private_key.html),
   643  [issuing self-signed TLS certificates](/docs/providers/tls/r/self_signed_cert.html),
   644  and even [generating random ids](/docs/providers/random/r/id.html).
   645  While these resource types often have a more marginal purpose than those
   646  managing "real" infrastructure objects, they can be useful as glue to help
   647  connect together other resources.
   648  
   649  The behavior of local-only resources is the same as all other resources, but
   650  their result data exists only within the Terraform state. "Destroying" such
   651  a resource means only to remove it from the state, discarding its data.
   652  
   653  ## Operation Timeouts
   654  
   655  Some resource types provide a special `timeouts` nested block argument that
   656  allows you to customize how long certain operations are allowed to take
   657  before being considered to have failed.
   658  For example, [`aws_db_instance`](/docs/providers/aws/r/db_instance.html)
   659  allows configurable timeouts for `create`, `update` and `delete` operations.
   660  
   661  Timeouts are handled entirely by the resource type implementation in the
   662  provider, but resource types offering these features follow the convention
   663  of defining a child block called `timeouts` that has a nested argument
   664  named after each operation that has a configurable timeout value.
   665  Each of these arguments takes a string representation of a duration, such
   666  as `"60m"` for 60 minutes, `"10s"` for ten seconds, or `"2h"` for two hours.
   667  
   668  ```hcl
   669  resource "aws_db_instance" "example" {
   670    # ...
   671  
   672    timeouts {
   673      create = "60m"
   674      delete = "2h"
   675    }
   676  }
   677  ```
   678  
   679  The set of configurable operations is chosen by each resource type. Most
   680  resource types do not support the `timeouts` block at all. Consult the
   681  documentation for each resource type to see which operations it offers
   682  for configuration, if any.
   683