0

用例描述

我有一个用例,我们需要使用存储帐户中可用的现有 VHD Uri 在 Azure 中创建一个 VM,并且相同的 ARM 模板应该具有加入域的可行性。目前正在尝试工作和执行 ARM 模板,该模板仅具有使用现有 VHD Uri 和创建 VM 的灵活性(此 Uri 将充当“OsDiskVhdUri”),另一个模板只能创建新 VM 并加入域这些都是独立工作的。

主要荧光笔:-

  • 需要一个同时具有“OsDiskVhdUri”和域加入参数的模板。
  • 模板参考应该是“OsDiskVhdUri”,因为当我尝试集成模板和故障排除时 - 部署时出现与图像参考相关的错误。
  • 非常重要的一点是 - 蓝图分配时的 ARM 模板要求提供 OsDiskVhdUri 参数,尽管我提供了用于创建 VM 的 Uri,但使用下面的模板,它似乎并没有采用该 Uri”,而是每次创建一个新 VM时间并附加到域。
  • 部署方法是 Azure 中的蓝图。

错误:- 由于以下错误,类型“模板”未能部署:模板部署失败,错误 [{“消息”:“在“ImageReference”类型的对象上找不到成员“osDiskVhdUri”。路径“properties.storageProfile.imageReference .osDiskVhdUri',第 1 行,位置 237。” }

用尽了所有方法,发现更深入地研究它&对此的任何指导将不胜感激!

参考代码:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "existingVNETName": {
            "type": "string",
            "metadata": {
                "description": "Existing VNET that contains the domain controller"
            }
        },
        "osDiskVhdUri": {
            "type": "string",
            "metadata": {
                "description": "Uri of the existing VHD in ARM standard or premium storage"
            }
        },
        "osType": {
      "type": "string",
      "defaultValue": "2019-Datacenter",
      "allowedValues": [
        
        "2019-Datacenter"
        
                                
      ],
      "metadata": {
        "description": "The Windows version for the VMs. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter."
      }
    },
        "existingSubnetName": {
            "type": "string",
            "metadata": {
                "description": "Existing subnet that contains the domain controller"
            }
        },
        "vmname": {
            "type": "string",
            "metadata": {
                "description": "Unique public DNS prefix for the deployment. The fqdn will look something like '<dnsname>.westus.cloudapp.azure.com'. Up to 62 chars, digits or dashes, lowercase, should start with a letter: must conform to '^[a-z][a-z0-9-]{1,61}[a-z0-9]$'."
            }
        },
        "vmSize": {
            "type": "string",
            "defaultValue": "Standard_D2_v2",
            "metadata": {
                "description": "The size of the virtual machines"
            }
        },
        "domainToJoin": {
            "type": "string",
            "metadata": {
                "description": "The FQDN of the AD domain"
            }
        },
        "domainUsername": {
            "type": "string",
            "metadata": {
                "description": "Username of the account on the domain"
            }
        },
        "domainPassword": {
            "type": "string",
            "metadata": {
                "description": "Password of the account on the domain"
            }
        },
        "ouPath": {
            "type": "string",
            "defaultValue": "",
            "metadata": {
                "description": "Specifies an organizational unit (OU) for the domain account. Enter the full distinguished name of the OU in quotation marks. Example: \"OU=testOU; DC=domain; DC=Domain; DC=com\""
            }
        },
        "domainJoinOptions": {
            "type": "int",
            "defaultValue": 3,
            "metadata": {
                "description": "Set of bit flags that define the join options. Default value of 3 is a combination of NETSETUP_JOIN_DOMAIN (0x00000001) & NETSETUP_ACCT_CREATE (0x00000002) i.e. will join the domain and create the account on the domain. For more information see https://msdn.microsoft.com/en-us/library/aa392154(v=vs.85).aspx"
            }
        },
        "vmAdminUsername": {
            "type": "string",
            "metadata": {
                "description": "The name of the administrator of the new VM and the domain. Exclusion list: 'admin','administrator"
            }
        },
        "vmAdminPassword": {
            "type": "string",
            "metadata": {
                "description": "The password for the administrator account of the new VM and the domain"
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "East US",
            "metadata": {
                "description": "Location for all resources."
            }
        }
    },
    "variables": {
        "storageAccountName": "[concat('diags', uniquestring(resourceGroup().id))]",
        "diskName": "[concat('diags', uniquestring(resourceGroup().id))]",
        "osDiskVhdUri": "[concat(parameters('osDiskVhdUri'), '-image')]",
        "nicName": "[concat(parameters('vmname'),'Nic')]",
        "publicIPName": "[concat(parameters('vmname'),'Pip')]",
        "subnetId": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/subnets', parameters('existingVNETName'), parameters('existingSubnetName'))]"
    },
    "resources": [
        {
            "apiVersion": "2015-06-15",
            "type": "Microsoft.Network/publicIPAddresses",
            "name": "[variables('publicIPName')]",
            "location": "[parameters('location')]",
            "properties": {
                "publicIPAllocationMethod": "Dynamic",
                "dnsSettings": {
                    "domainNameLabel": "[parameters('vmname')]"
                }
            }
        },
        {
            "type": "Microsoft.Compute/disks",
            "apiVersion": "2018-09-30",
            "name": "[variables('diskName')]",
            "location": "[parameters('location')]",
            "properties": {
                "creationData": {
                    "createOption": "Import",
                    "sourceUri": "[parameters('osDiskVhdUri')]"
                }
            }
        },
        {
            "apiVersion": "2015-06-15",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[variables('storageAccountName')]",
            "location": "[parameters('location')]",
            "properties": {
                "accountType": "Standard_LRS"
            }
        },
        {
            "apiVersion": "2015-06-15",
            "type": "Microsoft.Network/networkInterfaces",
            "name": "[variables('nicName')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPName'))]"
            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig",
                        "properties": {
                            "privateIPAllocationMethod": "Dynamic",
                            "publicIPAddress": {
                                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))]"
                            },
                            "subnet": {
                                "id": "[variables('subnetId')]"
                            }
                        }
                    }
                ]
            }
        },
        {
      "type": "Microsoft.Compute/images",
      "apiVersion": "2020-06-01",
      "name": "[variables('imageName')]",
      "location": "[parameters('location')]",
      "properties": {
        "hyperVGeneration": "V2",
        "storageProfile": {
          "osDisk": {
            "osType": "[parameters('osType')]",
            "osState": "Generalized",
            "blobUri": "[parameters('osDiskVhdUri')]",
            "caching": "ReadWrite",
            "storageAccountType": "Standard_LRS"
          }
        }
      }
    },

        {
      "apiVersion": "2020-06-01",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[parameters('vmName')]",
      "location": "[parameters('location')]",
      "tags": {
        "displayName": "VirtualMachine"
      },
      "dependsOn": [
        "[variables('nicName')]",
        "[variables('imageName')]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmSize')]"
        },
        "osProfile": {
          "computerName": "[parameters('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPasswordOrKey')]",
          "linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
        },
        "storageProfile": {
          "imageReference": {
              "id": "[resourceId('Microsoft.Compute/images', variables('imageName'))]"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
            }
          ]
        },
        "diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": true,
            "storageUri": "[reference(variables('diagStorageAccountName')).primaryEndpoints.blob]"
          }
        }
      }
    },
        {
            "apiVersion": "2015-06-15",
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(parameters('vmname'),'/joindomain')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[concat('Microsoft.Compute/virtualMachines/', parameters('vmname'))]"
            ],
            "properties": {
                "publisher": "Microsoft.Compute",
                "type": "JsonADDomainExtension",
                "typeHandlerVersion": "1.3",
                "autoUpgradeMinorVersion": true,
                "settings": {
                    "Name": "[parameters('domainToJoin')]",
                    "OUPath": "[parameters('ouPath')]",
                    "User": "[concat(parameters('domainToJoin'), '\\', parameters('domainUsername'))]",
                    "Restart": "true",
                    "Options": "[parameters('domainJoinOptions')]"
                },
                "protectedSettings": {
                    "Password": "[parameters('domainPassword')]"
                }
            }
        }
    ]
}


