Allow querying of parameter decorators within bicep
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
Bicep documentation shows deployment() returning the full object, but templates can only reference a limited range of members. In particular, the properties.parameters collection is absent which is different and a loss from ARM templates. ```bicep decompile``` correctly processes ARM templates that uses these references, but then can't deploy them 😬
To permit data re-use/de-duplication/DRY, we want to re-use the ```@allowed``` decorator array within the template. Our most common pattern is to generate an index for the parameter used from the allowed values:
```Bicep
@allowed([
'production'
'testing'
'development'
])
param environment string
var environmentValues = deployment().properties.parameters.environment.allowedValues
var environmentIndex = indexOf(environmentValues, environment)
output environmentInfo object = {
environment: environment
environmentIndex: environmentIndex
}
```
ARM Template version that does work:
```JSON
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"type": "string",
"allowedValues": [
"production",
"testing",
"development"
]
}
},
"variables": {
"environmentValues": "[deployment().properties.template.parameters.environment.allowedValues]",
"environmentIndex": "[indexOf(variables('environmentValues'), parameters('environment'))]"
},
"resources": [],
"outputs": {
"environmentInfo": {
"type": "object",
"value": {
"environment": "[parameters('environment')]",
"environmentIndex": "[variables('environmentIndex')]"
}
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.