如何返回模块的输出



我正在使用For Loop创建两个Azure应用服务和两个应用服务计划,但我需要将HostingPlanID从应用服务计划传递到每个应用服务,但我无法访问模块的输出。

我收到以下错误Cannot access properties of type "module[]". An "object" type is required.

在我的应用程序服务计划模块中,我正在创建一个输出output hostingPlanId string = hostingPlan.id

但我不能从我的模板(main.bicep) 中引用这个

hostingPlan: AppServicePlan.hostingPlan.id

模块:

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 = hostingPlan.id

模板:

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: [
    AppServicePlan
  ]
  params: {
    hostingPlan: AppServicePlan.hostingPlan.id
    webAppSettings:webAppSettings
    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
  }
}]

你知道我哪里错了吗?

感谢

如果您有一个hostingPlan.bicep文件,您可以从main.bicep文件中引用它,如下所示:

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

然后,您可以访问模块的输出:

hostingPlan.outputs.hostingPlanId

相关内容

  • 没有找到相关文章

最新更新