Backend GCS

Here’s an example with the gcs backend.

config/terraform/backend.tf:

terraform {
  backend "gcs" {
    bucket = "<%= expansion('terraform-state-:PROJECT-:REGION-:ENV') %>"
    prefix = "<%= expansion(':PROJECT/:TYPE_DIR/:APP/:ROLE/:MOD_NAME/:ENV/:EXTRA/:REGION') %>"
  }
}

Notice the variable notation. Terraspace expands it out, substituting the values. The starter backend.tf accounts for PROJECT, ENV, etc. Here’s an expanded example:

terraform {
  backend "gcs" {
    bucket = "terraform-state-google-project-id-us-central1-dev"
    prefix = "us-central1/dev/stacks/demo"
  }
}

Why Is Env in Bucket Name?

By default, the bucket name has the ENV at the end. This is done so we can easily see which environment the bucket stores Terraform statefiles for. This quickly helps with debugging. If you prefer not to have the ENV at the end of the bucket name, remove it after generating the project with terraspace new project.

More tools: