Question about working with an array of arrays #8664
-
Hi Bicep friends Currently I am developing a deployment solution for a kind of complex Azure Virtual Desktop backplane infrastructure (workspaces, host pools, application groups). I decided to use nested modules, two layers deep to loop through all of the virtual desktop components and their dependencies. In first step I call a module to deploy each host pools and hand over an array of related application groups: module hp 'avd-backplane-pool.bicep' = [for pool in poolData: {
name: 'deploy-${pool.name}'
params: {
deploymentLocation: deploymentLocation
appGroupData: pool.applicationGroups // <-- Array of application groups
hostPoolName: pool.name
...
}
}]
output appReferences array = [for (appRef, i) in poolData: hp[i].outputs.appGroupIds] In that module I create all the application groups from the 'appGroupData' parameter and output their ids back. resource appGroup 'Microsoft.DesktopVirtualization/applicationGroups@2022-04-01-preview' = [for app in appGroupData: {
name: app.name
location: deploymentLocation
properties: {
applicationGroupType: app.groupType
hostPoolArmPath: hp.id
friendlyName: app.friendlyName
}
tags: baseTagSet
}]
// Outputs
output appGroupIds array = [for (group, i) in appGroupData: appGroup[i].id] The output I get from those deployments looks like this: [
[
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/prod-avd1-we-rg/providers/Microsoft.DesktopVirtualization/applicationGroups/prod-avd1-we-w1-hp1-appg1-desktop",
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/prod-avd1-we-rg/providers/Microsoft.DesktopVirtualization/applicationGroups/prod-avd1-we-w1-hp1-appg2-devtools"
],
[
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/prod-avd1-we-rg/providers/Microsoft.DesktopVirtualization/applicationGroups/prod-avd1-we-w1-hp2-appg1-desktop",
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/prod-avd1-we-rg/providers/Microsoft.DesktopVirtualization/applicationGroups/prod-avd1-we-w1-hp2-appg2-erp"
]
] The point where I struggle is to reference those resource ids to the related virtual desktop workspace. In a simpler scenario I would do something like that: //AVD Workspace
resource ws 'Microsoft.DesktopVirtualization/workspaces@2022-04-01-preview' = {
name: wsName
location: deploymentLocation
properties: {
friendlyName: wsFriendlyName
applicationGroupReferences: [for (applicationGroup, i) in applicationGroups: appg[i].id]
}
tags: {
...
}
} But with my current output, the array of arrays thats not possible. Is there a way to "flatten" or "concat" those arrays into one array so I can loop through it the classic way? Just let me know if you have any further questions. Thanks a lot, and best regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@lrottach you're in luck! We now have the You should be able to use something like |
Beta Was this translation helpful? Give feedback.
-
Hi @anthony-c-martin This is exactly what I was looking for. |
Beta Was this translation helpful? Give feedback.
@lrottach you're in luck! We now have the
flatten()
function available for this exact scenario. Docs here.You should be able to use something like
flatten(hpMods.outputs.appReferences)