# 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:

```plaintext
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`](http://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:
    

```plaintext
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`](http://main.tf):

```plaintext
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.
