Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy applications and infrastructure to Azure using Copilot-guided workflows and Azure MCP
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/recipes/terraform/README.md
1# Terraform Deploy Recipe23Deploy to Azure using Terraform.45## Prerequisites67- Terraform CLI installed8- `.azure/deployment-plan.md` exists with status `Validated`9- Terraform initialized (`terraform init`)10- Plan validated (`terraform plan`)11- **Subscription and location confirmed** → See [Pre-Deploy Checklist](../../pre-deploy-checklist.md)1213## Workflow1415| Step | Task | Command |16|------|------|---------|17| 1 | **[Pre-deploy checklist](../../pre-deploy-checklist.md)** | Confirm subscription/location with user |18| 2 | Select workspace | `terraform workspace select <env>` |19| 3 | Apply | `terraform apply tfplan` |20| 4 | Get outputs | `terraform output` |21| 5 | Deploy app | Service-specific commands |22| 6 | **Report** | Present deployed endpoint URLs to the user — see [Verification](verify.md) |2324## Deployment Commands2526### Apply with Plan File (Recommended)2728```bash29terraform plan -out=tfplan30terraform apply tfplan31```3233### Auto-Approve (CI/CD)3435```bash36terraform apply -auto-approve37```3839### With Variables4041```bash42terraform apply \43-var="environment=prod" \44-var="location=westus2" \45-auto-approve46```4748### Target Specific Resource4950```bash51terraform apply -target=azurerm_container_app.api52```5354## Get Outputs5556```bash57terraform output58terraform output -json59terraform output api_url60```6162## Application Deployment6364After infrastructure is deployed:6566### Container Apps (Two-Phase Deployment)6768Container Apps with ACR require a two-phase flow because the app image doesn't exist in ACR during initial `terraform apply`. See the **azure-prepare** skill's `references/services/container-apps/terraform.md` for the full pattern.6970```bash71ACR_NAME=$(terraform output -raw acr_name)72ACR_SERVER=$(terraform output -raw acr_login_server)73APP_NAME=$(terraform output -raw container_app_name)74RG_NAME=$(terraform output -raw resource_group_name)7576# 1. Build and push the application image to ACR77az acr build --registry $ACR_NAME --image myapp:latest ./src/api7879# 2. Configure the registry/identity link (managed identity, no passwords)80az containerapp registry set \81--name $APP_NAME \82--resource-group $RG_NAME \83--server $ACR_SERVER \84--identity system8586# 3. Update the Container App to use the real image87az containerapp update \88--name $APP_NAME \89--resource-group $RG_NAME \90--image $ACR_SERVER/myapp:latest91```9293**PowerShell:**94```powershell95$AcrName = terraform output -raw acr_name96$AcrServer = terraform output -raw acr_login_server97$AppName = terraform output -raw container_app_name98$RgName = terraform output -raw resource_group_name99100az acr build --registry $AcrName --image myapp:latest ./src/api101102az containerapp registry set `103--name $AppName `104--resource-group $RgName `105--server $AcrServer `106--identity system107108az containerapp update `109--name $AppName `110--resource-group $RgName `111--image "$AcrServer/myapp:latest"112```113114> ⚠️ **Warning:** Step 2 requires the `AcrPull` role assignment to have propagated (1–5 minutes). If the update fails, wait and retry. See the [RBAC propagation health check](../../pre-deploy-checklist.md#container-apps--acr--pre-deploy-rbac-health-check).115116## References117118- [Verification steps](./verify.md)119- [Error handling](./errors.md)120