@Allowed decorator forces case sensitivity even though ARM doesn't require it
Bicep version bicep --version Bicep CLI version 0.3.255 (589f0375df)
Describe the bug Adding an @allowed syntax decorator forces a parameter to be case sensitive even though the ARM parameter is not.
To Reproduce A simple repo is a parameter that takes valid Azure regions
@allowed([
'EastUS'
'EastUS2'
'CentralUS'
'NorthCentralUS'
'SouthCentralUS'
'WestCentralUS'
'WestUS'
'WestUS2'
'CanadaEast'
'CanadaCentral'
'BrazilSouth'
'NorthEurope'
'WestEurope'
'FranceCentral'
'FranceSouth'
'UKWest'
'UKSouth'
'GermanyCentral'
'GermanyNortheast'
'GermanyNorth'
'GermanyWestCentral'
'SwitzerlandNorth'
'SwitzerlandWest'
'NorwayEast'
'NorwayWest'
'SoutheastAsia'
'EastAsia'
'AustraliaEast'
'AustraliaSoutheast'
'AustraliaCentral'
'AustraliaCentral2'
'ChinaEast'
'ChinaNorth'
'ChinaEast2'
'ChinaNorth2'
'CentralIndia'
'WestIndia'
'SouthIndia'
'JapanEast'
'JapanWest'
'KoreaCentral'
'KoreaSouth'
'SouthAfricaWest'
'SouthAfricaNorth'
'UAECentral'
'UAENorth'
])
param targetResourceRegion string
You cannot pass in "eastus" even though its a perfectly valid region
Additional context I do realize this is a crappy way to code this, but this is directly from Microsft docs: https://docs.microsoft.com/en-us/azure/azure-monitor/alerts/resource-manager-alerts-metric#template-file-6
Possible solutions
- Make the @Allowed decorator case insensitive
- Add a decorator @CaseInsensitive
- Add decorator types @AzureRegion - which may not work (run time vs compile time when looking at different AzureEnvironments (i.e. Azure vs AzureUSGovernment)
Good catch! We need to make the semantics of this match the runtime. (In the long term, we are considering introducing something like your @AzureRegion decorator to make declaring common sets of allowed values simpler.)
Thanks for your patience — this was recently picked up as an outstanding open issue for the Bicep team to review.
Good catch originally, and thanks @majastrz for the May 2021 note about matching runtime semantics. I dug into where the case-sensitivity actually comes from. I built a parameter with @allowed(['EastUS','WestUS','CentralUS']) and ran an ARM validation passing eastus, and the deployment engine is what rejects it:
The value 'eastus' is not part of the allowed value(s): 'EastUS,WestUS,CentralUS'.
So @allowed compiles to ARM allowedValues, and ARM matches those case-sensitively server-side — Bicep isn't adding the strictness. Because of that, making @allowed itself case-insensitive would be an ARM-engine change (and a potentially breaking one), so I'd consider that part by design rather than a Bicep fix.
The useful Bicep-side improvement here is your/@majastrz's other idea: built-in, Azure-aware allowed-value sets (an @AzureRegion-style type), which overlaps with the type work in #2481 and #622. I'm going to keep this open scoped to that, and treat the "case-insensitive @allowed" interpretation as by design.