Azure Bicep - Deployment Failed (Conflict)对该资源或依赖资源的另一个操作正在进



我是二头肌新手,试图使用模块创建VNet和子网。我有以下两个模块

vnet.bicep

param name string
param location string
param addressPrefixes array
param tags object
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2019-11-01' = {
name: name
location: location
properties: {
addressSpace: {
addressPrefixes: addressPrefixes
}
}
tags: tags
}

subnet.bicep

param parentVnetName string
param name string
param addressPrefix string
resource parentVnet 'Microsoft.Network/virtualNetworks@2020-11-01' existing = {
name: parentVnetName
}
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2021-08-01' = {
name: name
parent: parentVnet
properties: {
addressPrefix: addressPrefix
}
}

我正在尝试使用下面的配置来创建一个vnet和多个子网。

param location string = 'uksouth'
param vnet object = {
name: 'vnet'
addressPrefixes: [
'10.0.0.0/16'
]
subnets: [
{
name: 'subnet1'
addressPrefix: '10.0.1.0/24'
}
{
name: 'subnet2'
addressPrefix: '10.0.2.0/24'
}
]
}
targetScope = 'subscription'
resource rg 'Microsoft.Resources/resourceGroups@2021-01-01' = {
name: 'rg'
location: location
tags: {}
}
module vnetsym 'modules/vnet.bicep' = {
scope: rg
name: vnet.name
params: {
name: vnet.name
location: location
addressPrefixes: vnet.addressPrefixes
tags: {}
}
}
module subnetsym 'modules/subnet.bicep' = [for subnet in vnet.subnets: {
scope: rg
name: subnet.name
params: {
name: subnet.name
addressPrefix: subnet.addressPrefix
parentVnetName: vnet.name
}
dependsOn: [
vnetsym
]
}]

然而,bicep似乎无法计算出依赖关系,并抛出以下错误。除了这次部署,没有其他正在进行的行动。为什么模块依赖关系在这种情况下不起作用,我如何修复它?

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"Conflict","message":"{rn  "status": "Failed",rn  "error": {rn    "code": "ResourceDeploymentFailure",rn    "message": "The resource operation completed with terminal provisioning state 'Failed'.",rn    "details": [rn      {rn        "code": "DeploymentFailed",rn        "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",rn        "details": [rn          {rn            "code": "Conflict",rn            "message": "{\r\n  \"error\": {\r\n 
\"code\": \"AnotherOperationInProgress\",\r\n    \"message\": \"Another operation on this or dependent resource is in progress. To retrieve status of the operation use uri: https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Network/locations/uksouth/operations/ef9f087b-0448-44a2-ab05-9579837bf9de?api-version=2021-08-01.\",\r\n    \"details\": []\r\n  }\r\n}"rn          }rn        ]rn      }rn    ]rn  }rn}"}]}}

我也注意到行为是不一致的。有时不创建子网,有时只创建一个子网。通过多次部署,我有时也能够成功地完成部署!

这里的问题是子网模块是并行部署的。它们都试图同时更新vnet,导致您看到的冲突错误。

在这种情况下,你可以使用模块装饰器:

默认情况下,资源并行部署。当您添加batchSize装饰器时,您将按顺序部署实例。

所以这应该可以工作:

@batchSize(1)
module subnetsym 'modules/subnet.bicep' = [for subnet in vnet.subnets: {
...

您还应该在vnet资源中部署子网。如果重新运行模板,它将在重新创建子网之前删除子网。有几个问题相关:

  • 创建不破坏所有子网的VNET
  • 带有子网的资源虚拟网络想要删除现有子网

相关内容

  • 没有找到相关文章

最新更新