|
| 1 | +--- |
| 2 | +layout: "docs" |
| 3 | +page_title: "Command: remote" |
| 4 | +sidebar_current: "docs-commands-remote" |
| 5 | +description: |- |
| 6 | + The `terraform remote` command is used to configure Terraform to make |
| 7 | + use of remote state storage, change remote storage configuration, or |
| 8 | + to disable it. |
| 9 | +--- |
| 10 | + |
| 11 | +# Command: remote |
| 12 | + |
| 13 | +The `terraform remote` command is used to configure use of remote |
| 14 | +state storage. By default, Terraform persists its state only to a local |
| 15 | +disk. When remote state storage is enabled, Terraform will automatically |
| 16 | +fetch the latest state from the remote server when necessary and if any |
| 17 | +updates are made, the newest state is persisted back to the remote server. |
| 18 | +In this mode, users do not need to durably store the state using version |
| 19 | +control or shared storaged. |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +Usage: `terraform remote [options]` |
| 24 | + |
| 25 | +The `remote` command can be used to enable remote storage, change configuration, |
| 26 | +or disable the use of remote storage. Terraform supports multiple types |
| 27 | +of storage backends, specified by using the `-backend` flag. By default, |
| 28 | +Atlas is assumed to be the storage backend. Each backend expects different, |
| 29 | +configuration arguments documented below. |
| 30 | + |
| 31 | +When remote storage is enabled, an existing local state file can be migrated. |
| 32 | +By default, `remote` will look for the "terraform.tfstate" file, but that |
| 33 | +can be specified by the `-state` flag. If no state file exists, a blank |
| 34 | +state will be configured. |
| 35 | + |
| 36 | +When remote storage is disabled, the existing remote state is migrated |
| 37 | +to a local file. This defaults to the `-state` path during restore. |
| 38 | + |
| 39 | +The following backends are supported: |
| 40 | + |
| 41 | +* Atlas - Stores the state in Atlas. Requires the `-name` and `-access-token` flag. |
| 42 | + The `-address` flag can optionally be provided. |
| 43 | + |
| 44 | +* Consul - Stores the state in the KV store at a given path. |
| 45 | + Requires the `path` flag. The `-address` and `-access-token` |
| 46 | + flag can optionally be provided. Address is assumed to be the |
| 47 | + local agent if not provided. |
| 48 | + |
| 49 | +* HTTP - Stores the state using a simple REST client. State will be fetched |
| 50 | + via GET, updated via POST, and purged with DELETE. Requires the `-address` flag. |
| 51 | + |
| 52 | +The command-line flags are all optional. The list of available flags are: |
| 53 | + |
| 54 | +* `-address=url` - URL of the remote storage server. Required for HTTP backend, |
| 55 | + optional for Atlas and Consul. |
| 56 | + |
| 57 | +* `-access-token=token` - Authentication token for state storage server. |
| 58 | + Required for Atlas backend, optional for Consul. |
| 59 | + |
| 60 | +* `-backend=Atlas` - Specifies the type of remote backend. Must be one |
| 61 | + of Atlas, Consul, or HTTP. Defaults to Atlas. |
| 62 | + |
| 63 | +* `-backup=path` - Path to backup the existing state file before |
| 64 | + modifying. Defaults to the "-state" path with ".backup" extension. |
| 65 | + Set to "-" to disable backup. |
| 66 | + |
| 67 | +* `-disable` - Disables remote state management and migrates the state |
| 68 | + to the `-state` path. |
| 69 | + |
| 70 | +* `-name=name` - Name of the state file in the state storage server. |
| 71 | + Required for Atlas backend. |
| 72 | + |
| 73 | +* `-path=path` - Path of the remote state in Consul. Required for the |
| 74 | + Consul backend. |
| 75 | + |
| 76 | +* `-pull=true` - Controls if the remote state is pulled before disabling. |
| 77 | + This defaults to true to ensure the latest state is cached before disabling. |
| 78 | + |
| 79 | +* `-state=path` - Path to read state. Defaults to "terraform.tfstate" |
| 80 | + unless remote state is enabled. |
| 81 | + |
0 commit comments