Bicep Code Best Practices

Bicep Code Best Practices

Sets Infrastructure as Code rules for an AI assistant writing Azure Bicep: naming, parameters with descriptions, modules, verified modules, parameter files and linting.


description: 'Infrastructure as Code with Bicep'
applyTo: '**/.bicep, **/.bicepparam, **/bicepconfig.json'


Naming Conventions

  • When writing Bicep code, use lowerCamelCase for all names (variables, parameters, resources)
  • Use resource type descriptive symbolic names (e.g., 'storageAccount' not 'storageAccountName')
  • Avoid using 'name' in a symbolic name as it represents the resource, not the resource's name
  • Avoid distinguishing variables and parameters by the use of suffixes

Structure and Declaration

  • Always declare parameters at the top of files with @description decorators
  • Use latest stable API versions for all resources
  • Use descriptive @description decorators for all parameters
  • Specify minimum and maximum character length for naming parameters

Parameters

  • Set default values that are safe for test environments (use low-cost pricing tiers)
  • Use @allowed decorator sparingly to avoid blocking valid deployments
  • Use parameters for settings that change between deployments
  • Use .bicepparam files with a using declaration when supported by the project's tool versions; retain JSON parameter files where required. Keep secrets out of parameter files and use supported secret references.
  • Use supported user-defined object types for structured parameter contracts when they make validation clearer.

Modules and Validation

  • Prefer an appropriate Azure Verified Module when it meets the project's requirements, and reference a specific module version. Preserve existing module versions during unrelated changes.
  • Respect the project's Bicep CLI version and bicepconfig.json linter settings. Run the project's Bicep build/lint checks before deployment, and resolve diagnostics rather than disabling rules globally.

Variables

  • Variables automatically infer type from the resolved value
  • Use variables to contain complex expressions instead of embedding them directly in resource properties

Resource References

  • Use symbolic names for resource references instead of reference() or resourceId() functions
  • Create resource dependencies through symbolic names (resourceA.id) not explicit dependsOn
  • For accessing properties from other resources, use the 'existing' keyword instead of passing values through outputs

Resource Names

  • Use template expressions with uniqueString() to create meaningful and unique resource names
  • Add prefixes to uniqueString() results since some resources don't allow names starting with numbers

Child Resources

  • Avoid excessive nesting of child resources
  • Use parent property or nesting instead of constructing resource names for child resources

Security

  • Never include secrets or keys in outputs
  • Use resource properties directly in outputs (e.g., storageAccount.properties.primaryEndpoints)

Documentation

  • Include helpful // comments within your Bicep files to improve readability

References

  • [Bicep modules and Azure Verified Modules](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/modules)
  • [Bicep parameter files](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/parameter-files)
  • [Bicep linter](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/linter)

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…