bicep
bicep copied to clipboard
@allowed decorator for param should confirm default value after any expression is evaluated
Bicep version Bicep CLI version 0.10.61 (8f44805506)
Describe the bug Assuming a bicep template is deployed into a ResourceGroup located in eastus, the following code snippet should set the default value of locationName to 'eastus', but allow override to the allowed set of alternate regions.
@description('Location Name')
@allowed([
'eastus'
'eastus2'
'westus'
'westus2'
'centralus'
])
param locationName string = resourceGroup().location
Instead, we get this error, indicating the value is likely checked against the list of allowed values before it is evaluated to 'eastus', which is one of the allowed values and should be valid.
Error BCP027: The parameter expects a default value of type "'centralus' | 'eastus' | 'eastus2' | 'westus' | 'westus2'" but provided value is of type "string".
I think it's reasonable to want to both use as a default the Resource Group location, and then limit what alternatives can be chosen. Meaning, this code should work. I think any other variants of expressions allowed in a default value should also be evaluated to the final string result before the comparison with the @allowed list is performed.
To Reproduce Steps to reproduce described above - this is simple to reproduce.
Additional context N/A
You can work around this using the any() function like this:
@description('Location Name')
@allowed([
'eastus'
'eastus2'
'westus'
'westus2'
'centralus'
])
param locationName string = any(resourceGroup().location)
@majastrz You agree that's a bit of a hack, though, right? (it was certainly not documented nor intuitive.)
I also think that it should be possible to indicate the @allowed set is matched in a case-insensitive way, as in many cases, Microsoft has names which show up capitalized or uncapitalized in different contexts.
Case in point this very example - these location names often appear as 'EastUS' in one setting or in documentation, but 'eastus' in others, as in what's returned from the resourceGroup().location function.