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

Allow param assignments to use null values #11532

Merged
merged 7 commits into from Aug 16, 2023
Merged

Allow param assignments to use null values #11532

merged 7 commits into from Aug 16, 2023

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Aug 14, 2023

Resolves #11301 and resolves #11531

This PR allows .bicepparam files to specify a value of null (or an expression that evaluates to null) for optional parameters, as the ARM engine will interpret a null value as equivalent to no value having been supplied for the parameter. Because this means that the param's default value (which may not be known until deploy time) will be used, this PR also prevents parameters with a null value from being used in expressions.

While working on the block, I noticed that parameters using az.getSecret are currently allowed to be used in other expressions in .bicepparam files, but the compiled value is incorrect (the JSON will use the object value that should appear in the .parameters.json file). The block was updated to also prohibit references to parameters whose value will be pulled at deploy time from KeyVault.

Microsoft Reviewers: codeflow:open?pullrequest=https://github.com/Azure/bicep/pull/11532&drop=dogfoodAlpha

@jeskew jeskew changed the title Jeskew/11301 Allow param assignments to use null values Aug 14, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

Test Results (osx-x64)

       33 files  ±0         33 suites  ±0   1h 44m 18s ⏱️ + 16m 24s
10 406 tests +5  10 370 ✔️ +5  36 💤 ±0  0 ±0 
12 623 runs  +5  12 587 ✔️ +5  36 💤 ±0  0 ±0 

Results for commit 83bbb24. ± Comparison against base commit 6c3a71d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

Test Results (linux-musl-x64)

       33 files  ±0         33 suites  ±0   36m 22s ⏱️ +40s
10 402 tests +5  10 366 ✔️ +5  36 💤 ±0  0 ±0 
12 619 runs  +5  12 583 ✔️ +5  36 💤 ±0  0 ±0 

Results for commit 83bbb24. ± Comparison against base commit 6c3a71d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

Test Results (linux-x64)

       33 files  ±0         33 suites  ±0   36m 41s ⏱️ - 2m 55s
10 402 tests +5  10 366 ✔️ +5  36 💤 ±0  0 ±0 
12 619 runs  +5  12 583 ✔️ +5  36 💤 ±0  0 ±0 

Results for commit 83bbb24. ± Comparison against base commit 6c3a71d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

Test Results (win-x64)

       33 files  ±0         33 suites  ±0   37m 56s ⏱️ + 1m 16s
10 414 tests +5  10 378 ✔️ +5  36 💤 ±0  0 ±0 
12 630 runs  +5  12 594 ✔️ +5  36 💤 ±0  0 ±0 

Results for commit 83bbb24. ± Comparison against base commit 6c3a71d.

♻️ This comment has been updated with latest results.

@jeskew jeskew requested a review from a team August 16, 2023 16:16
Copy link
Contributor

@shenglol shenglol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@jeskew jeskew merged commit abfcb32 into main Aug 16, 2023
52 checks passed
@jeskew jeskew deleted the jeskew/11301 branch August 16, 2023 19:54
@slavizh
Copy link
Contributor

slavizh commented Sep 11, 2023

@jeskew
May be I am doing something wrong but I get error on the using statement as soon as I provide null value. To test:

example.bicep

param propertyx string

example.bicepparam

using 'example.bicep'
param propertyx = null

using statement throws error like: The following parameters are declared in the Bicep file but are missing an assignment in the params file: "propertyx".bicep(BCP258)

@jeskew
Copy link
Contributor Author

jeskew commented Sep 11, 2023

@slavizh The BCP258 diagnostic is expected because propertyx is a required parameter. In order to be able to either omit a parameter or set its value to null in a .bicepparam file, the parameter needs to be optional. You can do this by setting a default value:

param propertyx string = 'default value'

or by declaring the parameter to be nullable (optional without a default value):

param propertyx string?

@slavizh
Copy link
Contributor

slavizh commented Sep 11, 2023

@jeskew thanks a lot!

@islamzakyy
Copy link

@jeskew I have a question that might be related to this topic

I am trying to set a parameter value in bicepparam file from a variable that uses filter function, it failed with this error:

Failed to evaluate parameter "resourceName": Unhandled exception during evaluating template language function 'variables' is not handled.bicep(BCP338)

Here is the code:

using './storageaccount.bicep'

var pipeline_content = loadYamlContent('azure-pipelines.yml','parameters')
var tenant = pipeline_content[0].default
var env = pipeline_content[1].default[0].environmentName
var resourceGroupLocationActual = resourceGroup().name
var locationAbrv = filter(pipeline_content[1].default[0].regionDetails, rg => rg.resourceGroup == resourceGroupLocationActual)[0].abrv
param resourceName = 'r${env}${tenant}st${locationAbrv}02'

As If it requires from me to do exception handling on the filter function output, any other function apart from filter works good. Weird

@jeskew
Copy link
Contributor Author

jeskew commented Sep 20, 2023

@islammohamed94 Could you open a separate issue? The problem you're running into is that the resourceGroup() function can't be used in .bicepparam files, but the appropriate error diagnostic isn't being raised.

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