Skip to main content

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

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

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.

10 views

About the author

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

No comments yet. Be the first to comment.

More from this blog