Skip to content

Parameters, expressions, and outputs

Inputs and decorators

Bicep supports strings, integers, booleans, objects, arrays, and user-defined types. Use the smallest meaningful interface. @description explains intent; decorators such as @allowed and @minLength constrain values.

The language example uses a typed string array and a bounded environment:

examples/02-language/main.bicep
targetScope = 'resourceGroup'

@description('Short lowercase naming prefix; callers should also follow service-specific naming rules.')
@minLength(2)
@maxLength(12)
param prefix string = 'learn'

@description('Environment controls sample naming and retention metadata.')
@allowed([
  'dev'
  'test'
  'prod'
])
param environment string = 'dev'

@description('Non-sensitive names used to practice typed arrays and loop expressions.')
param workloads string[] = [
  'web'
  'worker'
]

var normalizedPrefix = toLower(prefix)
var retentionDays = environment == 'prod' ? 90 : 30
var workloadNames = [for workload in workloads: '${normalizedPrefix}-${environment}-${workload}']

@description('Calculated names; this example does not create Azure workloads.')
output workloadNames array = workloadNames

@description('Learning metadata only, not a deployed retention policy.')
output retentionDays int = retentionDays

Follow the expression flow

  1. prefix is normalized by toLower.
  2. A conditional selects prod retention metadata of 90, otherwise 30.
  3. A loop derives one name per workload.
  4. Outputs expose the calculated names and integer.

No storage retention policy or workload resource is deployed. This distinction matters: a descriptive output alone does not configure a service. Compile with:

az bicep build --file examples/02-language/main.bicep --stdout

Expected JSON contains constraints, expressions, and an empty resource collection. The compiler checks types; ARM evaluates parameter-dependent results. With defaults, evaluation produces dev names and 30.

Parameter files and evaluation time

.bicepparam files use using to bind an actual template, gaining typed parameter checking. They are not JSON files and not secret stores. Our foundation reads BICEP_STORAGE_NAME through readEnvironmentVariable at parameter compilation time; ARM does not look up the local variable. Set it explicitly before build/deployment.

Validation boundaries

Storage-name length decorators do not enforce lowercase characters or global uniqueness. A string CIDR is not proof of network containment or no overlap. Type safety and live service validation complement, rather than replace, one another.

Use @secure() for sensitive parameters when needed; never emit secrets through outputs or commit their values.

Exercise: predict the language output with prefix = 'TEAM', environment = 'prod', and one workload. Explain which checks happen offline and which values are evaluated by ARM.