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

https://abhaypatil001.github.io/abhay-portfolio/
Search for a command to run...

https://abhaypatil001.github.io/abhay-portfolio/
No comments yet. Be the first to comment.
Introduction User access management is one of the most fundamental responsibilities in any infrastructure environment, yet it is often handled in an ad hoc and manual way. In many organizations, espec

Managing sensitive credentials like API keys across multiple GitHub repositories is challenging. It leads to duplicate secrets, a lack of versioning, and potential inconsistencies between environments. The solution is to use HashiCorp Vault Secrets o...

Introduction DevOps engineers today spend countless hours context-switching between dashboards, logs, cloud consoles, and documentation. Traditional AI tools like ChatGPT are great at answering questions, but they lack direct access to your infrastru...

When working with GitHub Actions, you may face situations where multiple workflow runs overlap, consume unnecessary resources, or even cause conflicts in deployment. This is where concurrency comes into play. Concurrency in GitHub Actions allows you ...

When teams scale, managing workflows across multiple repositories becomes more complex. Each project often shares common configuration values, cloud credentials, or deployment secrets. Instead of duplicating these across repositories, GitHub provides...

CloudDecode
11 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.
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:
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.