通过 CLI 将 Azure 资源管理器模板部署到现有 VNET

Deploy Azure Resource Manager Template to existing VNET via CLI

我在 Azure 中设置了一个 VNET,其中包含许多子网,每个子网都有自己的 NSG 定义入站和出站规则。

我想在这些子网中部署具有自动缩放规则的 VM 规模集(例如基于 https://raw.githubusercontent.com/gbowerman/azure-myriad/master/vmss-ubuntu-scale/azuredeploy.json)和某些扩展(可能从 github/docker 中提取一些回购协议)。

在我的模板中,如何定义规模集/VM 应分配给现有 subnet/NSG 等?

好吧,这很简单,您只需指定要引用的资源的 ID。

假设您要使用现有子网:

"parameters": {
...
    "existingVirtualNetworkName": {
      "type": "string",
      "metadata": {
        "description": "Name of the existing VNET"
      }
    },
    "existingVirtualNetworkResourceGroup": {
      "type": "string",
      "metadata": {
        "description": "Name of the existing VNET resource group"
      }
    },
    "subnetName": {
      "type": "string",
      "metadata": {
        "description": "Name of the subnet in the virtual network you want to use"
      }
    },
...
  },
  "variables": {
...
    "vnetID": "[resourceId(parameters('existingVirtualNetworkResourceGroup'), 'Microsoft.Network/virtualNetworks', parameters('existingVirtualNetworkName'))]",
    "subnetRef": "[concat(variables('vnetID'),'/subnets/', parameters('subnetName'))]",
...
}
  "resources": [
... 
  {
    "apiVersion": "[variables('api-version')]",
    "type": "Microsoft.Network/networkInterfaces",
    "name": "[variables('nicName')]",
    "location": "[resourceGroup().location]",
    "dependsOn": [
      "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
    ],
    "tags": {
      "displayName": "NetworkInterface"
    },
    "properties": {
      "ipConfigurations": [{
        "name": "ipconfig1",
        "properties": {
          "privateIPAllocationMethod": "Dynamic",
          "publicIPAddress": {
            "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
          },
          "subnet": {
            "id": "[variables('subnetRef')]"
          }
        }
      }]
    }
  },

您可以对网络安全组使用相同的方法。

点击这里了解更多:https://github.com/Azure/azure-quickstart-templates/blob/master/201-vm-specialized-vhd-existing-vnet/azuredeploy.json