Output from azd version
azd version 1.11.0 (commit 5b92e06)
Describe the bug
In bicep, it is possible to define nullable parameters when using the following syntax:
When doing so, these parameters are not required to be passed to the deployment commands in order to deploy the resulting ARM template.
However, azd treats such parameters as if they were non-nullable parameters with no default value whenever running which causes the following three issues:
- The user is always prompted to provide the value of the parameter, even if the value is clearly marked as
null inside the .azure/{env}/config.json file
- Due to the issue above, deploying resources with azd in a CI/CD setup becomes impossible as the following error is provided
ERROR: initializing provisioning manager: prompting for value: no default response for prompt 'Enter a value for the 'param_name' infrastructure parameter:'
- Templates making use of nullable types are not working properly
To Reproduce
Attempt to provision the infra with the following main.bicep:
param parameter_null string[]?
param parameter_null_second string?
output out string = parameter_null_second ?? 'some value'
When running az provision, you will be requested to provide a value for both parameters (1st issue). Enter "null" into the prompt.
The content of the config.json will then look like this:
{
"infra": {
"parameters": {
"parameter_null ": null,
"parameter_null_second": "null"
}
}
}
The nullable array has a JSON null value, which is acceptable even if it shouldn't be asked. However, it is impossible to provide a null value for the nullable string. Typing null into the prompt generates "null" as seen above. Typing nothing returns the empty string ""
Re-run again az provision, you will be asked to provide a value for parameter_null once more despite being defined as null inside theconfig.json.
Finally, try to run az provision --no-prompt and you will be blocked by the error ERROR: initializing provisioning manager: prompting for value: no default response for prompt 'Enter a value for the 'parameter_null' infrastructure parameter:' (second issue)
Expected behavior
Bicep nullable types are not prompted for a value and are not defined inside the config.json file as those should be provided through the main.parameters.json if needed.
Environment
Information on your environment:
- Bicep v0.32
- IDE and version : VS code 1.96.2
Additional context
Example of a scenario where a template can be broken by this limitation
param log_analytics_workspace_name string?
resource la_workspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = if (log_analytics_workspace_name != null) {
name: log_analytics_workspace_name!
scope: resourceGroup()
}
module setup_la_workspace 'modules/la-setup.bicep' = if (log_analytics_workspace_name == null) {
name: 'setup_la_workspace'
}
output la_workspace_id string = log_analytics_workspace_name ? la_workspace.id : setup_la_workspace.outputs.id
output la_workspace_name string = log_analytics_workspace_name ? log_analytics_workspace_name : setup_la_workspace.outputs.name
In this template, the module would never be called since setting log_analytics_workspace_name to null is impossible through azd, generating runtime errors on the existing part every time this template is deployed.
Output from
azd versionazd version 1.11.0 (commit 5b92e06)
Describe the bug
In bicep, it is possible to define nullable parameters when using the following syntax:
When doing so, these parameters are not required to be passed to the deployment commands in order to deploy the resulting ARM template.
However, azd treats such parameters as if they were non-nullable parameters with no default value whenever running which causes the following three issues:
nullinside the.azure/{env}/config.jsonfileERROR: initializing provisioning manager: prompting for value: no default response for prompt 'Enter a value for the 'param_name' infrastructure parameter:'To Reproduce
Attempt to provision the infra with the following main.bicep:
When running
az provision, you will be requested to provide a value for both parameters (1st issue). Enter "null" into the prompt.The content of the
config.jsonwill then look like this:{ "infra": { "parameters": { "parameter_null ": null, "parameter_null_second": "null" } } }The nullable array has a JSON null value, which is acceptable even if it shouldn't be asked. However, it is impossible to provide a null value for the nullable string. Typing null into the prompt generates
"null"as seen above. Typing nothing returns the empty string""Re-run again
az provision, you will be asked to provide a value forparameter_nullonce more despite being defined as null inside theconfig.json.Finally, try to run
az provision --no-promptand you will be blocked by the errorERROR: initializing provisioning manager: prompting for value: no default response for prompt 'Enter a value for the 'parameter_null' infrastructure parameter:'(second issue)Expected behavior
Bicep nullable types are not prompted for a value and are not defined inside the
config.jsonfile as those should be provided through themain.parameters.jsonif needed.Environment
Information on your environment:
Additional context
Example of a scenario where a template can be broken by this limitation
In this template, the module would never be called since setting
log_analytics_workspace_nameto null is impossible through azd, generating runtime errors on theexistingpart every time this template is deployed.