Sahas
Sahas

Reputation: 3186

Terraform backend remote config with Google Cloud Buckets

I'm running the below command and seeing the output that Terraform has been successfully initialized!

terraform init \
  -backend=true \
  -backend-config="bucket=terraform-remote-states" \
  -backend-config="project=<<my-poject>>" \
  -backend-config="path=terraform.tfstate"

However, when I run the template, it creates the state file locally instead of within GCS.

Not sure what I'm missing here. Appreciate any thoughts and help.

Upvotes: 3

Views: 1555

Answers (1)

jlucktay
jlucktay

Reputation: 432

When you execute the listed terraform init command, it seems like you don't have a backend block that looks like the below within any of the .tf files in that directory.

terraform {  
  backend "gcs" {
    bucket  = "terraform-state"
    path    = "/terraform.tfstate"
    project = "my-project"
  }
}

None of those -backend-config arguments you're passing tell Terraform that you want the state to go into GCS.

Without an explicit backend "gcs" {} declaration as above, Terraform will default to storing state locally, which is the behaviour you're currently seeing.

Upvotes: 1

Related Questions