如何使用 BICEP 将 VNET 部署到应用服务?

问题描述 投票:0回答:1

我想部署一个 BICEP 模板来配置应用服务的出站流量。当我部署 BICEP 模板时,没有错误并且显示成功,但它没有添加虚拟网络集成。

$template = 'main.bicep'
$resourceGroup = "my-resource-group"
az deployment group create `
   --resource-group $resourceGroup `
   --template-file $template

main.bicep

var vnetResourceId = '/subscriptions/{subscription-id}/resourceGroups/my-resource-group/providers/Microsoft.Network/virtualNetworks/{vnet-name}/subnets/default'
var outboundVnetNet = 'doesItEvenMatter'
resource appService 'Microsoft.Web/sites@2024-04-01' = {
  name: 'my-awesome-app-lol'
  location: 'WestUS2'
  properties: {
    serverFarmId: appServicePlanId
    httpsOnly: true
    siteConfig: {
      cors: {
        allowedOrigins: [
          'https://portal.azure.com'
        ]
      }
      ftpsState: 'FtpsOnly'
      netFrameworkVersion: 'v8.0'
      vnetRouteAllEnabled: true
      vnetName: outboundVnetNet
    }
  }
}

resource outboundVnetConfiguration 'Microsoft.Web/sites/virtualNetworkConnections@2023-12-01' = {
  name: outboundVnetNet
  parent: appService
  properties: {
    isSwift: true
    vnetResourceId: vnetResourceId
  }
}

当我在门户内手动执行此操作时,从 UI 导出的 ARM 模板会添加以下 JSON:

{
  "type": "Microsoft.Web/sites/virtualNetworkConnections",
  "apiVersion": "2023-12-01",
  "name": "my-awesome-app-lol/9e717979-f385-412e-b1a5-2fdffd21fa7f_default",
  "location": "West US 2",
  "dependsOn": [
    "[resourceId('Microsoft.Web/sites', 'my-awesome-app-lol')]"
  ],
  "properties": {
    "vnetResourceId": "/subscriptions/{subscription-id}/resourceGroups/my-resource-group/providers/Microsoft.Network/virtualNetworks/{vnet-name}/subnets/default",
    "isSwift": true
  }
}

当我使用 BICEP 时,我错过了什么导致虚拟网络集成无法部署?

azure azure-web-app-service azure-rm-template azure-bicep vnet
1个回答
0
投票

您只需用 api-version

virtualNetworkSubnetId
指定
2024-04-01
属性即可。

此外

vnetRouteAllEnabled
virtualNetworkSubnetId
位于
siteConfig
对象之外:

var vnetResourceId = '/subscriptions/{subscription-id}/resourceGroups/my-resource-group/providers/Microsoft.Network/virtualNetworks/{vnet-name}/subnets/default'
resource appService 'Microsoft.Web/sites@2024-04-01' = {
  name: 'my-awesome-app-lol'
  location: 'WestUS2'
  properties: {
    serverFarmId: appServicePlanId
    httpsOnly: true
    siteConfig: {
      cors: {
        allowedOrigins: [
          'https://portal.azure.com'
        ]
      }
      ftpsState: 'FtpsOnly'
      netFrameworkVersion: 'v8.0'      
    }
    vnetRouteAllEnabled: true
    virtualNetworkSubnetId: vnetResourceId
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.