Terraform Cloud planning state differs from local

I’ve just signed up for terraform cloud and it looks great!

Got a workspace running (0.12.3) but I seem to be running into some difference when planning on TFC and locally.

On TFC, it seems like TF is not looking at the right place for the state and when it plans, it thinks its creating a brand new resource.

My main.tf looks something like:

  provider "google-beta" {
    project = "${var.project_id}"
  }

  provider "google" {
    project = "${var.project_id}"
  }

  terraform {
   backend "gcs" {
     bucket  = "x-terraform-admin"
     prefix  = "terraform/state/prod/gke"
   }
  }


  data "terraform_remote_state" "prod-vpc" {
    backend = "gcs"
    config = {
     bucket  = "x-terraform-admin"
     prefix  = "terraform/state/prod/vpc"
   }
  }

My variables are in a file global.auto.tfvars and I’ve added the following envvars:

GOOGLE_CREDENTIALS
GOOGLE_PROJECT

When I run terraform plan locally, I get the expected

Plan: 0 to add, 3 to change, 0 to destroy.

But on TFC when it plans I get

Plan: 6 to add, 0 to change, 0 to destroy.

Has anyone run into this issue before?

Both environments appear to be identical.

Hello!

Did you happen to go through all the instructions in the Migrating State docs ? It seems like your workspace doesn’t have your existing state (which needs to be migrated). After editing the backend configuration block to point to Terraform Cloud instead of your GCS bucket, running terraform init will automatically give you a prompt asking if you’d like to move your state.

There’s some help in the Troubleshooting section for how to re-set your backend to your original state to try and migrate it again, if this is the case.

Hi Chris,

I’m embarrassed, I went through the docs a few times, but skipped the migrating state doc because it didn’t look like anything to do with my issue.

Thanks so much for pointing this out!

1 Like