Bicep Best Practices
What you'll learn: How to write clean, maintainable, and scalable Bicep code by following industry-standard naming conventions, organization patterns, and linting rules.
Why Best Practices Matter
Think of Bicep code like a recipe book that multiple chefs will use. Without consistent naming, clear organization, and quality checks, your infrastructure code becomes hard to understand, difficult to maintain, and error-prone at scale.
Core Best Practices
Naming Conventions
Use descriptive, consistent names for parameters, variables, and resources. Prefix parameters with their type context (like storageAccountName not just name). Keep resource symbolic names clear: storageAccount rather than sa1.
Code Organization
Group related resources together logically. Place parameters at the top, followed by variables, then resources, and outputs at the bottom. This predictable structure helps anyone quickly navigate your templates.
Use Modules
Break large templates into reusable modules. Instead of one massive 500-line file, create focused modules for networking, storage, or compute that can be composed together.
Leverage Linting
The Bicep CLI includes built-in linting that catches common mistakes before deployment. Run bicep build regularly to validate syntax and detect issues like unused parameters or missing required properties.
Maintain at Scale
Use consistent file naming (main.bicep, modules/network.bicep). Version your modules when storing them in registries. Document parameters with @description decorators so others understand their purpose without reading the entire template.
Resource Dependencies
Let Bicep infer dependencies through symbolic references rather than explicit dependsOn whenever possible—it's cleaner and less error-prone.
Key Takeaway: Following Bicep best practices—clear naming, logical organization, modular design, and regular linting—transforms your infrastructure code from fragile scripts into maintainable, team-friendly assets.