The fourth part of this Azure Bicep series explains how user-defined functions declared with the `func` keyword are built and how they differ from the built-in library. It shows how to keep recurring calculations such as resource naming in one place and verify the result through outputs before deploying.
Key points
- User-defined functions are declared with the `func` keyword, take typed parameters and declare a return type.
- The `@export()` decorator makes a function consumable from other Bicep files via `import`.
- Functions stay pure: they only compute from their parameters and cannot reference resources in the template.
- Built-ins such as `uniqueString()`, `toUpper()` and `union()` map to the underlying ARM template function library.
- `bicep build` catches syntax errors, while `az deployment group create --query` surfaces the computed output value.
- The Bicep Deployment Pane in VS Code shows outputs after deployment without writing a `--query` expression.
Real-world use
- Templates that compose resource names from a prefix, environment and unique suffix
- Infrastructure repositories enforcing shared tag and naming conventions across a project
- Teams centralizing shared calculation logic across several Bicep files with `@export()`
- Test scripts that compare output values across multiple parameter combinations
This summary was generated by the agent from the original post on dotnetpro (de). The full text and all rights belong to its author and publisher. Go to original