azure ARM "code": "InUseSubnetCannotBeDeleted" when trying to update vnet

标签 azure azure-resource-manager azure-rm-template

我有一个相当简单的 ARM 模板,用于创建 vnet、子网和服务端点。当我尝试更改服务端点时,出现错误“代码”:“InUseSubnetCannotBeDeleted”。指出我的一台虚拟机正在使用其中一个子网。但是,我不想删除该子网。我只是想更新它,我可以通过门户或 powershell 来完成操作。我是否需要更改一些开关才能使 ARM 模板更新资源而不是从头开始创建它们?

模板。我把它精简到最低限度。首先,我使用它创建 vnet 和两个子网,部署一个虚拟机,然后再次运行部署,我发现子网无法删除:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "VNet1",
      "metadata": {
        "description": "VNet name"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Address prefix"
      }
    },
    "subnets": {
      "type": "object"
    }
  },
  "variables": {
    "location": "[resourceGroup().location]",
    "subnetcount": "[length(parameters('subnets').settings)]"
  },
  "resources": [
    {
      "apiVersion": "2018-06-01",
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[parameters('vnetName')]",
      "location": "[variables('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": ["[parameters('vnetAddressPrefix')]"]
        }
      },
      "resources": [
      ]
    },
    {
      "apiVersion": "2018-06-01",
      "type": "Microsoft.Network/virtualNetworks/subnets",
      "name": "[concat(parameters('vnetName') , '/' , parameters('subnets').settings[copyIndex()].name)]",
      "location": "[variables('location')]",
      "copy": {
        "name": "subnetLoop",
        "count": "[variables('subnetcount')]"
      },
      "dependsOn": ["[parameters('vnetName')]"],
      "properties": {
        "addressPrefix": "[parameters('subnets').settings[copyIndex()].addressPrefix]"
      }
    }
  ]
}

最佳答案

我也遇到了同样的问题。这是我找到的,与上面其他用户的答案基本相同。

在 ARM 模板中创建带有子网的 vnet 的三种方法。 (非常粗略的例子)

1。第一次运行时有效。之后,vnet 资源尝试删除子网。

{
  "vnet"
},
{
  "subnet",
  "dependsOnVnet"
}
<小时/>

2。尽管它们是嵌套资源,但虚拟网络没有上下文感知。与选项 #1 类似。

{
  "vnet"
  resources : [
    {
      "subnet",
      "dependsOnVnet"
    }
  ]
}
<小时/>

3。 vnet 资源是子网感知的,因为它是 vnet 的属性。它不会删除子网。

{
  "vnet"
  "properties":{
    "subnets" : ["subnet"]
  }
}
<小时/>

*这些示例采用增量 ARM 部署。*

关于 azure ARM "code": "InUseSubnetCannotBeDeleted" when trying to update vnet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55901747/

相关文章:

azure - 是否需要具有 md5-content 属性才能让 Snowpipe 从 azure adls gen2 自动摄取文件?

powershell - Azure 资源模板参数 hell

Azure Key Vault 参数引用限制

azureservicebus - 使用 Bicep 以编程方式获取服务总线 SharedAccessKey

azure - 我尝试使用 ARM/bicep 和 HTTP 触发器来部署函数应用程序

iis - 通过 Azure 云服务 RDP 访问现有的 Azure 网站

Azure AppInsight 不适用于静态文件应用程序

azure - VS Code 智能感知不适用于某些 ARM 命令

azure - 上传 Key Vault 证书并通过 ARM 模板在应用服务中访问它

azure - 如何获取azure VM的azure VMUUID?