我正在尝试使用 ARM 模板部署 Azure SQL VM。我收到错误消息,因为模板引用 'ion5eddb999' 不明确

I am trying to deploy an Azure SQL VM with ARM template. I am getting error as The template reference 'ion5eddb999' is ambiguous

完整错误如下。

New-AzResourceGroupDeployment : 23:35:36 - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template reference 'ion5eddb999' is ambiguous: there are multiple template 
resources '/subscriptions/d2143d4c-a258-4a38-8fbf-de0e42756e22/resourceGroups/sumantest/providers/Microsoft.Compute/virtualMachines/ion5eddb999,/subscriptions/d2143d4c-a258-4a38-8fbf-de0e42756e22/resou 
rceGroups/sumantest/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/ion5eddb999' defined with this name. Please use fully qualified resource identity instead. Please see 
https://aka.ms/arm-template-expressions/#reference for usage details.'.

下面是ARM模板。我也尝试过使用硬编码的 sqlserver 名称,但同样的错误。 请让我知道我在这里做错了什么。感谢任何帮助。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "virtualMachineName": {
      "type": "String",
      "defaultValue": "ion5eddb999",
      "metadata": {
        "description": "The name of the VM"
      }
    },
    "virtualMachineSize": {
      "type": "String",
      "defaultValue": "Standard_B4ms",
      "metadata": {
        "description": "The virtual machine size."
      }
    },
    "ipAddress":{
        "type":"string",
        "defaultValue": "172.31.172.99",
        "metadata": {
            "description": "The virtual machine ip address"
        }
    },
    "existingVirtualNetworkName": {
      "type": "String",
      "defaultValue": "ion5ed-vnet",
      "metadata": {
        "description": "Specify the name of an existing VNet in the same resource group"
      }
    },
    "existingVnetResourceGroup": {
      "type": "String",
      "defaultValue": "ion5ed-gateway",
      "metadata": {
        "description": "Specify the resrouce group of the existing VNet"
      }
    },
    "existingSubnetName": {
      "type": "String",
      "defaultValue": "ion5ed-sub-devtest",
      "metadata": {
        "description": "Specify the name of the Subnet Name"
      }
    },
    "imageOffer": {
      "type": "String",
      "defaultValue": "sql2019-ws2019",
      "allowedValues": [
        "sql2019-ws2019",
        "sql2017-ws2019",
        "SQL2017-WS2016",
        "SQL2016SP1-WS2016",
        "SQL2016SP2-WS2016",
        "SQL2014SP3-WS2012R2",
        "SQL2014SP2-WS2012R2"
      ],
      "metadata": {
        "description": "Windows Server and SQL Offer"
      }
    },
    "sqlSku": {
      "type": "String",
      "defaultValue": "Standard",
      "allowedValues": [
        "Standard",
        "Enterprise",
        "SQLDEV",
        "Web",
        "Express"
      ],
      "metadata": {
        "description": "SQL Server Sku"
      }
    },
    "adminUsername": {
      "type": "String",
      "metadata": {
        "description": "The admin user name of the VM"
      }
    },
    "adminPassword": {
        "type": "SecureString",
        "metadata": {
        "description": "The admin password of the VM"
      }
    },
    "storageWorkloadType": {
      "type": "String",
      "defaultValue": "General",
      "allowedValues": [
        "General",
        "OLTP",
        "DW"
      ],
      "metadata": {
        "description": "SQL Server Workload Type"
      }
    },
    "sqlVirtualMachineName": {
        "type": "string",
        "defaultValue": "ion5eddb999"
    },
    "sqlDataDisksCount": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "maxValue": 8,
      "metadata": {
        "description": "Amount of data disks (1TB each) for SQL Data files"
      }
    },
    "dataPath": {
      "type": "String",
      "defaultValue": "F:\SQLData",
      "metadata": {
        "description": "Path for SQL Data files. Please choose drive letter from F to Z, and other drives from A to E are reserved for system"
      }
    },
    "sqlLogDisksCount": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "maxValue": 8,
      "metadata": {
        "description": "Amount of data disks (1TB each) for SQL Log files"
      }
    },
    "logPath": {
      "type": "String",
      "defaultValue": "G:\SQLLog",
      "metadata": {
        "description": "Path for SQL Log files. Please choose drive letter from F to Z and different than the one used for SQL data. Drive letter from A to E are reserved for system"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {
    "networkInterfaceName": "[concat(parameters('virtualMachineName'), '-nic')]",
    //"networkSecurityGroupName": "[concat(parameters('virtualMachineName'), '-nsg')]",
    "diskConfigurationType": "NEW",
    "subnetRef": "[resourceID(parameters('existingVNetResourceGroup'), 'Microsoft.Network/virtualNetWorks/subnets', parameters('existingVirtualNetworkName'), parameters('existingSubNetName'))]",
    "dataDisksLuns": "[array(range(0 ,parameters('sqlDataDisksCount')))]",
    "logDisksLuns": "[array(range(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount')))]",
    "dataDisks": {
      "createOption": "empty",
      "caching": "ReadOnly",
      "writeAcceleratorEnabled": false,
      "storageAccountType": "StandardSSD_LRS",
      "diskSizeGB": 100
    },
    "tempDbPath": "D:\SQLTemp"
  },
  "resources": [
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2020-06-01",
      "name": "[variables('networkInterfaceName')]",
      "location": "[parameters('location')]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "subnet": {
                "id": "[variables('subnetRef')]"
              },
              "privateIPAllocationMethod": "Static",
              "privateIPAddress": "[parameters('ipAddress')]",
              "privateIPAddressVersion": "IPv4"
            }
          }
        ],
        "enableAcceleratedNetworking": false
        }
    },
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2020-06-01",
      "name": "[parameters('virtualMachineName')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('virtualMachineSize')]"
        },
        "storageProfile": {
          "osDisk": {
            "createOption": "fromImage",
            "managedDisk": {
              "storageAccountType": "StandardSSD_LRS"
            }
          },
          "imageReference": {
            "publisher": "MicrosoftSQLServer",
            "offer": "[parameters('imageOffer')]",
            "sku": "[parameters('sqlSku')]",
            "version": "latest"
          },
          "copy": [
            {
              "name": "dataDisks",
              "count": "[add(parameters('sqlDataDisksCount'), parameters('sqlLogDisksCount'))]",
              "input": {
                "lun": "[copyIndex('dataDisks')]",
                "createOption": "[variables('dataDisks').createOption]",
                "caching": "[if(greaterOrEquals(copyIndex('dataDisks'), parameters('sqlDataDisksCount')) ,'None', variables('dataDisks').caching )]",
                "writeAcceleratorEnabled": "[variables('dataDisks').writeAcceleratorEnabled]",
                "diskSizeGB": "[variables('dataDisks').diskSizeGB]",
                "managedDisk": {
                  "storageAccountType": "[variables('dataDisks').storageAccountType]"
                }
              }
            }
          ]
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
            }
          ]
        },
        "osProfile": {
          "computerName": "[parameters('virtualMachineName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]",
          "windowsConfiguration": {
            "enableAutomaticUpdates": true,
            "provisionVmAgent": true
          }
        }
      }
    },
    {
      "type": "Microsoft.SqlVirtualMachine/SqlVirtualMachines",
      "apiVersion": "2017-03-01-preview",
      "name": "[last(split(resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName')),'/'))]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
      ],
      "properties": {
        "virtualMachineResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
        "sqlManagement": "Full",
        "SqlServerLicenseType": "PAYG",
        "StorageConfigurationSettings": {
          "DiskConfigurationType": "[variables('diskConfigurationType')]",
          "StorageWorkloadType": "[parameters('storageWorkloadType')]",
          "SQLDataSettings": {
            "LUNs": "[variables('dataDisksLUNs')]",
            "DefaultFilePath": "[parameters('dataPath')]"
          },
          "SQLLogSettings": {
            "Luns": "[variables('logDisksLUNs')]",
            "DefaultFilePath": "[parameters('logPath')]"
          },
          "SQLTempDbSettings": {
            "DefaultFilePath": "[variables('tempDbPath')]"
          }
        }
      }
    }
  ],
  "outputs": {
    "virtualMachine": {
        "type": "object",
        "value": "[reference(parameters('virtualMachineName'))]"
    }
  }
}

您的输出使用:

  "outputs": {
    "virtualMachine": {
        "type": "object",
        "value": "[reference(resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName')))]"
    },
    "sqlVirtualMachine": {
        "type": "object",
        "value": "[reference(resourceId('Microsoft.SqlVirtualMachine/SqlVirtualMachines', parameters('virtualMachineName')))]"
    }
  }

取决于您想要什么...您可以将它们命名为相同的名称,但对它们的任何引用(dependsOn、reference())都必须是明确的。