How can I have conditional parameter value in Azure Workbook?
I want to have one parameter called environment. It has some text values. E.g. it has two values test
and production
.
Also, I want to have two other parameters: subscription and app_insights.
Now, I want to select the subscription and app_insights values automatically based on the environment parameter value.
So, here is how I am trying to select the test subscription for the subscription parameter when the environment parameter is test
:
summarize by subscriptionId
| project subscriptionId=strcat("/subscriptions/", subscriptionId),
selected = case("{environment}" == "test" and subscriptionId == "test subscription id", true, false)
But it seems that the environment parameter does not get substituted for the "{environment}"
placeholder. If I remove the "{environment}" == "test"
check, then the test subscription gets selected as expected.
How can I use one parameter to decide the value of another parameter? Is there a better way to achieve what I want? Preferably I also want the subscription and app_insights parameters not to be shown to the user of the workbook and prevent them from being edited manually.
Here's an example which illustrates how a parameter can be conditional upon another.
Let's say we have a parameter named Environment
, of type Options group
which gets data from the following JSON:
[
{ "value":"'dev'", "label":"dev", "selected":true },
{ "value":"'prod'", "label":"prod" }
]
then, we can create a secondary parameter which will return a certain list if dev
is selected, and a different one if prod
is selected. This second parameter is of type Dropdown
and is configured to run an Azure resource graph query across all subscriptions.
resources
| extend dev_subs = dynamic([
"dev-sub1",
"dev-sub2"
])
| extend prod_subs = dynamic([
"prod-sub1",
"prod-sub2"
])
| extend selection = {Environment}
| extend output = iff(selection == "dev", dev_subs, prod_subs)
| project output
| mv-expand output
| distinct tostring(output)
when dev
is selected in the first parameter, the second parameter will show a dropdown with options dev-sub1
and dev-sub2
; when prod
is selected, the second parameter will show a dropdown with options prod-sub1
and prod-sub2
.