Bicep - Do you use User-defined Data Types?
Updated by Brady Stroud [SSW] 1 year ago. See history
User-defined data types in Bicep allow you to create custom data structures for better code organization and type safety. They enhance reusability, abstraction, and maintainability within projects. When creating a cloud resource, numerous parameters are typically required for configuration and customization. Organizing and naming these parameters effectively is increasingly important.
@allowed(['Basic', 'Standard'])param skuName string = 'Basic'@allowed([5, 10, 20, 50, 100])param skuCapacity int = 5param skuSizeInGB int = 2
❌ Figure: Bad example - Relying on parameter prefixes and order leads to unclear code, high complexity, and increased maintenance effort
param sku object
❌ Figure: Bad example - When declaring a parameter as an untyped object, bicep cannot validate the object's properties and values at compile time, risking runtime errors.
// User-defined data typetype skuConfig = {name: 'Basic' | 'Standard'capacity: 5 | 10 | 20 | 50 | 100sizeInGB: int}param sku skuConfig = {name: 'Basic'capacity: 5sizeInGB: 2}
✅ Figure: Good example - User-defined data type provides type safety, enhanced readability and making maintenance easier