Coder Perfect

How to return output of module


I’m using For Loop to create two Azure App Services and two App Service Plans, but I need to pass the HostingPlanID from the AppService plan to each of the App Services, but I can’t get to the module’s output.

This is the error I’m getting: Property of type “module[]” cannot be accessed. It’s necessary to use a “object” type.

I’m creating an output output hostingPlanId string = within my App Service Plan Module.

However, I am unable to reference this in my template (main.bicep)



param appPlanSkuCode string
param appPlanSkuTier string
param appPlanOS string
param appPlanSize string
param appPlanFamily string
param appPlanCapacity int
param hostingPlanName string

resource hostingPlan 'Microsoft.Web/serverfarms@2020-10-01' = {
  name: hostingPlanName
  location: resourceGroup().location
  kind: appPlanOS
  sku: {
    name: appPlanSkuCode
    tier: appPlanSkuTier
    size: appPlanSize
    family: appPlanFamily
    capacity: appPlanCapacity
  properties: {
    perSiteScaling: false
    maximumElasticWorkerCount: 1
    isSpot: false
    reserved: true
    isXenon: false
    hyperV: false
    targetWorkerCount: 0
    targetWorkerSizeId: 0


output hostingPlanId string =


module AppService '../../Modules/Azure.App.Service.template.bicep'  = [for i in range(0, length(webAppSettings.webApps)): {
  name: webAppSettings.webApps[i].appServiceType == 'functionApp' ? toLower('fnc-${webAppSettings.webApps[i].name}-${resourceGroupNameSuffix}') : toLower('web-${webAppSettings.webApps[i].name}-${resourceGroupNameSuffix}')
  dependsOn: [
  params: {
    vnetSubnetID:webAppSettings.webApps[i].appPurpose == 'backend' ? '${backendvnetSubnetID}' : '${frontendvnetSubnetID}'
    appServiceName:webAppSettings.webApps[i].appServiceType == 'functionApp' ? toLower('fnc-${webAppSettings.webApps[i].name}-${resourceGroupNameSuffix}') : toLower('web-${webAppSettings.webApps[i].name}-${resourceGroupNameSuffix}')
    appServiceType: webAppSettings.webApps[i].appServiceType
    LinuxFXVersion: webAppSettings.webApps[i].LinuxFX

I’m not sure where I’m going wrong.


Asked by JacksWastedLife

Solution #1

If you have a hostingPlan.bicep file, you may use the following syntax to refer to it from the main.bicep file:

module hostingPlan 'hostingPlan.bicep' = {
  name: 'hostingPlan'
  params: {

The module’s outputs can then be accessed:


Answered by Thomas

Post is based on