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.
2
Answers
Yes, this is 100% supported.
Parameters have to be declared before they are referenced, and then parameters can be referenced left to right, just like code. Order is important in both steps and parameters.
If you open the "Resource Picker" sample in Workbooks in Azure Monitor:
if you look at the exact query for the resources parameter here, its query text is:
Where you can see that the
ResourceGroups
parameter and theResourceTypes
parameter are both referenced in the query, and replaced at query time. TheSubscriptions
parameter is selected in the ARG query’s subscription field.If a parameter isn’t being replaced in the query, then that parameter doesn’t exist before that query (or the parameter is not marked required and has no value, so it gets replaced as an empty string).
while editing a query step, the toolbar in the upper right corner of that step has an item to open up the query with all the parameters replaced in the appropriate view (the Resource Graph Explorer blade, or Logs query blade, or ADX query site, etc) so you can see exactly how the parameters were replaced.
Here’s an example which illustrates how a parameter can be conditional upon another.
Let’s say we have a parameter named
Environment
, of typeOptions group
which gets data from the following JSON:then, we can create a secondary parameter which will return a certain list if
dev
is selected, and a different one ifprod
is selected. This second parameter is of typeDropdown
and is configured to run an Azure resource graph query across all subscriptions.when
dev
is selected in the first parameter, the second parameter will show a dropdown with optionsdev-sub1
anddev-sub2
; whenprod
is selected, the second parameter will show a dropdown with optionsprod-sub1
andprod-sub2
.