Skip to main content

Command Palette

Search for a command to run...

Terraform + Azure Storage Backend: The Right Way to Migrate State

Updated
1 min read
Terraform + Azure Storage Backend: The Right Way to Migrate State
C

https://abhaypatil001.github.io/abhay-portfolio/

While configuring a remote backend in Terraform using Azure Storage, I hit an error that might look familiar:

If you wish to attempt automatic migration of the state, use "terraform init -migrate-state".
If you wish to store the current configuration with no changes to the state, use "terraform init -reconfigure".

This happened because I updated the backend block in main.tf before moving the existing terraform.tfstate file to Azure storage.

✅ Correct sequence to avoid this issue:

  1. Upload the existing state file manually to Azure Blob Storage:
az storage blob upload \
  --account-name <storage-account> \
  --container-name <container> \
  --name <key>.tfstate \
  --file terraform.tfstate

2. Then add the backend block in main.tf:

terraform {
  backend "azurerm" {
    resource_group_name  = "..."
    storage_account_name = "..."
    container_name       = "..."
    key                  = "prod.terraform.tfstate"
  }
}
  • Run the reconfigure command to connect Terraform to the new backend:

  • terraform init

  • Now you’re good to go:

  • terraform plan

Tip: Always move your state before updating backend configs — it avoids migration prompts and keeps your infrastructure consistent.

8 views

More from this blog

C

CloudDecode

10 posts

CloudDecode simplifies cloud & DevOps—covering Azure, AWS, Kubernetes, Terraform, CI/CD & more—with clear guides to help you decode, learn, and build with confidence.