You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bicep中VNet子网委托配置失败及相关冲突问题求助

Azure Bicep子网服务委托配置问题

背景

  • 现有代码库可成功创建虚拟网络(VNet)及子网,但无法为子网添加服务委托
  • 初始代码由github@ChristopherGLewis编写

服务委托配置代码

尝试添加服务委托的Bicep代码如下:

param vNetName string    
param rgVnet string    
param subnetName string    
param subnetAddressPrefix string    
param delegations array = []

//Subnet with delegation

resource subnet 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = {    
  name: '${vNetName}/${subnetName}'    
  properties: {     
    // delegations: delegations    
    delegations:[    
      {    
        name: 'delegation'    
        properties:{    
          serviceName: 'Microsoft.Web/serverfarms'    
        }    
      }    
    ]    
  }    
}

执行后VNet和子网正常创建,但服务委托未配置生效。

部署步骤

克隆代码仓库后执行以下PowerShell命令部署:

$rgExists = az group exists --name 'rg-testing'

if ($rgExists -eq $true){
    Write-Output "Deleting the resource group"
    az group delete -y -n  rg-testing
}

az group create --name rg-testing --location CentralUS

New-AzResourceGroupDeployment -Name network-deployment -resourcegroupName rg-testing -templatefile .\vNet.bicep -Templateparameterfile .\envs\stg.json

更新1:添加委托模块后的错误

添加用于传递委托数组的模块后,硬编码委托出现如下部署错误:

New-AzResourceGroupDeployment : 17:54:35 - The deployment 'Deployvnet' failed with error(s). Showing 2 out of 2 error(s).
Status Message: Operation was canceled. (Code: Canceled)
 - Operation PutSubnetOperation (3434545f-6f7e-46c8-aaa2-5710c58acbac) was canceled and superseded by operation PutSubnetOperation (ca028961-7ada-45af-b8af-697006f000c6).
(Code:CanceledAndSupersededDueToAnotherOperation)
Status Message: At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details. (Code:
DeploymentFailed)
 - {
  "status": "Canceled",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource write operation failed to complete successfully, because it reached terminal provisioning state 'Canceled'.",
    "details": [
      {
        "code": "Canceled",
        "message": "Operation was canceled.",
        "details": [
          {
            "code": "CanceledAndSupersededDueToAnotherOperation",
            "message": "Operation PutSubnetOperation (3434545f-6f7e-46c8-aaa2-5710c58acbac) was canceled and superseded by operation PutSubnetOperation (ca028961-7ada-45af-b8af-697006f000c6)."
          }
        ]
      }
    ]
  }
} (Code:Conflict)
CorrelationId: ere34444-f496-4ec4-bbe1-d748542c3c1b
At line:1 char:1
+ New-AzResourceGroupDeployment -Name Deployvnet -resourcegroupName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

更新3:新问题:配置委托后NSG和路由表丢失

已修复上述错误,但出现新问题:当子网配置服务委托后,关联的网络安全组(NSG)和路由表会被删除;禁用委托配置时,NSG和路由表可正常创建并关联。

目前可通过Az CLI手动添加服务委托,请问能否通过读取JSON配置文件的方式实现该功能,替代CLI操作?

内容的提问来源于stack exchange,提问作者learner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 19:52:55