azure-deployment-preflight
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAzure Deployment Preflight Validation
Azure部署预检验证
This skill validates Bicep deployments before execution, supporting both Azure CLI () and Azure Developer CLI () workflows.
azazd此技能在执行前验证Bicep部署,支持Azure CLI () 和Azure Developer CLI () 工作流。
azazdWhen to Use This Skill
何时使用此技能
- Before deploying infrastructure to Azure
- When preparing or reviewing Bicep files
- To preview what changes a deployment will make
- To verify permissions are sufficient for deployment
- Before running ,
azd up, orazd provisioncommandsaz deployment
- 向Azure部署基础架构之前
- 准备或审核Bicep文件时
- 预览部署将做出哪些变更时
- 验证部署权限是否足够时
- 运行、
azd up或azd provision命令之前az deployment
Validation Process
验证流程
Follow these steps in order. Continue to the next step even if a previous step fails—capture all issues in the final report.
按顺序遵循以下步骤。即使上一步失败,也要继续执行下一步——在最终报告中捕获所有问题。
Step 1: Detect Project Type
步骤1:检测项目类型
Determine the deployment workflow by checking for project indicators:
-
Check for azd project: Look forin the project root
azure.yaml- If found → Use azd workflow
- If not found → Use az CLI workflow
-
Locate Bicep files: Find allfiles to validate
.bicep- For azd projects: Check directory first, then project root
infra/ - For standalone: Use the file specified by the user or search common locations (,
infra/, project root)deploy/
- For azd projects: Check
-
Auto-detect parameter files: For each Bicep file, look for matching parameter files:
- (Bicep parameters - preferred)
<filename>.bicepparam - (JSON parameters)
<filename>.parameters.json - or
parameters.jsonin same directoryparameters/<env>.json
通过检查项目标识来确定部署工作流:
-
检查azd项目:在项目根目录中查找
azure.yaml- 如果找到 → 使用azd工作流
- 如果未找到 → 使用Azure CLI工作流
-
定位Bicep文件:找到所有需要验证的文件
.bicep- 对于azd项目:首先检查目录,然后检查项目根目录
infra/ - 对于独立项目:使用用户指定的文件或搜索常见位置(、
infra/、项目根目录)deploy/
- 对于azd项目:首先检查
-
自动检测参数文件:对于每个Bicep文件,查找匹配的参数文件:
- (Bicep参数 - 首选)
<filename>.bicepparam - (JSON参数)
<filename>.parameters.json - 同一目录中的或
parameters.jsonparameters/<env>.json
Step 2: Validate Bicep Syntax
步骤2:验证Bicep语法
Run Bicep CLI to check template syntax before attempting deployment validation:
bash
bicep build <bicep-file> --stdoutWhat to capture:
- Syntax errors with line/column numbers
- Warning messages
- Build success/failure status
If Bicep CLI is not installed:
- Note the issue in the report
- Continue to Step 3 (Azure will validate syntax during what-if)
在尝试部署验证之前,运行Bicep CLI检查模板语法:
bash
bicep build <bicep-file> --stdout需要捕获的内容:
- 带行/列号的语法错误
- 警告消息
- 构建成功/失败状态
如果未安装Bicep CLI:
- 在报告中记录此问题
- 继续执行步骤3(Azure会在what-if期间验证语法)
Step 3: Run Preflight Validation
步骤3:运行预检验证
Choose the appropriate validation based on project type detected in Step 1.
根据步骤1中检测到的项目类型选择合适的验证方式。
For azd Projects (azure.yaml exists)
对于azd项目(存在azure.yaml)
Use to validate the deployment:
azd provision --previewbash
azd provision --previewIf an environment is specified or multiple environments exist:
bash
azd provision --preview --environment <env-name>使用验证部署:
azd provision --previewbash
azd provision --preview如果指定了环境或存在多个环境:
bash
azd provision --preview --environment <env-name>For Standalone Bicep (no azure.yaml)
对于独立Bicep(无azure.yaml)
Determine the deployment scope from the Bicep file's declaration:
targetScope| Target Scope | Command |
|---|---|
| |
| |
| |
| |
Run with Provider validation level first:
bash
undefined从Bicep文件的声明确定部署范围:
targetScope| 目标范围 | 命令 |
|---|---|
| |
| |
| |
| |
首先使用Provider验证级别运行:
bash
undefinedResource Group scope (most common)
资源组范围(最常见)
az deployment group what-if
--resource-group <rg-name>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--resource-group <rg-name>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
az deployment group what-if
--resource-group <rg-name>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--resource-group <rg-name>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
Subscription scope
订阅范围
az deployment sub what-if
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
az deployment sub what-if
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
Management Group scope
管理组范围
az deployment mg what-if
--location <location>
--management-group-id <mg-id>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--location <location>
--management-group-id <mg-id>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
az deployment mg what-if
--location <location>
--management-group-id <mg-id>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--location <location>
--management-group-id <mg-id>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
Tenant scope
租户范围
az deployment tenant what-if
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
**Fallback Strategy:**
If `--validation-level Provider` fails with permission errors (RBAC), retry with `ProviderNoRbac`:
```bash
az deployment group what-if \
--resource-group <rg-name> \
--template-file <bicep-file> \
--validation-level ProviderNoRbacNote the fallback in the report—the user may lack full deployment permissions.
az deployment tenant what-if
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
--location <location>
--template-file <bicep-file>
--parameters <param-file>
--validation-level Provider
**回退策略:**
如果`--validation-level Provider`因权限错误(RBAC)失败,使用`ProviderNoRbac`重试:
```bash
az deployment group what-if \
--resource-group <rg-name> \
--template-file <bicep-file> \
--validation-level ProviderNoRbac在报告中记录回退操作——用户可能缺少完整的部署权限。
Step 4: Capture What-If Results
步骤4:捕获what-if结果
Parse the what-if output to categorize resource changes:
| Change Type | Symbol | Meaning |
|---|---|---|
| Create | | New resource will be created |
| Delete | | Resource will be deleted |
| Modify | | Resource properties will change |
| NoChange | | Resource unchanged |
| Ignore | | Resource not analyzed (limits reached) |
| Deploy | | Resource will be deployed (changes unknown) |
For modified resources, capture the specific property changes.
解析what-if输出以对资源变更进行分类:
| 变更类型 | 符号 | 含义 |
|---|---|---|
| Create | | 将创建新资源 |
| Delete | | 将删除资源 |
| Modify | | 资源属性将变更 |
| NoChange | | 资源未变更 |
| Ignore | | 未分析资源(已达限制) |
| Deploy | | 将部署资源(变更未知) |
对于已修改的资源,捕获具体的属性变更。
Step 5: Generate Report
步骤5:生成报告
Create a Markdown report file in the project root named:
preflight-report.md
Use the template structure from references/REPORT-TEMPLATE.md.
Report sections:
- Summary - Overall status, timestamp, files validated, target scope
- Tools Executed - Commands run, versions, validation levels used
- Issues - All errors and warnings with severity and remediation
- What-If Results - Resources to create/modify/delete/unchanged
- Recommendations - Actionable next steps
在项目根目录中创建一个名为以下名称的Markdown报告文件:
preflight-report.md
使用references/REPORT-TEMPLATE.md中的模板结构。
报告章节:
- 摘要 - 整体状态、时间戳、已验证文件、目标范围
- 已执行工具 - 运行的命令、版本、使用的验证级别
- 问题 - 所有错误和警告,包含严重性和修复建议
- what-if结果 - 将创建/修改/删除/未变更的资源
- 建议 - 可执行的后续步骤
Required Information
所需信息
Before running validation, gather:
| Information | Required For | How to Obtain |
|---|---|---|
| Resource Group | | Ask user or check existing |
| Subscription | All deployments | |
| Location | Sub/MG/Tenant scope | Ask user or use default from config |
| Environment | azd projects | |
If required information is missing, prompt the user before proceeding.
运行验证之前,收集以下信息:
| 信息 | 用于 | 获取方式 |
|---|---|---|
| 资源组 | | 询问用户或检查现有 |
| 订阅 | 所有部署 | |
| 位置 | 订阅/管理组/租户范围 | 询问用户或使用配置中的默认值 |
| 环境 | azd项目 | |
如果缺少所需信息,在继续之前提示用户。
Error Handling
错误处理
See references/ERROR-HANDLING.md for detailed error handling guidance.
Key principle: Continue validation even when errors occur. Capture all issues in the final report.
| Error Type | Action |
|---|---|
| Not logged in | Note in report, suggest |
| Permission denied | Fall back to |
| Bicep syntax error | Include all errors, continue to other files |
| Tool not installed | Note in report, skip that validation step |
| Resource group not found | Note in report, suggest creating it |
有关详细的错误处理指南,请参阅references/ERROR-HANDLING.md。
**核心原则:**即使发生错误,也要继续执行验证。在最终报告中捕获所有问题。
| 错误类型 | 操作 |
|---|---|
| 未登录 | 在报告中记录,建议 |
| 权限拒绝 | 回退到 |
| Bicep语法错误 | 包含所有错误,继续处理其他文件 |
| 未安装工具 | 在报告中记录,跳过该验证步骤 |
| 资源组未找到 | 在报告中记录,建议创建资源组 |
Tool Requirements
工具要求
This skill uses the following tools:
- Azure CLI () - Version 2.76.0+ recommended for
az--validation-level - Azure Developer CLI () - For projects with
azdazure.yaml - Bicep CLI () - For syntax validation
bicep - Azure MCP Tools - For documentation lookups and best practices
Check tool availability before starting:
bash
az --version
azd version
bicep --version此技能使用以下工具:
- Azure CLI () - 建议版本2.76.0+以支持
az--validation-level - Azure Developer CLI () - 用于包含
azd的项目azure.yaml - Bicep CLI () - 用于语法验证
bicep - Azure MCP Tools - 用于文档查找和最佳实践
开始之前检查工具可用性:
bash
az --version
azd version
bicep --versionExample Workflow
示例工作流
- User: "Validate my Bicep deployment before I run it"
- Agent detects → azd project
azure.yaml - Agent finds and
infra/main.bicepinfra/main.bicepparam - Agent runs
bicep build infra/main.bicep --stdout - Agent runs
azd provision --preview - Agent generates in project root
preflight-report.md - Agent summarizes findings to user
- 用户:"在我运行之前验证我的Bicep部署"
- Agent检测到→ azd项目
azure.yaml - Agent找到和
infra/main.bicepinfra/main.bicepparam - Agent运行
bicep build infra/main.bicep --stdout - Agent运行
azd provision --preview - Agent在项目根目录生成
preflight-report.md - Agent向用户总结发现的问题
Reference Documentation
参考文档
- Validation Commands Reference
- Report Template
- Error Handling Guide
- 验证命令参考
- 报告模板
- 错误处理指南