Terraform
State in Stacks
HCP Terraform stores the state of Stacks in files corresponding to each deployment of that Stack. Each deployment's state file includes the state of every component in that deployment.
View state
You can view the state of a deployment in each run of that deployment. To view the state of a deployment run, perform the following steps:
- Sign in to HCP Terraform or Terraform Enterprise and select your organization.
- Select the project your Stack lives in and click that Stack name.
- Select a version of your Stack configuration.
- Click on the deployment you want to review the state of.
- Click View state in the top right-hand corner to view your deployment state at each point in that deployment run.
HCP Terraform lists the components that make up the current deployment. You can expand each component and search the available components to review the resources within those components.
Note that HCP Terraform redacts sensitive values in the UI of deployment state, but those values are still stored. To learn more about sensitive values in state, refer to Manage sensitive data.
Manage state
Stacks automatically update and upgrade State whenever you plan or apply a deployment run.
To update the state of a deployment, update your component configuration files and apply the corresponding deployment runs to update the state of each deployment. You cannot manually affect the state of a Stack deployment without updating your configuration.
The following actions in your component configuration update the state of a deployment when you apply the corresponding deployment runs:
- Define new
component
blocks - Update a
component
block - Remove components
- Update the resources in the module that a
component
block sources
Adding new deployment
blocks to your deployment configuration file creates a new state file for that deployment after you apply the corresponding run. Applying a run that removes a deployment
block, or using the destroy=true
argument in a deployment, removes that deployment and its corresponding state file in HCP Terraform.
State locking and runs
HCP Terraform lets multiple deployment runs exist simultaneously for different configuration versions, but only one run can modify a deployment's state at a time. Deployment runs lock state while they are applying to ensure a run can finish without interference. To learn more, refer to deployment runs.
Access state from other Stacks
If you have multiple Stacks that do not share a provisioning lifecycle, you can link Stacks together to export data from one Stack for another to consume. If the output value of a Stack changes after a run, HCP Terraform automatically detects the change in state and triggers runs for any Stacks that depend on those outputs. To learn more and review examples, refer to Pass data from one Stack to another.
Managed resources in state
A managed resource is a resource in a state file where mode = "managed"
. HCP Terraform reads all the deployment's state files to determine the total number of managed resources for that Stack and determine the cost for your organization. To learn more about managed resources and billing, refer to Estimate HCP Terraform cost.