AI skill: validate Bicep template compatibility with azd local preflight snapshot
- Dominant language
- Go
- Stars
- 569
- Forks
- 364
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 136
Description
## Problem
Bicep template authors may unknowingly use patterns that prevent `bicep snapshot` from succeeding, which causes azd's local preflight checks (AI quota validation, reserved resource names, etc.) to be silently skipped. The most common problematic pattern is using non-null assertions (`!`) on module outputs:
```bicep
// ❌ This causes snapshot to fail — module outputs are null at snapshot time
principalId: myModule.outputs.systemAssignedMIPrincipalId!
// ✅ Use null-coalescing with a placeholder instead
principalId: myModule.outputs.?systemAssignedMIPrincipalId ?? '00000000-0000-0000-0000-000000000000'
```
## Proposed Solution
Create an AI skill (Copilot skill) that helps template authors validate whether their Bicep template can generate a snapshot for azd preflight checks. The skill should:
1. **Analyze the Bicep template** for patterns known to cause snapshot failures:
- Non-null assertions (`!`) on module outputs
- `reference()` calls to resources whose properties are only available after deployment
- Other patterns that produce `TemplateValidationException` during snapshot
2. **Recommend fixes** — suggest null-coalescing (`??`), safe navigation (`?`), or conditional expressions that allow the snapshot to succeed while preserving correct runtime behavior
3. **Run `bicep snapshot`** on the template and report whether it succeeds, providing actionable guidance if it fails
## Known Patterns That Cause Failures
| Pattern | Why it fails | Fix |
|---|---|---|
| `module.outputs.prop!` | Non-null assertion on unknown output | Use `module.outputs.?prop ?? placeholder` |
| `reference('res').prop` in nested module params | Runtime-only value | Use conditional or placeholder |
## Related
- Upstream: [Azure/bicep#18822](https://github.com/Azure/bicep/issues/18822)
- Investigation: #7986
- User warning: #8171
- Telemetry: #8172
Contributor guide
Assessment
This issue has not been assessed yet.