|
Scenario
|
State status
|
Should previous state be restored?
|
Correct recovery approach
|
|---|---|---|---|
|
Terraform apply fails completely. Resources are not created.
|
State unchanged
|
No
|
Revert code and run Terraform plan.
|
|
Apply partially succeeds, In this case, some resources are created.
|
State partially updated but accurate
|
No
|
Revert code and rerun Terraform apply.
|
|
Apply crashes during state write.
|
State corrupted or unreadable
|
Yes
|
Restore the previous blob version and rerun Terraform.
|
|
Apply succeeds but deployment must be undone.
|
State valid
|
No
|
Revert code and rerun Terraform apply.
|
|
Component
|
Status
|
|---|---|
|
Code
|
Contains new resource
|
|
State
|
Unchanged
|
|
Azure
|
No resource created
|
Code: gpt-5-nano deployment added
State: V1 (unchanged)
Azure: resource does not exist
#if using git...
git checkout <earlier_branch/earlier_tag>
terraform plan -var-file=infra.tfvars
|
Component
|
Status
|
|---|---|
|
Code
|
Contains resource1, resource2, resource3
|
|
State
|
Contains resource1 and resource2
|
|
Azure
|
resource1 and resource2 exist, resource3 was not created
|
Code: resource1, resource2, resource3
State: resource1, resource2
Azure: resource1, resource2
terraform apply -var-file=infra.tfvars
|
Component
|
Status
|
|---|---|
|
State
|
resource1, resource2, resource3
|
|
Azure
|
resource1, resource2, resource3
|
#if using git...
git checkout <earlier_branch/earlier_tag>
terraform apply -var-file=infra.tfvars
|
Component
|
Status
|
|---|---|
|
Code
|
resource1 and resource2 removed
|
|
State
|
resource1 and resource2 exist
|
|
Azure
|
resource1 and resource2 exist
|
- destroy resource1
- destroy resource2
|
Component
|
Status
|
|---|---|
|
State
|
clean
|
|
Azure
|
resource1 and resource2 removed
|
|
Component
|
Status
|
|---|---|
|
Code
|
May contain new resources
|
|
State
|
Corrupted or unreadable
|
|
Azure
|
Resources may or may not exist
|
terraform plan -var-file=infra.tfvars
╷
│ Error: Unsupported state file format
│
│ The version in the state file is string. A positive whole number is required.
╵
╷
│ Error: Unsupported state file format
│
│ The state file does not have a "version" attribute, which is required to identify the format version.
OR
$ terraform plan -var-file=infra.tfvars
│ Error: Unsupported state file format
│
│ The state file could not be parsed as JSON: syntax error at
│ byte offset 7805.
terraform plan -var-file=infra.tfvars
╷
│ Error: Unsupported state file format
│
│ The version in the state file is string. A positive whole number is required.
╵
╷
│ Error: Unsupported state file format
│
│ The state file does not have a "version" attribute, which is required to identify the format version.
OR
$ terraform plan -var-file=infra.tfvars
│ Error: Unsupported state file format
│
│ The state file could not be parsed as JSON: syntax error at
│ byte offset 7805.
az storage blob list \
--container-name <container_name>\
--account-name <storage_account_name> \
--include v \
--auth-mode login \
--query "[?name=='terraform.tfstate'].{name:name, Version:versionId, Modified:properties.lastModified}" \
--output table
|
Name
|
Version
|
Modified
|
|---|---|---|
|
terraform.tfstate
|
2026-03-13T11:00:00.0000000Z
|
2026-03-13T11:00:00
|
|
terraform.tfstate
|
2026-03-13T11:05:00.0000000Z
|
2026-03-13T11:05:00
|
az storage blob download \
--container-name <container_name> \
--account-name <storage_account_name> \
--name terraform.tfstate \
--version-id <version_id> \
--file recovered-state.json \
--auth-mode login
az storage blob upload \
--container-name <container_name> \
--account-name <storage_account_name> \
--name terraform.tfstate \
--file recovered-state.json \
--overwrite \
--auth-mode login
az storage blob list \
--container-name <container_name>\
--account-name <storage_account_name> \
--include v \
--auth-mode login \
--query "[?name=='terraform.tfstate'].{name:name, Version:versionId, Modified:properties.lastModified}" \
--output table
|
Version
|
Description
|
|---|---|
|
V1
|
Original valid state
|
|
V2
|
Corrupted state
|
|
V3
|
Restored valid state
|
|
Test step
|
Expected outcome
|
|---|---|
|
Corrupt state file
|
Terraform fails to read state
|
|
Check blob versions
|
Previous state version exists
|
|
Download valid version
|
Valid JSON state retrieved
|
|
Restore state file
|
Blob replaced successfully
|
|
Run Terraform plan
|
Terraform fully operational
|
|
Component
|
Status
|
|---|---|
|
Code
|
Contains gpt-5-nano
|
|
State
|
Contains gpt-5-nano
|
|
Azure
|
gpt-5-nano exists
|
#if using git...
git checkout <earlier_branch/earlier_tag>
terraform apply -var-file=infra.tfvars
│Error: Error acquiring the state lock
│ Error message: state blob is already locked
│ Lock Info:
│ ID: 47befb15-5e0e-908e-d1cd-298e3c723f3d
│ Path: tfstate/infra.tfstate
│ Operation: OperationTypePlan
│ Who: user@machine
│ Version: 1.14.0
│ Created: 2026-04-09 07:02:45 +0000 UTC
az storage blob lease break \
--account-name "<storage-account>" \
--container-name "<container>" \
--blob-name "<state-file>.tfstate" \
--auth-mode login
│ Error: creating Private Endpoint: Put "https://management.azure.com/...":
│ net/http: TLS handshake timeout
│ Error: creating AKS Cluster: HTTP response was nil; connection may have been reset
│ Error: context deadline exceeded (Client.Timeout exceeded while awaiting headers)
$env:ARM_CLIENT_TIMEOUT_SECONDS = "3600"
terraform apply -var-file="infra.tfvars"
│ Error: a resource with the ID "/subscriptions/xxx/resourceGroups/my-rg/providers/
│ Microsoft.ContainerService/managedClusters/my-cluster" already exists - to be
│ managed via Terraform this resource needs to be imported into the State.
│
│ with module.aks.azurerm_kubernetes_cluster.aks,
│ on ../../modules/aks/main.tf line 13, in resource "azurerm_kubernetes_cluster" "aks":
│ 13: resource "azurerm_kubernetes_cluster" "aks" {
terraform import -var-file="infra.tfvars" \
"module.aks.azurerm_kubernetes_cluster.aks" \
"/subscriptions/xxx/resourceGroups/my-rg/providers/Microsoft.ContainerService/managedClusters/my-cluster"
│ Error: creating Deployment: unexpected status 400 (400 Bad Request) with error:
│ InsufficientQuota: This operation require 10000 new capacity in quota
│ One Thousand Tokens Per Minute - gpt-5-mini - DataZoneStandard, which is bigger
│ than the current available capacity 3650. The current quota usage is 350 and
│ the quota limit is 4000.
{"error": {"code": "403", "message": "Traffic is not from an approved private endpoint."}}
az network private-endpoint show \
--resource-group "<rg>" \
--name "<pe-name>" \
--query "privateLinkServiceConnections[0].privateLinkServiceConnectionState.status"
kubectl run dns-test --image=busybox --rm -it --restart=Never -- \
nslookup <account-name>.openai.azure.com
│ Error: deleting Deployment: unexpected status 409 (Conflict) with error:
│ DeploymentInUse: The deployment 'gpt-5-mini-2025-08-07-spillover' cannot be
│ deleted because it is referenced by deployment 'gpt-5-mini-2025-08-07' as
│ spillover deployment.
terraform destroy \
-target="module.cognitive_deployment-gpt5-mini.azapi_resource.deployment_with_spillover[0]" \
-var-file="infra.tfvars"
│ Error: building AzureRM Client: obtain subscription() from Azure CLI:
│ parsing json result from the Azure CLI: waiting for the Azure CLI:
│ exit status 1: ERROR: Please run 'az login' to setup account.
│ Error: obtaining Authorization Token: AADSTS700024: Client assertion is not
│ within its valid time range.
│ Error: Subscription not found: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
│ Error: deleting Resource Group: the Resource Group was not found
│
│ Resource Group Name: "my-rg"