4

1 回答 1

1

如果您想使用 vhd 文件创建 Azure VM,请更新您的模板,如下所示

{
      "type": "Microsoft.Compute/images",
      "apiVersion": "2020-06-01",
      "name": "[variables('imageName')]",
      "location": "[parameters('location')]",
      "properties": {
        "hyperVGeneration": "V2",
        "storageProfile": {
          "osDisk": {
            "osType": "[parameters('osType')]",
            "osState": "Generalized",
            "blobUri": "[parameters('osDiskVhdUri')]",
            "caching": "ReadWrite",
            "storageAccountType": "Standard_LRS"
          }
        }
      }
    },
    {
      "apiVersion": "2020-06-01",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[parameters('vmName')]",
      "location": "[parameters('location')]",
      "tags": {
        "displayName": "VirtualMachine"
      },
      "dependsOn": [
        "[variables('nicName')]",
        "[variables('imageName')]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmSize')]"
        },
        "osProfile": {
          "computerName": "[parameters('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPasswordOrKey')]",
          "linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
        },
        "storageProfile": {
          "imageReference": {
              "id": "[resourceId('Microsoft.Compute/images', variables('imageName'))]"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
            }
          ]
        },
        "diagnosticsProfile": {
          "bootDiagnostics": {
            "enabled": true,
            "storageUri": "[reference(variables('diagStorageAccountName')).primaryEndpoints.blob]"
          }
        }
      }
    }
于 2021-05-26T06:28:28.973 回答