github.com/hugorut/terraform@v1.1.3/website/docs/language/state/backends.mdx (about) 1 --- 2 page_title: 'Backends: State Storage and Locking' 3 description: >- 4 Backends are configured directly in Terraform files in the `terraform` 5 section. 6 --- 7 8 # State Storage and Locking 9 10 Backends are responsible for storing state and providing an API for 11 [state locking](/language/state/locking). State locking is optional. 12 13 Despite the state being stored remotely, all Terraform commands such 14 as `terraform console`, the `terraform state` operations, `terraform taint`, 15 and more will continue to work as if the state was local. 16 17 ## State Storage 18 19 Backends determine where state is stored. For example, the local (default) 20 backend stores state in a local JSON file on disk. The Consul backend stores 21 the state within Consul. Both of these backends happen to provide locking: 22 local via system APIs and Consul via locking APIs. 23 24 When using a non-local backend, Terraform will not persist the state anywhere 25 on disk except in the case of a non-recoverable error where writing the state 26 to the backend failed. This behavior is a major benefit for backends: if 27 sensitive values are in your state, using a remote backend allows you to use 28 Terraform without that state ever being persisted to disk. 29 30 In the case of an error persisting the state to the backend, Terraform will 31 write the state locally. This is to prevent data loss. If this happens the 32 end user must manually push the state to the remote backend once the error 33 is resolved. 34 35 ## Manual State Pull/Push 36 37 You can still manually retrieve the state from the remote state using 38 the `terraform state pull` command. This will load your remote state and 39 output it to stdout. You can choose to save that to a file or perform any 40 other operations. 41 42 You can also manually write state with `terraform state push`. **This 43 is extremely dangerous and should be avoided if possible.** This will 44 overwrite the remote state. This can be used to do manual fixups if necessary. 45 46 When manually pushing state, Terraform will attempt to protect you from 47 some potentially dangerous situations: 48 49 - **Differing lineage**: The "lineage" is a unique ID assigned to a state 50 when it is created. If a lineage is different, then it means the states 51 were created at different times and its very likely you're modifying a 52 different state. Terraform will not allow this. 53 54 - **Higher serial**: Every state has a monotonically increasing "serial" 55 number. If the destination state has a higher serial, Terraform will 56 not allow you to write it since it means that changes have occurred since 57 the state you're attempting to write. 58 59 Both of these protections can be bypassed with the `-force` flag if you're 60 confident you're making the right decision. Even if using the `-force` flag, 61 we recommend making a backup of the state with `terraform state pull` 62 prior to forcing the overwrite. 63 64 ## State Locking 65 66 Backends are responsible for supporting [state locking](/language/state/locking) 67 if possible. 68 69 Not all backends support locking. The 70 [documentation for each backend](/language/settings/backends) 71 includes details on whether it supports locking or not. 72 73 For more information on state locking, view the 74 [page dedicated to state locking](/language/state/locking).