terraform/website/source/docs/state/remote/gcs.html.md

1.3 KiB

layout page_title sidebar_current description
remotestate Remote State Backend: gcs docs-state-remote-gcs Terraform can store the state remotely, making it easier to version and work with in a team.

gcs

Stores the state as a given key in a given bucket on Google Cloud Storage.

-> Note: Passing credentials directly via config options will make them included in cleartext inside the persisted state. Use of environment variables or config file is recommended.

Example Usage

terraform remote config \
	-backend=gcs \
	-backend-config="bucket=terraform-state-prod" \
	-backend-config="path=network/terraform.tfstate" \
	-backend-config="project=goopro"

Example Referencing

# setup remote state data source
data "terraform_remote_state" "foo" {
	backend = "gcs"
	config {
		bucket = "terraform-state-prod"
		path = "network/terraform.tfstate"
		project = "goopro"
	}
}

# read value from data source
resource "template_file" "bar" {
  template = "${greeting}"

  vars {
    greeting = "${data.terraform_remote_state.foo.output.greeting}"
  }
}

Configuration variables

The following configuration options are supported:

  • bucket - (Required) The name of the GCS bucket
  • path - (Required) The path where to place/look for state file inside the bucket