Downloading and Uploading the State File

Learn the pull and push subcommands and when they’re used in Terraform state.

The pull subcommand

The terraform state pull command is used to manually download and output the state from a remote backend. This command also works with the local back-end.

Syntax

The pull subcommand has the following syntax: terraform state pull [options].

This command is equivalent to viewing the contents of the Terraform state directly, in a read-only mode. The output of the command is sent in JSON format. Let’s run the following command to send the output in JSON format:

cp terraform.tfstate tfstate-file-download.json

Then, we view the content of this file by running the following command:

cat tfstate-file-download.json

Use of the pull subcommand

The primary use of the subcommand is to read the contents of the remote state. If we were using the local back-end, we could just as easily use cat on the local file.

Let’s run the following command to read the content of the remote state:

Get hands-on with 1200+ tech skills courses.