Terraform
terraform state push command
The terraform state push command uploads a local state file to remote state or a local state. We only recommend using this command when you must manually modify the remote state.
Usage
Usage: terraform state push [options] PATH
This command pushes the state specified by PATH to the currently configured backend.
If PATH is "-" then the state data to push is read from stdin. This data is loaded completely into memory and verified prior to being written to the destination state.
Note: Terraform state files must be in UTF-8 format without a byte order mark (BOM). For PowerShell on Windows, use Set-Content to automatically encode files in UTF-8 format. For example, run terraform state push | Set-Content terraform.tfstate.
Terraform will perform a number of safety checks to prevent you from making changes that appear to be unsafe:
Differing lineage: If the "lineage" value in the state differs, Terraform will not allow you to push the state. A differing lineage suggests that the states are completely different and you may lose data.
Higher remote serial: If the "serial" value in the destination state is higher than the state being pushed, Terraform will prevent the push. A higher serial suggests that data is in the destination state that isn't accounted for in the local state being pushed.
Both of these safety checks can be disabled with the -force flag.
This is not recommended. If you disable the safety checks and are
pushing state, the destination state will be overwritten.
This command also accepts the following options:
-force- Disable the safety checks for differing lineage and higher remote serial.-var 'NAME=VALUE'- Sets a value for a single input variable declared in the root module of the configuration. Use this option multiple times to set more than one variable. Refer to Input Variables on the Command Line for more information.-var-file=FILENAME- Sets values for potentially many input variables declared in the root module of the configuration, using definitions from a.tfvarsfile. Use this option multiple times to include values from more than one file. There are several other ways to set values for input variables in the root module, aside from the-varand-var-fileoptions. Refer to Assign values to input variables for more information.
For configurations using the HCP Terraform CLI integration or the remote backend
only, terraform state push
also accepts the option
-ignore-remote-version.