2017-02-15 19:47:30 +01:00
---
2017-02-15 21:19:38 +01:00
layout: "backend-types"
page_title: "Backend Type: gcs"
sidebar_current: "docs-backends-types-standard-gcs"
2017-02-15 19:47:30 +01:00
description: |-
Terraform can store the state remotely, making it easier to version and work with in a team.
---
# gcs
2017-09-11 08:25:42 +02:00
**Kind: Standard (with locking)**
2017-02-15 19:47:30 +01:00
2018-11-05 13:49:33 +01:00
Stores the state as an object in a configurable prefix in a given bucket on [Google Cloud Storage ](https://cloud.google.com/storage/ ) (GCS).
This backend also supports [state locking ](/docs/state/locking.html ).
~> **Warning!** It is highly recommended that you enable
[Object Versioning ](https://cloud.google.com/storage/docs/object-versioning )
on the GCS bucket to allow for state recovery in the case of accidental deletions and human error.
2017-02-15 19:47:30 +01:00
2017-02-15 21:19:38 +01:00
## Example Configuration
2017-02-15 19:47:30 +01:00
2017-04-05 17:29:27 +02:00
```hcl
2017-02-15 21:19:38 +01:00
terraform {
backend "gcs" {
2017-09-11 08:25:42 +02:00
bucket = "tf-state-prod"
prefix = "terraform/state"
2017-02-15 21:19:38 +01:00
}
}
2017-02-15 19:47:30 +01:00
```
## Example Referencing
```hcl
data "terraform_remote_state" "foo" {
2017-04-05 17:29:27 +02:00
backend = "gcs"
2018-10-29 17:22:21 +01:00
config = {
2017-09-11 08:25:42 +02:00
bucket = "terraform-state"
prefix = "prod"
2017-04-05 17:29:27 +02:00
}
2017-02-15 19:47:30 +01:00
}
resource "template_file" "bar" {
template = "${greeting}"
vars {
greeting = "${data.terraform_remote_state.foo.greeting}"
}
}
```
## Configuration variables
The following configuration options are supported:
2017-09-12 11:12:23 +02:00
* `bucket` - (Required) The name of the GCS bucket.
2017-09-12 13:58:36 +02:00
This name must be globally unique.
For more information, see [Bucket Naming Guidelines ](https://cloud.google.com/storage/docs/bucketnaming.html#requirements ).
2017-09-12 11:12:23 +02:00
* `credentials` / `GOOGLE_CREDENTIALS` - (Optional) Local path to Google Cloud Platform account credentials in JSON format.
If unset, [Google Application Default Credentials ](https://developers.google.com/identity/protocols/application-default-credentials ) are used.
2017-09-12 13:58:36 +02:00
The provided credentials need to have the `devstorage.read_write` scope and `WRITER` permissions on the bucket.
2017-12-14 16:08:41 +01:00
* `prefix` - (Optional) GCS prefix inside the bucket. Named states for workspaces are stored in an object called `<prefix>/<name>.tfstate` .
2017-09-12 11:12:23 +02:00
* `path` - (Deprecated) GCS path to the state file of the default state. For backwards compatibility only, use `prefix` instead.
2017-12-18 01:59:10 +01:00
* `encryption_key` / `GOOGLE_ENCRYPTION_KEY` - (Optional) A 32 byte base64 encoded 'customer supplied encryption key' used to encrypt all state. For more information see [Customer Supplied Encryption Keys ](https://cloud.google.com/storage/docs/encryption#customer-supplied ).