1.
- Snapshot of infrastructure
- In file the default file
terraform.tfstate
- Can be stored in Terraform Cloud
- Inspection and Modification
- Shouldnt be modified
- state remove, forget?
- Format:
- can use with
terraform output -json
- can use with
terraform show -json
- All subcommands that modify state (except show, list) will write backup file
2. Purpose:
- To map real world resources
- To guarantee one-to-one mapping
- To track of metadata:
- For
terraform plan
to work faster
- For sharing
- State locking?
- Workspace:
6. Locking:
- If supported by backend, Terraform will lock states for all operations that could write state
- happens automatically on all operations that could write state
- terraform force-unlock
Synopsis:
terraform state <subcommand> [options] [args]
terraform state list
: list resources in the state
terraform state pull
: pull current remote state and output to stdout
terraform state push
: update remote state from local state
terraform state replace-provider
: replace provider in state
terraform state rm
: remove instances from state
terraform state show
: show a resource in the state
- move an item in the state
- Allows to:
- rename existing resources
- move a resource/module into a module
- instead of rename a resource or move module then
terraform apply
, resources will be destroyed and recreated
- so move just change the ref
- rename:
terraform state mv aws_vpn.worker aws_vpn.helper
- resource to module:
terraform state mv packet_device.worker module.worker.packet_device.main
- module into module
terraform state mv module.app module.parent.module.app
- …