1
---
2
name: azure-deployment-preflight
3
description: 'Performs comprehensive preflight validation of Bicep deployments to Azure, including template syntax validation, what-if analysis, and permission checks. Use this skill before any deployment to Azure to preview changes, identify potential issues, and ensure the deployment will succeed. Activate when users mention deploying to Azure, validating Bicep files, checking deployment permissions, previewing infrastructure changes, running what-if, or preparing for azd provision.'
4
---
5
6
# Azure Deployment Preflight Validation
7
8
This skill validates Bicep deployments before execution, supporting both Azure CLI (`az`) and Azure Developer CLI (`azd`) workflows.
9
10
## When to Use This Skill
11
12
- Before deploying infrastructure to Azure
13
- When preparing or reviewing Bicep files
14
- To preview what changes a deployment will make
15
- To verify permissions are sufficient for deployment
16
- Before running `azd up`, `azd provision`, or `az deployment` commands
17
18
## Validation Process
19
20
Follow these steps in order. Continue to the next step even if a previous step fails—capture all issues in the final report.
21
22
### Step 1: Detect Project Type
23
24
Determine the deployment workflow by checking for project indicators:
25
26
1. **Check for azd project**: Look for `azure.yaml` in the project root
27
- If found → Use **azd workflow**
28
- If not found → Use **az CLI workflow**
29
30
2. **Locate Bicep files**: Find all `.bicep` files to validate
31
- For azd projects: Check `infra/` directory first, then project root
32
- For standalone: Use the file specified by the user or search common locations (`infra/`, `deploy/`, project root)
33
34
3. **Auto-detect parameter files**: For each Bicep file, look for matching parameter files:
35
- `<filename>.bicepparam` (Bicep parameters - preferred)
36
- `<filename>.parameters.json` (JSON parameters)
37
- `parameters.json` or `parameters/<env>.json` in same directory
38
39
### Step 2: Validate Bicep Syntax
40
41
Run Bicep CLI to check template syntax before attempting deployment validation:
42
43
```bash
44
bicep build <bicep-file> --stdout
45
```
46
47
**What to capture:**
48
- Syntax errors with line/column numbers
49
- Warning messages
50
- Build success/failure status
51
52
**If Bicep CLI is not installed:**
53
- Note the issue in the report
54
- Continue to Step 3 (Azure will validate syntax during what-if)
55
56
### Step 3: Run Preflight Validation
57
58
Choose the appropriate validation based on project type detected in Step 1.
59
60
#### For azd Projects (azure.yaml exists)
61
62
Use `azd provision --preview` to validate the deployment:
63
64
```bash
65
azd provision --preview
66
```
67
68
If an environment is specified or multiple environments exist:
69
```bash
70
azd provision --preview --environment <env-name>
71
```
72
73
#### For Standalone Bicep (no azure.yaml)
74
75
Determine the deployment scope from the Bicep file's `targetScope` declaration:
76
77
| Target Scope | Command |
78
|--------------|---------|
79
| `resourceGroup` (default) | `az deployment group what-if` |
80
| `subscription` | `az deployment sub what-if` |
81
| `managementGroup` | `az deployment mg what-if` |
82
| `tenant` | `az deployment tenant what-if` |
83
84
**Run with Provider validation level first:**
85
86
```bash
87
# Resource Group scope (most common)
88
az deployment group what-if \
89
--resource-group <rg-name> \
90
--template-file <bicep-file> \
91
--parameters <param-file> \
92
--validation-level Provider
93
94
# Subscription scope
95
az deployment sub what-if \
96
--location <location> \
97
--template-file <bicep-file> \
98
--parameters <param-file> \
99
--validation-level Provider
100
101
# Management Group scope
102
az deployment mg what-if \
103
--location <location> \
104
--management-group-id <mg-id> \
105
--template-file <bicep-file> \
106
--parameters <param-file> \
107
--validation-level Provider
108
109
# Tenant scope
110
az deployment tenant what-if \
111
--location <location> \
112
--template-file <bicep-file> \
113
--parameters <param-file> \
114
--validation-level Provider
115
```
116
117
**Fallback Strategy:**
118
119
If `--validation-level Provider` fails with permission errors (RBAC), retry with `ProviderNoRbac`:
120
121
```bash
122
az deployment group what-if \
123
--resource-group <rg-name> \
124
--template-file <bicep-file> \
125
--validation-level ProviderNoRbac
126
```
127
128
Note the fallback in the report—the user may lack full deployment permissions.
129
130
### Step 4: Capture What-If Results
131
132
Parse the what-if output to categorize resource changes:
133
134
| Change Type | Symbol | Meaning |
135
|-------------|--------|---------|
136
| Create | `+` | New resource will be created |
137
| Delete | `-` | Resource will be deleted |
138
| Modify | `~` | Resource properties will change |
139
| NoChange | `=` | Resource unchanged |
140
| Ignore | `*` | Resource not analyzed (limits reached) |
141
| Deploy | `!` | Resource will be deployed (changes unknown) |
142
143
For modified resources, capture the specific property changes.
144
145
### Step 5: Generate Report
146
147
Create a Markdown report file in the **project root** named:
148
- `preflight-report.md`
149
150
Use the template structure from [references/REPORT-TEMPLATE.md](references/REPORT-TEMPLATE.md).
151
152
**Report sections:**
153
1. **Summary** - Overall status, timestamp, files validated, target scope
154
2. **Tools Executed** - Commands run, versions, validation levels used
155
3. **Issues** - All errors and warnings with severity and remediation
156
4. **What-If Results** - Resources to create/modify/delete/unchanged
157
5. **Recommendations** - Actionable next steps
158
159
## Required Information
160
161
Before running validation, gather:
162
163
| Information | Required For | How to Obtain |
164
|-------------|--------------|---------------|
165
| Resource Group | `az deployment group` | Ask user or check existing `.azure/` config |
166
| Subscription | All deployments | `az account show` or ask user |
167
| Location | Sub/MG/Tenant scope | Ask user or use default from config |
168
| Environment | azd projects | `azd env list` or ask user |
169
170
If required information is missing, prompt the user before proceeding.
171
172
## Error Handling
173
174
See [references/ERROR-HANDLING.md](references/ERROR-HANDLING.md) for detailed error handling guidance.
175
176
**Key principle:** Continue validation even when errors occur. Capture all issues in the final report.
177
178
| Error Type | Action |
179
|------------|--------|
180
| Not logged in | Note in report, suggest `az login` or `azd auth login` |
181
| Permission denied | Fall back to `ProviderNoRbac`, note in report |
182
| Bicep syntax error | Include all errors, continue to other files |
183
| Tool not installed | Note in report, skip that validation step |
184
| Resource group not found | Note in report, suggest creating it |
185
186
## Tool Requirements
187
188
This skill uses the following tools:
189
190
- **Azure CLI** (`az`) - Version 2.76.0+ recommended for `--validation-level`
191
- **Azure Developer CLI** (`azd`) - For projects with `azure.yaml`
192
- **Bicep CLI** (`bicep`) - For syntax validation
193
- **Azure MCP Tools** - For documentation lookups and best practices
194
195
Check tool availability before starting:
196
```bash
197
az --version
198
azd version
199
bicep --version
200
```
201
202
## Example Workflow
203
204
1. User: "Validate my Bicep deployment before I run it"
205
2. Agent detects `azure.yaml` → azd project
206
3. Agent finds `infra/main.bicep` and `infra/main.bicepparam`
207
4. Agent runs `bicep build infra/main.bicep --stdout`
208
5. Agent runs `azd provision --preview`
209
6. Agent generates `preflight-report.md` in project root
210
7. Agent summarizes findings to user
211
212
## Reference Documentation
213
214
- [Validation Commands Reference](references/VALIDATION-COMMANDS.md)
215
- [Report Template](references/REPORT-TEMPLATE.md)
216
- [Error Handling Guide](references/ERROR-HANDLING.md)
217