Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This diagnostic occurs when you try to use a for-expression in a location where Bicep doesn't allow it.
For-expressions can be used in a few specific locations in Bicep. You can use them when defining resources, modules, variables, and outputs. You can also use them inside resources and modules when you set their properties. If you place a for-expression directly inside an unsupported location, such as an object literal, Bicep throws BCP138 because the syntax isn't supported there.
Description
For-expressions aren't supported in this context. For-expressions may be used as values of resource, module, variable, and output declarations, or values of resource and module properties.
Level
Error
Solution
The solution is to move the for-expression into the supported location.
Examples
The following example has a for loop inside the disks property of an object literal. Bicep doesn't allow for-expressions in this context.
param diskCount int = 5
var vmConfiguration = {
description: 'Virtual machine configuration'
dataDisks: [
for diskIndex in range(0, diskCount): {
name: 'dataDisk${diskIndex + 1}'
sizeGB: 1
index: diskIndex
}
]
}
output vmConfig object = vmConfiguration
The solution is to move the for-expression into its own variable and then references that variable inside the object:
param diskCount int = 5
var dataDiskArray = [
for diskIndex in range(0, diskCount): {
name: 'dataDisk${diskIndex + 1}'
sizeGB: 1
index: diskIndex
}
]
var vmConfiguration = {
description: 'Virtual machine configuration'
dataDisks: dataDiskArray
}
output vmConfig object = vmConfiguration
Next steps
For more information about Bicep diagnostics, see Bicep core diagnostics.