Professional Documents
Culture Documents
io
/docs/language/resources/index.html
The Meta-Arguments section documents special arguments that can be used with
every resource type, including
depends_on,
count,
for_each,
provider,
and
lifecycle.
Provisioners
documents configuring post-creation actions for a resource using the
provisioner and connection blocks. Since provisioners are non-declarative
and
potentially unpredictable, we strongly recommend that you treat them as a
last
resort.
www.terraform.io
/docs/language/resources/syntax.html
»
Resource Syntax
Resource declarations can include a number of advanced features, but only
a small
subset are required for initial use. More advanced syntax features,
such as single
resource declarations that produce multiple similar remote
objects, are described later in
this page.
ami = "ami-a1b2c3d4"
instance_type = "t2.micro"
The resource type and name together serve as an identifier for a given
resource and so
must be unique within a module.
Within the block body (between { and }) are the configuration arguments
for the resource
itself. Most arguments in this section depend on the
resource type, and indeed in this
example both ami and instance_type are
arguments defined specifically for the
aws_instance resource type.
»
Resource Types
Each resource is associated with a single resource type, which determines
the kind of
infrastructure object it manages and what arguments and other
attributes the resource
supports.
»
Providers
»
Resource Arguments
Most of the arguments within the body of a resource block are specific to the
selected
resource type. The resource type's documentation lists which arguments
are available and
how their values should be formatted.
There are also some meta-arguments that are defined by Terraform itself
and apply
across all resource types. (See Meta-Arguments below.)
»
Documentation for Resource Types
Every Terraform provider has its own documentation, describing its resource
types and
their arguments.
»
Resource Behavior
For more information about how Terraform manages resources when applying a
configuration, see
Resource Behavior.
The Terraform language defines several meta-arguments, which can be used with
any
resource type to change the behavior of resources.
»
Operation Timeouts
Some resource types provide a special timeouts nested block argument that
allows you
to customize how long certain operations are allowed to take
before being considered to
have failed.
For example, aws_db_instance
allows configurable timeouts for create,
update and delete operations.
# ...
timeouts {
create = "60m"
delete = "2h"
»
How Terraform Applies a Configuration
When Terraform creates a new infrastructure object represented by a resource
block, the
identifier for that real object is saved in Terraform's
state, allowing it to be updated and
destroyed
in response to future changes. For resource blocks that already have an
associated infrastructure object in the state, Terraform compares the
actual configuration
of the object with the arguments given in the
configuration and, if necessary, updates the
object to match the configuration.
Create resources that exist in the configuration but are not associated with a real
infrastructure object in the state.
Destroy resources that exist in the state but no longer exist in the configuration.
Update in-place resources whose arguments have changed.
Destroy and re-create resources whose arguments have changed but which cannot
be updated in-place due to remote API limitations.
This general behavior applies for all resources, regardless of type. The
details of what it
means to create, update, or destroy a resource are different
for each resource type, but
this standard set of verbs is common across them
all.
»
Accessing Resource Attributes
Expressions within a Terraform module can access
information about resources in the
same module, and you can use that information
to help configure other resources. Use the
<RESOURCE TYPE>.<NAME>.<ATTRIBUTE>
syntax to reference a resource attribute in an
expression.
For a list of the attributes a resource or data source type provides, consult
its
documentation; these are generally included in a second list below its list
of configurable
arguments.
»
Resource Dependencies
Most resources in a configuration don't have any particular relationship, and
Terraform can
make changes to several unrelated resources in parallel.
»
Local-only Resources
While most resource types correspond to an infrastructure object type that
is managed via
a remote network API, there are certain specialized resource
types that operate only
within Terraform itself, calculating some results and
saving those results in the state for
future use.
The behavior of local-only resources is the same as all other resources, but
their result
data exists only within the Terraform state. "Destroying" such
a resource means only to
remove it from the state, discarding its data.