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

[FEATURE REQ] Support Parameters "allowedValues" property #314

Open
JohnathonMohr opened this issue Jan 17, 2023 · 2 comments
Open

[FEATURE REQ] Support Parameters "allowedValues" property #314

JohnathonMohr opened this issue Jan 17, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@JohnathonMohr
Copy link
Contributor

Please describe the feature or suggestion.

Template parameters can have an array defined specifying what values are allowed for the parameter.
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/parameters#allowed-values

Currently, if a parameter has allowed values specified, template parsing (without using a parameters file) throws an exception because a mock value is used that (very likely) will not be an allowed value.

BPA should be able to pick a value from this list and use that for the parameter value instead of making up a value on its own.

Additional context

This could also be considered a bug, but I'm filing the issue as a feature request.

@pamelafox
Copy link
Member

I ran into an issue with @Allowed parameters and am not sure if it's a bug with template-analyzer, a bug with our Bicep, or if it's this bug.

Specifically:

We have functions.bicep with these params:

// Runtime Properties
@allowed([
  'dotnet', 'dotnetcore', 'dotnet-isolated', 'node', 'python', 'java', 'powershell', 'custom'
])
param runtimeName string
param runtimeNameAndVersion string = '${runtimeName}|${runtimeVersion}'
param runtimeVersion string

https://github.com/Azure/azure-dev/blob/2545c2f84c0858d59b8df0c3c62bb733adbd4656/templates/common/infra/bicep/core/host/functions.bicep#L16

That runtimeName parameter gets passed into appservice.bicep, which has the same params declared:

// Runtime Properties
@allowed([
  'dotnet', 'dotnetcore', 'dotnet-isolated', 'node', 'python', 'java', 'powershell', 'custom'
])
param runtimeName string
param runtimeNameAndVersion string = '${runtimeName}|${runtimeVersion}'
param runtimeVersion string

https://github.com/Azure/azure-dev/blob/2545c2f84c0858d59b8df0c3c62bb733adbd4656/templates/common/infra/bicep/core/host/appservice.bicep#L15

The bicep checker is okay with this, but template-analyzer errors (fatally) and says:

    Error: An exception occurred while analyzing template /home/runner/work/simple-flask-server-example/simple-flask-server-example/infra/core/host/functions.bicep
    Exception details:
    Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzerException: Error while evaluating rules.
     ---> Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzerException: Error while processing template.
     ---> Azure.Deployments.Templates.Exceptions.TemplateValidationException: The provided value '[parameters('runtimeName')]' for the template parameter 'runtimeName' at line '1' and column '577' is not valid. The parameter value is not part of the allowed value(s): 'dotnet,dotnetcore,dotnet-isolated,node,python,java,powershell,custom'.

See full run: https://github.com/pamelafox/simple-flask-server-example/actions/runs/4492526898/jobs/7902534396?pr=3

Are we required to specify a default in functions.bicep for this scenario? Or is this a template-analyzer parsing issue? (And if so, is it the one described above?)

Thanks!

@mattcorr
Copy link

Any update on this? We are getting this issue as well when we have a parameter that needs to be a specific allowed value and if a parameter file is not provided the text generated does not match.

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

No branches or pull requests

4 participants