Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@allowed decorator for param should confirm default value after any expression is evaluated #8448

Open
michael-crawford opened this issue Sep 21, 2022 · 2 comments

Comments

@michael-crawford
Copy link

Bicep version
Bicep CLI version 0.10.61 (8f44805)

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

@majastrz
Copy link
Member

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)

@michael-crawford
Copy link
Author

michael-crawford commented Oct 26, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants