github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/resources/behavior.html.md (about)

     1  ---
     2  layout: "language"
     3  page_title: "Resource Behavior - Configuration Language"
     4  description: "Learn how Terraform uses resource blocks to create infrastructure objects. Also learn about resource dependencies and how to access resource attributes."
     5  ---
     6  
     7  # Resource Behavior
     8  
     9  A `resource` block declares that you want a particular infrastructure object
    10  to exist with the given settings. If you are writing a new configuration for
    11  the first time, the resources it defines will exist _only_ in the configuration,
    12  and will not yet represent real infrastructure objects in the target platform.
    13  
    14  _Applying_ a Terraform configuration is the process of creating, updating,
    15  and destroying real infrastructure objects in order to make their settings
    16  match the configuration.
    17  
    18  ## How Terraform Applies a Configuration
    19  
    20  When Terraform creates a new infrastructure object represented by a `resource`
    21  block, the identifier for that real object is saved in Terraform's
    22  [state](/docs/language/state/index.html), allowing it to be updated and destroyed
    23  in response to future changes. For resource blocks that already have an
    24  associated infrastructure object in the state, Terraform compares the
    25  actual configuration of the object with the arguments given in the
    26  configuration and, if necessary, updates the object to match the configuration.
    27  
    28  In summary, applying a Terraform configuration will:
    29  
    30  - _Create_ resources that exist in the configuration but are not associated with a real infrastructure object in the state.
    31  - _Destroy_ resources that exist in the state but no longer exist in the configuration.
    32  - _Update in-place_ resources whose arguments have changed.
    33  - _Destroy and re-create_ resources whose arguments have changed but which cannot be updated in-place due to remote API limitations.
    34  
    35  This general behavior applies for all resources, regardless of type. The
    36  details of what it means to create, update, or destroy a resource are different
    37  for each resource type, but this standard set of verbs is common across them
    38  all.
    39  
    40  The meta-arguments within `resource` blocks, documented in the
    41  sections below, allow some details of this standard resource behavior to be
    42  customized on a per-resource basis.
    43  
    44  ## Accessing Resource Attributes
    45  
    46  [Expressions](/docs/language/expressions/index.html) within a Terraform module can access
    47  information about resources in the same module, and you can use that information
    48  to help configure other resources. Use the `<RESOURCE TYPE>.<NAME>.<ATTRIBUTE>`
    49  syntax to reference a resource attribute in an expression.
    50  
    51  In addition to arguments specified in the configuration, resources often provide
    52  read-only attributes with information obtained from the remote API; this often
    53  includes things that can't be known until the resource is created, like the
    54  resource's unique random ID.
    55  
    56  Many providers also include [data sources](/docs/language/data-sources/index.html),
    57  which are a special type of resource used only for looking up information.
    58  
    59  For a list of the attributes a resource or data source type provides, consult
    60  its documentation; these are generally included in a second list below its list
    61  of configurable arguments.
    62  
    63  For more information about referencing resource attributes in expressions, see
    64  [Expressions: References to Resource Attributes](/docs/language/expressions/references.html#references-to-resource-attributes).
    65  
    66  ## Resource Dependencies
    67  
    68  Most resources in a configuration don't have any particular relationship, and
    69  Terraform can make changes to several unrelated resources in parallel.
    70  
    71  However, some resources must be processed after other specific resources;
    72  sometimes this is because of how the resource works, and sometimes the
    73  resource's configuration just requires information generated by another
    74  resource.
    75  
    76  Most resource dependencies are handled automatically. Terraform analyses any
    77  [expressions](/docs/language/expressions/index.html) within a `resource` block to find references
    78  to other objects, and treats those references as implicit ordering requirements
    79  when creating, updating, or destroying resources. Since most resources with
    80  behavioral dependencies on other resources also refer to those resources' data,
    81  it's usually not necessary to manually specify dependencies between resources.
    82  
    83  However, some dependencies cannot be recognized implicitly in configuration. For
    84  example, if Terraform must manage access control policies _and_ take actions
    85  that require those policies to be present, there is a hidden dependency between
    86  the access policy and a resource whose creation depends on it. In these rare
    87  cases,
    88  [the `depends_on` meta-argument](/docs/language/meta-arguments/depends_on.html)
    89  can explicitly specify a dependency.
    90  
    91  ## Local-only Resources
    92  
    93  While most resource types correspond to an infrastructure object type that
    94  is managed via a remote network API, there are certain specialized resource
    95  types that operate only within Terraform itself, calculating some results and
    96  saving those results in the state for future use.
    97  
    98  For example, local-only resource types exist for
    99  [generating private keys](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key),
   100  [issuing self-signed TLS certificates](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/self_signed_cert),
   101  and even [generating random ids](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id).
   102  While these resource types often have a more marginal purpose than those
   103  managing "real" infrastructure objects, they can be useful as glue to help
   104  connect together other resources.
   105  
   106  The behavior of local-only resources is the same as all other resources, but
   107  their result data exists only within the Terraform state. "Destroying" such
   108  a resource means only to remove it from the state, discarding its data.
   109