在Bicep中创建虚拟网络、子网和应用网关



我正在尝试创建一个VNet,子网和一个应用网关在一个二头肌文件。

当我运行文件时,我得到一个错误:

New-AzResourceGroupDeployment: 11:23:37 - The deployment 'AppGateway' failed with error(s). Showing 1 out of 1 error(s).
Status Message: Subnet 'NLWifiPrint-AppGateway-Subnet' is not valid in virtual network 'NetloanCloudPrint-vnet'. (Code: NetcfgInvalidSubnet)

部署将创建我的子网和公共IP地址。然后,我可以使用web门户使用公共IP和子网创建我的应用程序网关。因此,我创建的子网确实看起来很好,并且满足网关使用的要求。

我错在哪里?

这是我可以重新创建问题的二头肌文件:

param location string = resourceGroup().location
@description('VNet Name')
param vnetName string
@description('VNet default subnet name')
param vnetSubnetDefaultName string
@description('VNet admin subnet name')
param vnetSubnetAdminName string
@description('VNet API subnet name')
param vnetSubnetApiName string
@description('VNet Functions subnet name')
param vnetSubnetFunctionsName string
@description('VNet App Gateway subnet name')
param vnetSubnetAppGatewayName string
@description('App Gateway Name')
param appGatewayName string
// ********************************************************************************************************************
// Virtual Network with 5 Subnets
// 1) Default
// 2) Admin
// 3) API
// 4) Functions
// 5) App Gateway
// There is an odd thing where each sub net depend on the previous one, without this the deployment seems to want to 
// try and make changes to the vnet while the other subnets are still being added.
// ********************************************************************************************************************
resource vnet 'Microsoft.Network/virtualNetworks@2020-11-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: vnetSubnetAppGatewayName
properties: {
addressPrefix: '10.0.4.0/24'
}
}
]
}
}
resource subnetDefault 'Microsoft.Network/virtualNetworks/subnets@2022-09-01' = {
parent: vnet
name: vnetSubnetDefaultName
properties: {
addressPrefix: '10.0.0.0/24'
serviceEndpoints: [
{
service: 'Microsoft.Storage'
locations: [ location ]                  
}
]
}
}
resource subnetAdmin 'Microsoft.Network/virtualNetworks/subnets@2022-09-01' = {
parent: vnet
name: vnetSubnetAdminName
dependsOn: [ subnetDefault ]
properties: {
addressPrefix: '10.0.1.0/24'
serviceEndpoints: [
{
service: 'Microsoft.Storage'
locations: [ location ]                  
}
]
delegations: [
{
name: 'Microsoft.Web/serverFarms'
properties: {
serviceName: 'Microsoft.Web/serverFarms'
}
}
]
}
}
resource subnetApi 'Microsoft.Network/virtualNetworks/subnets@2022-09-01' = {
parent: vnet
name: vnetSubnetApiName
dependsOn: [ subnetAdmin ]
properties: {
addressPrefix: '10.0.2.0/24'
serviceEndpoints: [
{
service: 'Microsoft.Storage'
locations: [ location ]                  
}
]
delegations: [
{
name: 'Microsoft.Web/serverFarms'
properties: {
serviceName: 'Microsoft.Web/serverFarms'
}
}
]
}
}
resource subnetFunctions 'Microsoft.Network/virtualNetworks/subnets@2022-09-01' = {
parent: vnet
name: vnetSubnetFunctionsName
dependsOn: [ subnetApi ]
properties: {
addressPrefix: '10.0.3.0/24'
serviceEndpoints: [
{
service: 'Microsoft.Storage'
locations: [ location ]                  
}
]
delegations: [
{
name: 'Microsoft.Web/serverFarms'
properties: {
serviceName: 'Microsoft.Web/serverFarms'
}
}
]
}
}
// This is an empty Subnet for use by the App Gateway
resource subnetAppGateway 'Microsoft.Network/virtualNetworks/subnets@2022-09-01' = {
parent: vnet
name: 'NLWifiPrint-AppGateway-Subnet'
dependsOn: [ subnetFunctions ]
properties: {
addressPrefix: '10.0.4.0/24'
serviceEndpoints: []
delegations: []
privateEndpointNetworkPolicies: 'Disabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
// ********************************************************************************************************************
// WAF Gateway
// ********************************************************************************************************************
resource publicIPAddress 'Microsoft.Network/publicIPAddresses@2021-08-01' = {
name: '${appGatewayName}-ip'
location: location
sku: {
name: 'Standard'
}
properties: {
publicIPAddressVersion: 'IPv4'
publicIPAllocationMethod: 'Static'
}
}
resource myAppGateway 'Microsoft.Network/applicationGateways@2022-09-01' = {
name: appGatewayName
location: location
properties: {
sku: {
name: 'WAF_v2'
tier: 'WAF_v2'
capacity: 2
}
gatewayIPConfigurations: [
{
name: 'appGatewayIpConfig'
properties: {
subnet: {
id: subnetAppGateway.id
}
}
}
]
frontendIPConfigurations: [
{
name: 'appGwPublicFrontendIp'
properties: {
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: publicIPAddress.id
}
}
}
]
frontendPorts: [
{
name: 'port_80'
properties: {
port: 80
}
}
]
backendAddressPools: [
{
name: 'MyBackendPool'
properties: {
backendAddresses: []
}
}
]
//backendHttpSettingsCollection: [
//  {
//    name: 'BackendSettings'
//    properties: {
//      port: 80
//      protocol: 'Http'
//      cookieBasedAffinity: 'Disabled'
//      requestTimeout: 20
//    }
//  }
//]
//backendSettingsCollection: []
//  httpListeners: [
//  {
//    name: 'MyListener'
//    properties: {
//      frontendIPConfiguration: {
//          id: publicIPAddress.id
//      }
//      //frontendPort: {
//      //  id: '${applicationGatewayId}/frontendPorts/port_80'
//      //}
//      protocol: 'Http'
//      sslCertificate: null
//    }
//  }
//]
}
dependsOn: [ vnet ]
}

您定义了两个共享相同IP地址空间的子网。

resource vnet 'Microsoft.Network/virtualNetworks@2020-11-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: vnetSubnetAppGatewayName
properties: {
addressPrefix: '10.0.4.0/24'
}
}
]
}
}

resource subnetAppGateway 'Microsoft.Network/virtualNetworks/subnets@2022-09-01' = {
parent: vnet
name: 'NLWifiPrint-AppGateway-Subnet'
dependsOn: [ subnetFunctions ]
properties: {
addressPrefix: '10.0.4.0/24'
serviceEndpoints: []
delegations: []
privateEndpointNetworkPolicies: 'Disabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}

最新更新