如何使用 ARM 模板或 Azure.NetSDK 更改现有的 azure 虚拟机大小
How to change existing azure virtual machine size using ARM template or Azure.NetSDK
我想更改我的虚拟机大小。
修改现有 VM 大小的 ARM 模板片段:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualMachine_name": {
"defaultValue": "myvm",
"type": "String"
},
"disk_OS_externalid": {
"defaultValue": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxxxx-xxxxx/providers/Microsoft.Compute/disks/myvm_OsDisk_1_4db7cb0985634db6b86e93392286c2ac",
"type": "String"
},
"networkInterface_externalid": {
"defaultValue": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxxxx-xxxxx/providers/Microsoft.Network/networkInterfaces/myvm345",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-03-01",
"name": "[parameters('virtualMachine_name')]",
"location": "westus2",
"zones": [
"1"
],
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/AzSecPackAutoConfigRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/AzSecPackAutoConfigUA-westus2": {
"principalId": "6ccdb9b1-6cce-4a62-qazx-e814d59f3365",
"clientId": "9ad4fcb5-9485-4951-qgsa-654f64039941"
}
}
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_B1s"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsDesktop",
"offer": "Windows-10",
"sku": "20h2-pro",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"name": "[concat(parameters('virtualMachine_name'), '_OsDisk_1_4db7cb0985634db6b86e93392286c2ac')]",
"createOption": "FromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS",
"id": "[parameters('disk_OS_externalid')]"
},
"diskSizeGB": 127
},
"dataDisks": []
},
"osProfile": {
"computerName": "[parameters('virtualMachine_name')]",
"adminUsername": "azureuser",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS",
"assessmentMode": "ImageDefault",
"enableHotpatching": false
}
},
"secrets": [],
"allowExtensionOperations": true,
"requireGuestProvisionSignal": true
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[parameters('networkInterface_externalid')]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"licenseType": "Windows_Client"
}
}
]
}
这是一个 Azure Sample you can tweak to do the same using the newer Resource Management (Preview) 库。
我想更改我的虚拟机大小。
修改现有 VM 大小的 ARM 模板片段:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualMachine_name": {
"defaultValue": "myvm",
"type": "String"
},
"disk_OS_externalid": {
"defaultValue": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxxxx-xxxxx/providers/Microsoft.Compute/disks/myvm_OsDisk_1_4db7cb0985634db6b86e93392286c2ac",
"type": "String"
},
"networkInterface_externalid": {
"defaultValue": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxxxx-xxxxx/providers/Microsoft.Network/networkInterfaces/myvm345",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-03-01",
"name": "[parameters('virtualMachine_name')]",
"location": "westus2",
"zones": [
"1"
],
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/AzSecPackAutoConfigRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/AzSecPackAutoConfigUA-westus2": {
"principalId": "6ccdb9b1-6cce-4a62-qazx-e814d59f3365",
"clientId": "9ad4fcb5-9485-4951-qgsa-654f64039941"
}
}
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_B1s"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsDesktop",
"offer": "Windows-10",
"sku": "20h2-pro",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"name": "[concat(parameters('virtualMachine_name'), '_OsDisk_1_4db7cb0985634db6b86e93392286c2ac')]",
"createOption": "FromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Premium_LRS",
"id": "[parameters('disk_OS_externalid')]"
},
"diskSizeGB": 127
},
"dataDisks": []
},
"osProfile": {
"computerName": "[parameters('virtualMachine_name')]",
"adminUsername": "azureuser",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS",
"assessmentMode": "ImageDefault",
"enableHotpatching": false
}
},
"secrets": [],
"allowExtensionOperations": true,
"requireGuestProvisionSignal": true
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[parameters('networkInterface_externalid')]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"licenseType": "Windows_Client"
}
}
]
}
这是一个 Azure Sample you can tweak to do the same using the newer Resource Management (Preview) 库。