Terraform state
Represents the current state of the resources in the cloud
state mv
allows to change the refrence so u avodi create and destroy
action - rename exisitng resources - move a resource into a module -
move a module into a module
Rename resource
Move resource into module
Move moudle into a module
Replacing Resources
Cloud resoruce can become degraded or damaged and u want to return it to a healty state
# provide the flag and the resource adress
#Works only on one resource!!!
# avaibable on plan and apply
terraform apply -replace="aws_instance.example[0]"
Terraform State Backups
*All commands that modify state will write a backup file** -
Terraform sotores it in terraform.tfstate.backup
—
Note
Backup cannot be disabled!
to get rid of it u have to delete it mannualy
### Resource addressing ![]() |
#### Refresh-Only Mode ![]() |
### Terrafrom_remote_state Retrieves the root module output values from another Terraform configuration - Only the root-level values from the remote state snapshot are exposed. - Resource data and output values from nested modules are not accessible. - To enable that, explicitly configure a passthrough in the root module.** |
![]() |
### Alternative to Remote State |
The terraform_remote_state only exposes output values, requiring users to access the entire state snapshot, which may contain sensitive information. |
IMPORTANT
Publish data for external consumption to a sepearte location
instead of using remote state
Terraform State Locking
Terraform will lock your state for all operations that could write sate.
- Disableing Locing(not recommended
-lock
flag) - Force unlock(mannualy unlock satte if it failes)
-
If u unlock the sate when someone is hold a lock it causes multiple wirters issues
- The command requaiers the uniqe lock id
- Terraform wil oputput lock ID if unlocking fails
-
Note
Terraform log doesn’t show if it fails or succeeds only if it
takes to long