Azure / Azure/bicep

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

Open
#8,448 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

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

```bicep
@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

Contributor guide

Open the contributing guide

Research direction

Start with the reproducer in the issue and inspect the @allowed parameter validation and default-value type checking. The change is complete when an expression such as resourceGroup().location is evaluated before comparison with the allowed values, while invalid defaults remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.