admin管理员组

文章数量:1122826

I have a terraform state file in local which we want to migrate it to GCP cloud as a remote backend. I have created the bucket named "dns-zone" and added the existing tfstate file named terraform.tfstate into the bucket folder named "dns-folder".

The backend code looks like this:

terraform {
  backend "gcs" {
    bucket  = "dns-zone"
    prefix  = "dns-folder"
  }
}

after that I ran the command "terraform init -migrate-state".

now its creating the new tfstate file as "default.tfstate" in the bucket location instead of using the previuos state file (terraform.tfstate). And when i try to run terraform plan it shows whole infra to create which is already exists.

Please help me to resolve this issue.

I have a terraform state file in local which we want to migrate it to GCP cloud as a remote backend. I have created the bucket named "dns-zone" and added the existing tfstate file named terraform.tfstate into the bucket folder named "dns-folder".

The backend code looks like this:

terraform {
  backend "gcs" {
    bucket  = "dns-zone"
    prefix  = "dns-folder"
  }
}

after that I ran the command "terraform init -migrate-state".

now its creating the new tfstate file as "default.tfstate" in the bucket location instead of using the previuos state file (terraform.tfstate). And when i try to run terraform plan it shows whole infra to create which is already exists.

Please help me to resolve this issue.

Share Improve this question asked Nov 22, 2024 at 11:56 MaheshMahesh 111 bronze badge 1
  • does it matter if its called default.tfstate? The docs say Named states for workspaces are stored in an object called <prefix>/<name>.tfstate. When you dont specify a workspace then terraform uses the workspace called default. You can see this when you run terraform workspace list – Chris Doyle Commented Nov 22, 2024 at 16:51
Add a comment  | 

1 Answer 1

Reset to default 0

When working with the state, I always use and recommend using the terraform state ... commands to ensure terraform does everything necessary to keep track of it. In your case, you would use terraform state push <path/to/your/terraform.tfstate> to get your local state into your remote backend. https://developer.hashicorp.com/terraform/cli/commands/state/push

本文标签: Terraform state file migration from local to GCP cloudStack Overflow