创建 azure 虚拟机并附加托管磁盘(从快照创建)
得到错误,
“如果 VM 是从平台、用户或共享库映像创建的,则无法附加现有的 OS 磁盘
尝试将“创建选项”中的调整为“复制”、“导入”等,但都没有成功
代码如下,
provider "azurerm" {
subscription_id = "abcd"
features {}
}
resource "azurerm_managed_disk" "example" {
name = "managed-disk-01"
location = "East US"
resource_group_name = "RG-APP"
storage_account_type = "Premium_LRS"
create_option = "Copy"
disk_size_gb = "127"
source_resource_id = azurerm_snapshot.example.id
os_type = "Windows"
}
resource "azurerm_snapshot" "example" {
name = "snapshot"
location = "East US"
resource_group_name = "RG-APP"
create_option = "Copy"
source_uri = "/subscriptions/abcv/resourceGroups/RG-APP/providers/Microsoft.Compute/disk/AppA_OsDisk_1_0e"
}
data "azurerm_subnet" "subnet" {
name = "vnet-sn-app"
resource_group_name = "rg-network"
virtual_network_name = "vnet"
}
resource "azurerm_network_interface" "example" {
name = "example-nic"
location = "East US"
resource_group_name = "RG-APP"
ip_configuration {
name = "ipconfig"
subnet_id = "${data.azurerm_subnet.subnet.id}"
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_availability_set" "DemoAset" {
name = "example-aset"
location = "East US"
resource_group_name = "RG-APP"
}
resource "azurerm_virtual_machine" "example" {
name = "example-machine-01"
resource_group_name = "RG-APP"
location = "East US"
vm_size = "Standard_F2"
availability_set_id = azurerm_availability_set.DemoAset.id
delete_os_disk_on_termination = false
delete_data_disks_on_termination = false
network_interface_ids = [
azurerm_network_interface.example.id,
]
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_windows_config {
provision_vm_agent ="true"
}
storage_os_disk {
name = "myosdisk1"
managed_disk_id = "${azurerm_managed_disk.example.id}"
caching = "ReadWrite"
create_option = "Attach"
}
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}
}
请帮助指导解决此问题。谢谢!