用于使用现有VHD Uri(osDiskVHDUri)在azure中创建VM的ARM模板&;加入域
用例描述: 我有一个用例,在这个用例中,我们需要使用存储帐户中现有的VHD Uri在azure中创建一个VM&同一个ARM模板应该具有加入域的可行性。目前,正在尝试使用和执行ARM模板,该模板仅具有使用现有VHD Uri和创建VM的灵活性(该Uri将充当“OsDiskVhdUri”)&另一个模板仅具有创建新VM和加入域的能力。这些模板是独立工作的 关键高亮显示:-用于使用现有VHD Uri(osDiskVHDUri)在azure中创建VM的ARM模板&;加入域,azure,uri,azure-storage,arm-template,azure-blueprints,Azure,Uri,Azure Storage,Arm Template,Azure Blueprints,用例描述: 我有一个用例,在这个用例中,我们需要使用存储帐户中现有的VHD Uri在azure中创建一个VM&同一个ARM模板应该具有加入域的可行性。目前,正在尝试使用和执行ARM模板,该模板仅具有使用现有VHD Uri和创建VM的灵活性(该Uri将充当“OsDiskVhdUri”)&另一个模板仅具有创建新VM和加入域的能力。这些模板是独立工作的 关键高亮显示:- 需要同时具有“OsDiskVhdUri”和域联接参数的模板 模板引用应该是“OsDiskVhdUri”,因为当我尝试集成这两个模板
- 需要同时具有“OsDiskVhdUri”和域联接参数的模板
- 模板引用应该是“OsDiskVhdUri”,因为当我尝试集成这两个模板并进行故障排除时,部署时会出现与映像引用相关的错误
- 非常重要的一点是,当blueprint assignment请求OsDiskVhdUri参数时,ARM模板,尽管我给出了创建VM的Uri,但使用下面的模板,它似乎不接受该Uri“而是每次创建一个新VM并连接到域
- 部署方法是Azure中的blueprint
{
"$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')]"
}
}
}
]
}
{
“$schema”:”https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
“内容版本”:“1.0.0.0”,
“参数”:{
“existingVNETName”:{
“类型”:“字符串”,
“元数据”:{
“描述”:“包含域控制器的现有VNET”
}
},
“osDiskVhdUri”:{
“类型”:“字符串”,
“元数据”:{
“描述”:“ARM标准或高级存储中现有VHD的Uri”
}
},
“osType”:{
“类型”:“字符串”,
“defaultValue”:“2019数据中心”,
“允许值”:[
“2019数据中心”
],
“元数据”:{
“说明”:“虚拟机的Windows版本。允许的值:2008-R2-SP1、2012数据中心、2012-R2-Datacenter。”
}
},
“existingSubnetName”:{
“类型”:“字符串”,
“元数据”:{
“说明”:“包含域控制器的现有子网”
}
},
“vmname”:{
“类型”:“字符串”,
“元数据”:{
“description:“部署的唯一公共DNS前缀。fqdn类似于“.westus.cloudapp.azure.com”。最多62个字符、数字或破折号(小写)应以字母开头:必须符合“^[a-z][a-z0-9-]{1,61}[a-z0-9]$”
}
},
“vmSize”:{
“类型”:“字符串”,
“defaultValue”:“Standard_D2_v2”,
“元数据”:{
“说明”:“虚拟机的大小”
}
},
“域名之路”:{
“类型”:“字符串”,
“元数据”:{
“说明”:“AD域的FQDN”
}
},
“域名用户名”:{
“类型”:“字符串”,
“元数据”:{
“说明”:“域上帐户的用户名”
}
},
“域密码”:{
“类型”:“字符串”,
“元数据”:{
“说明”:“域上帐户的密码”
}
},
“ouPath”:{
“类型”:“字符串”,
“defaultValue”:“,
“元数据”:{
“描述”:“指定域帐户的组织单位(OU)。在引号中输入OU的完整可分辨名称。示例:\“OU=testOU;DC=domain;DC=domain;DC=com”
}
},
“domainJoinOptions”:{
“类型”:“int”,
“默认值”:3,
“元数据”:{
“description”:“定义连接选项的一组位标志。默认值3是NETSETUP_join_DOMAIN(0x00000001)和NETSETUP_ACCT_CREATE(0x00000002)的组合,即将加入域并在域上创建帐户。有关更多信息,请参阅https://msdn.microsoft.com/en-us/library/aa392154(v=vs.85).aspx“
}
},
“vmAdminUsername”:{
“类型”:“字符串”,
“元数据”:{
“描述”:“新VM和域的管理员的名称。排除列表:'管理员','管理员'
}
},
“vmAdminPassword”:{
“类型”:“字符串”,
“元数据”:{
“描述”:“新VM和域的管理员帐户的密码”
}
},
“地点”:{
“类型”:“字符串”,
“defaultValue”:“美国东部”,
“元数据”:{
“说明”:“所有资源的位置。”
}
}
},
“变量”:{
“storageAccountName:“[concat('diags',uniquestring(resourceGroup().id))]”,
“diskName”:“[concat('diags',uniquestring(resourceGroup().id))]”,
“osDiskVhdUri”:“[concat(参数('osDiskVhdUri'),'-image')”,
“nicName”:“[concat(参数('vmname'),'Nic')]”,
“publicIPName”:“[concat(参数('vmname'),'Pip')]”,
“子网ID”:“[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks/subnets',参数('existingVNETName'),参数('existingSubnetName'))]
{
"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]"
}
}
}
}