Are there any nested loop workarounds? #5054
-
I am in the process of writing 2 alerts for various app services (4 function apps, and one web app). Originally I have it set up as one file, metric-alerts.bicep where I have the parameterized resource:
Shown below, in my main bicep file I consume the resource as modules, and for each alert I have (in my case I have a simple 403 & 500 implementation) I need to create a new module:
The above implementation works and will generate my two alerts for all 5 app services however, I've been looking into trying to create a less verbose implementation. I keep my parameterized resource in metric-alerts.bicep, but added a parameter file:
I then re-write the module in main.bicep to loop through my parameter values, and if I hard-code the name of the app service it will create the two alerts for that service:
Of course, the goal is to create 2 alerts for all 5 app services so I switch up my scopes param to:
It gives me an error saying: 'Unexpected array in scopes[0]. I know that the nested loops isn't yet supposed so I created a new variable which would hold the looping logic and assigned it to the scopes param:
This gave me an error saying that I have seen several workarounds in different discussions, like #1280 on here but haven't been able to figure out how to make it work in this situation. Is there something else I should try? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
main.bicepjust loop over the app services (only) - Add this extra (outer) layer onto what you have now.
appService.bicepfor a single app service loop over the Metric alerts
metric-alert.bicepyou just have the name of a single app service and a single alert rule resource WS 'Microsoft.Web/sites@2021-01-01' existing = {
name: wsname
}
// for scope just use this
scopes: [
WS.id
] |
Beta Was this translation helpful? Give feedback.
main.bicep
just loop over the app services (only) - Add this extra (outer) layer onto what you have now.
module appService 'appService.bicep' = [for (ws, index) in appServices : {
metricAlerts
from the param file, you will use that at the next layer.appService.bicep
for a single app service loop over the Metric alerts
module dealsMetricAlerts '../modules/management/metric-alert.bicep' = [for (alert, index) in alertConfig.metricAlerts: {
metric-alert.bicep
you just have the name of a single app service and a single alert rule