data - data source, requests terraform read from a
given data sourceprovider - configs for the specific provider
e.g. aws with specified versionresource - defines components of the
infrastructurevariable - defines variablesoutput - use to connect the terraform projects with
other parts of your infrastructure or with other terraform projectslocal - local variables to be reuse in this fileDifference of resource and data
data is read only where resource cause
terraform to create, update and delete infrastructure objectsinit - initializes a working directory containing
Terraform configuration files. It is safe to run this command multiple
times.Provisioning Infrastructure
validate - check whether the configuration is
validplan - present a plan for making changes, dry-run of
applyapply - apply the planned changes to each resource
using the relevant infrastructure provider’s APIInterally, Terraform uses API to create and manage cloud resources.
Inspecting Infrastructure
console - inspect outputs interactively
e.g. > data.terraform.remote_state.sharedgraph - creates a visual representation of a
configuration or a set of planned changes.output - can get the values for the top-level output
values of a configurationshow - can generate human-readable versions of a state
file or plan file, or generate machine-readable versions that can be
integrated with other tools.state list - List resources in the stateDeveloping
fmt - formatvalidate - validates the configuration files in a
directory, referring only to the configuration and not accessing any
remote services such as remote state, provider APIs, etc.See Also: terraform cli doc
Terraform module
Terraform state
Terraform stores state about your workspace’s managed infrastructure and configuration due to following reasons.
Why does Terraform use state?
The primary purpose of state is to store bindings between objects in a remote system and resource instances declared in your configuration. When Terraform creates a remote object in response to a change of configuration, it records the identity of that remote object against a particular resource instance, and potentially updates and deletes that objects in response to future configuration changes.
Internal to terraform, workspace state is stored as JSON file. Do not directly edit this file. Terraform expects a one-to-one mapping between configured resource instance and remote objects. Normally that is guranteed by Terraform being the one to create each object and record its identity in the state, or to destroy an object and then remove the binding for it. If you add or remote bindings in the state by other means, such as by importing externally - created objects with ‘terraform import’, or by asking Terraform to ‘forget’ an existing object with ‘terraform state rm’, you’ll then need to ensure for yourself that this one-to-one rule is followed, such as by manually deleting an object that you asked terraform to forget, or by re-importing it to bind it to some other resource instance.
remote state backends
Helps collaboration and coordinate execution for multiple developers working on the same codebase.
scale Terraform
how to define boundaries or infrastructure ownership. need to decide on a cloud deployment strategy, possible approaches include using a single account in a single cloud provider, a hybrid or multi-cloud approach, or to divide up resources across accounts by environments.
Divide infrastructure responsibility
It’s common for different teams to focus on different parts of your organisation’s infrastructure. Networking team manage the VPCs, application team only needs to know where to deploy their application and focus on configuring servers and databases. But application still needs to access data about the networking resources for their own configuration - use reference data about other resources in your configuration without having to manage them in the same state file, allowing you to maintain distinct areas of ownership and infrastructure decoupling.