Deployment Workflow
To deploy a storage account and App Service using an ARM template, follow these sequential steps. This assumes you have the Azure CLI installed and are authenticated via az login.
1. Prerequisites and Resource Group Creation
First, define your variables to ensure consistency across commands. The location (e.g., eastus) is critical because it determines the physical data center where your resources reside, affecting latency, regional availability of specific SKUs, and compliance with data residency laws.
# Define variables
RG_NAME="MyDemoRG"
LOCATION="eastus"
TEMPLATE_FILE="azuredeploy.json"
PARAMS_FILE="azuredeploy.parameters.json"
DEPLOYMENT_NAME="DemoDeployment"
Create the resource group:
az group create --name $RG_NAME --location $LOCATION
2. Template Validation and Deployment
Before committing resources, validate the template to catch syntax errors or invalid parameter values without incurring costs.
az deployment group validate --resource-group $RG_NAME --template-file $TEMPLATE_FILE --parameters $PARAMS_FILE
If validation succeeds, execute the deployment. Use --verbose to see detailed progress in the terminal.
az deployment group create --resource-group $RG_NAME --template-file $TEMPLATE_FILE --parameters $PARAMS_FILE --name $DEPLOYMENT_NAME --verbose
3. Verification of Success
Checking the CLI output is insufficient for automation. You must verify the provisioningState of the deployment object.
az deployment group show --resource-group $RG_NAME --name $DEPLOYMENT_NAME --query properties.provisioningState -o tsv
The expected output is Succeeded. If the output is Failed, inspect the error details using:
az deployment group show --resource-group $RG_NAME --name $DEPLOYMENT_NAME --query properties.error
You can also confirm the expected resources exist:
az resource list --resource-group $RG_NAME --output table
4. Cleanup
To avoid ongoing costs, delete the entire resource group. This is the most efficient way to remove all associated resources (Storage Account, App Service, and App Service Plan) simultaneously.
az group delete --name $RG_NAME --yes --no-wait
Verify cleanup by attempting to show the group; it should return a ResourceGroupNotFound error.
az group show --name $RG_NAME
Error Handling and Rollback
Debug Output
If a deployment hangs or fails with a generic error, append --debug to your command. This provides the raw HTTP request/response logs between the CLI and the Azure Resource Manager API.
Rollback Strategy
ARM templates do not have a built-in "undo" button for a failed deployment. You have two primary options:
- Re-deploy: Fix the template or parameters and run the
create command again. ARM is idempotent, meaning it will only update the resources that need changing. - Manual Cleanup: If the failure left the environment in an inconsistent state, delete the resource group and start from step 1.
Note: To provide more specific rollback advice, please specify if you are using a CI/CD pipeline (like GitHub Actions or Azure DevOps) or deploying manually from a local terminal.