无法使用ARM模板创建VM

时间:2019-03-05 17:21:21

标签: azure azure-resource-manager arm-template

我正在尝试使用ARM模板创建虚拟机。我已经创建了NIC,VNET,子网等。但是,当尝试创建虚拟机时,出现了解析错误。

  

New-AzDeployment:17:13:38-资源   Microsoft.Compute / virtualMachines“之前”失败,并显示消息“ {
  “错误”:{       “细节”: [],       “ code”:“ InvalidRequestFormat”,       “ message”:“无法解析请求。” }}'在第1行:char:1   + New-AzDeployment-位置“ UK West” -TemplateFile“ C:\ Users \ Matt.Lea ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:未指定:(:) [New-AzDeployment],异常       + FullyQualifiedErrorId:Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureDeploymentCmdlet

我正在使用以下JSON创建虚拟机。

"resources": [
    {
        "name": "[parameters('DR Network RG')]",
        "type": "Microsoft.Resources/resourceGroups",
        "apiVersion": "2018-05-01",
        "location": "[variables('Location')]",
        "tags": {},
        "properties": {}
    },
    {
        "name": "[parameters('HUB Network RG')]",
        "type": "Microsoft.Resources/resourceGroups",
        "apiVersion": "2018-05-01",
        "location": "[variables('Location')]",
        "tags": {},
        "properties": {}
    },
    {
        "name": "[parameters('Test DR Network RG')]",
        "type": "Microsoft.Resources/resourceGroups",
        "apiVersion": "2018-05-01",
        "location": "[variables('Location')]",
        "tags": {},
        "properties": {}
    },
    {
        "name": "[variables('hubsharedrg')]",
        "type": "Microsoft.Resources/resourceGroups",
        "apiVersion": "2018-05-01",
        "location": "[variables('Location')]",
        "tags": {},
        "properties": {}
    },
    {
        "name": "[variables('DRVMRG')]",
        "type": "Microsoft.Resources/resourceGroups",
        "apiVersion": "2018-05-01",
        "location": "[variables('Location')]",
        "tags": {},
        "properties": {}
    },
    {
        "name": "[variables('DRTESTVMRG')]",
        "type": "Microsoft.Resources/resourceGroups",
        "apiVersion": "2018-05-01",
        "location": "[variables('Location')]",
        "tags": {},
        "properties": {}
    },
    {
        "name": "[variables('rsvrg')]",
        "type": "Microsoft.Resources/resourceGroups",
        "apiVersion": "2018-05-01",
        "location": "[variables('Location')]",
        "tags": {},
        "properties": {}
    },
    {
        "apiVersion": "2017-05-10",
        "name": "DR-Template",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('DR Network RG')]",
        "dependsOn": [
            "[resourceId('Microsoft.Resources/resourceGroups/', parameters('DR Network RG'))]",
            "[resourceId('Microsoft.Resources/resourceGroups/', parameters('HUB Network RG'))]",
            "[resourceId('Microsoft.Resources/resourceGroups/', parameters('Test DR Network RG'))]"
        ],
        "properties": {
            "mode": "incremental",
            "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentversion": "1.0.0.0",
                "parameters": {},
                "variables": {},
                "resources": [
                    {
                        "apiVersion": "2017-06-01",
                        "type": "Microsoft.Network/virtualNetworks",
                        "name": "[parameters('DR VNet')]",
                        "dependsOn": [
                            "[concat('Microsoft.Network/networkSecurityGroups/', variables('DRNetworkSecurityGroup'))]"
                        ],
                        "location": "[variables('Location')]",
                        "properties": {
                            "addressSpace": {
                                "addressPrefixes": [
                                    "[parameters('DR vnetAddressPrefix')]"
                                ]
                            },
                            "subnets": [
                                {
                                    "name": "[parameters('DR Failover Subnet')]",
                                    "properties": {
                                        "addressPrefix": "[parameters('DR Failover Subnet Address Prefix')]"
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "apiVersion": "2015-06-15",
                        "type": "Microsoft.Network/networkSecurityGroups",
                        "name": "[variables('DRNetworkSecurityGroup')]",
                        "location": "[variables('location')]",
                        "properties": {
                            "securityRules": []
                        }
                    }
                ]
            }
        }
    },
    {
        "apiVersion": "2017-05-10",
        "name": "HUB-Template",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('HUB Network RG')]",
        "dependsOn": [
            "DR-Template"
        ],
        "properties": {
            "mode": "incremental",
            "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentversion": "1.0.0.0",
                "parameters": {},
                "variables": {},
                "resources": [
                    {
                        "apiVersion": "2017-06-01",
                        "type": "Microsoft.Network/virtualNetworks",
                        "name": "[parameters('HUB vnet')]",
                        "dependsOn": [
                            "[concat('Microsoft.Network/networkSecurityGroups/', variables('DomainControllerNSG'))]"
                        ],
                        "location": "[variables('Location')]",
                        "properties": {
                            "addressSpace": {
                                "addressPrefixes": [
                                    "[parameters('HUB vnetAddressPrefix')]"
                                ]
                            },
                            "subnets": [
                                {
                                    "name": "[parameters('HUB DC Subnet')]",
                                    "properties": {
                                        "addressPrefix": "[parameters('HUB DC Subnet AddressPrefix')]"
                                    }
                                },
                                {
                                    "name": "[parameters('Gateway Subnet')]",
                                    "properties": {
                                        "addressPrefix": "[parameters('Gateway Subnet AddressPrefix')]"
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "apiVersion": "2015-06-15",
                        "type": "Microsoft.Network/networkSecurityGroups",
                        "name": "[variables('DomainControllerNSG')]",
                        "location": "[variables('location')]",
                        "properties": {
                            "securityRules": []
                        }
                    }
                ]
            }
        }
    },
    {
        "apiVersion": "2017-05-10",
        "name": "DR-TEST-Template",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('Test DR Network RG')]",
        "dependsOn": [
            "HUB-Template"
        ],
        "properties": {
            "mode": "incremental",
            "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentversion": "1.0.0.0",
                "parameters": {},
                "variables": {},
                "resources": [
                    {
                        "apiVersion": "2017-06-01",
                        "type": "Microsoft.Network/virtualNetworks",
                        "name": "[parameters('Test DR vnet')]",
                        "dependsOn": [
                            "[concat('Microsoft.Network/networkSecurityGroups/', variables('DRtestNSG'))]"
                        ],
                        "location": "[variables('Location')]",
                        "properties": {
                            "addressSpace": {
                                "addressPrefixes": [
                                    "[parameters('Test DR vnetAddressPrefix')]"
                                ]
                            },
                            "subnets": [
                                {
                                    "name": "[parameters('Test DR Subnet')]",
                                    "properties": {
                                        "addressPrefix": "[parameters('Test DR Subnet AddressPrefix')]"
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "apiVersion": "2015-06-15",
                        "type": "Microsoft.Network/networkSecurityGroups",
                        "name": "[variables('DRtestNSG')]",
                        "location": "[variables('location')]",
                        "properties": {
                            "securityRules": []
                        }
                    }
                ]
            }
        }
    },
    {
        "apiVersion": "2017-05-10",
        "name": "DC-Template",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[variables('hubsharedrg')]",
        "dependsOn": [
            "DR-TEST-Template"
        ],
        "properties": {
            "mode": "incremental",
            "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentversion": "1.0.0.0",
                "parameters": {},
                "variables": {},
                "resources": [
                    {
                        "type": "Microsoft.Storage/storageAccounts",
                        "name": "[variables('storageAccountName')]",
                        "location": "[variables('location')]",
                        "apiVersion": "2018-07-01",
                        "sku": {
                            "name": "[variables('storageaccountsku')]"
                        },
                        "kind": "Storage",
                        "properties": {}
                    },
                    {
                        "type": "Microsoft.Network/networkInterfaces",
                        "name": "[variables('nicnamedc1')]",
                        "location": "[variables('location')]",
                        "apiVersion": "2018-10-01",
                        "properties": {
                            "ipConfigurations": [
                                {
                                    "name": "ipconfig1",
                                    "properties": {
                                        "privateIPAllocationMethod": "Dynamic",
                                        "subnet": {
                                            "id": "[variables('subnetRef')]"
                                        }
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "name": "[variables('vmnamedc1')]",
                        "type": "Microsoft.Compute/virtualMachines",
                        "location": "[variables('location')]",
                        "apiVersion": "2017-03-30",
                        "tags": {},
                        "properties": {
                            "hardwareProfile": {
                                "vmSize": "[variables('vmSize')]"
                            },
                            "osProfile": {
                                "computerName": "[variables('vmnamedc1')]",
                                "adminUsername": "[parameters('AdminUserName')]",
                                "adminPassword": "[parameters('AdminPassword')]"
                            },
                            "storageProfile": {
                                "imageReference": {
                                    "publisher": "[variables('vmImagePublisher')]",
                                    "offer": "[variables('vm1ImageOffer')]",
                                    "sku": "[parameters('WindowsOSVersion')]",
                                    "version": "latest"
                                },
                                "osDisk": {
                                    "name": "[concat(variables('vmnamedc1'),'_OSDisk')]",
                                    "caching": "ReadWrite",
                                    "createOption": "FromImage"
                                },
                                "dataDisks": [
                                    {
                                        "name": "[concat(variables('vmnamedc1'),'_DataDisk1')]",
                                        "lun": 0,
                                        "diskSizeGB": "100",
                                        "caching": "None",
                                        "createOption": "Empty"
                                    }
                                ]
                            },
                            "networkProfile": {
                                "networkInterfaces": [
                                    {
                                        "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicnamedc1'))]"
                                    }
                                ]
                            }
                        }
                    }
                ]
            }
        }
    }
]

1 个答案:

答案 0 :(得分:0)

是的,使用VSCode,它没有显示任何错误。同样,test-azdeployment也不会返回任何错误。尽管从未构建过VM。