Azure / Azure/bicep

optional enforcement of User Defined Type 'Allowed' (support suggested values/open enums)

Open
#10,432 5 comments 4 reactions 0 assignees View on GitHub
enhancement Needs: Upvote
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

# Is your feature request related to a problem? Please describe.
Users should be able to pass in values even if their are not 'allowed'.

The `allowed` has many benefits, such as improving the user experience when writing a Bicep template. But there are cases where all of the allowed values cannot be known. It may be that some allowed values are secrets that can't be initially shared. (I ran into this issue for GameDev VM, where we had to remove our allowed values to let some users try "win11-unreal-engine").

### vm.bicep
This module is an example, and is not configurable by the user. It could be in a public registry.
```bicep
@allowed['win10']
param os string
```

### main.bicep
This module is written by the end-user, who is provided a option which has been made to them before the module was updated.

```bicep
module vm 'br:bicep-module-registry:vm@1.0.0' = {
name: 'myVM'
params: {
// Surpress Error
os: 'win11'
}
}
```

This will help to enable advanced use cases for user-defined types, like a `Location` type which is difficult to fully capture in a allowed Values field, but could be created that at least covers a majority of use cases.
# Describe the solution you'd like
I should be able to deploy the above example. This should still initially raise errors, and the user should have to perform some action to suppress this. This should then produce a warning. The warning should explain that the error is being suppressed, and that the user is trying to use a value that is not allowed. That could also be suppressed by the user.

This could be done entirely in bicep, where the error suppression is detected and casts instances of os to simple strings without any restrictions on the values.

The main.json would either no longer contain the allowedValues, or they would be commented out explaining they have been suppressed.

### main.json
```json
"os": {
"type": "string"/*, (start comment here in case its last item in object)
If we could simply comment this out in the final json
and explain that this allowedValue is being suppressed, that its ideal, other drop this section)
"allowedValues": [
"new",
"existing"
]*/,
"metadata": {
"description": "Create new or use existing Public IP resource"
}
},
```

Contributor guide

Open the contributing guide

Research direction

Start with the vm.bicep and main.bicep examples in the issue, then trace how allowed values are validated and emitted into main.json. Determine how explicit suppression should change the diagnostic and generated template, and verify that deployment accepts the previously disallowed value while warning about the suppression.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, json
Domain
cloud, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.