我希望将市场映像获取到托管磁盘,然后将此托管磁盘连接到具有Terraform的Azure虚拟机。
这可以更改虚拟机配置,在该配置中,销毁和重建操作可以使虚拟机保持完整。
我发现有人也有类似的问题,但是这些问题被解决了,没有实现该目标的范例。
对于平台图片
data "azurerm_platform_image" "2016-Datacenter" {
location = "West Europe"
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
}
使用平台映像创建托管磁盘
resource "azurerm_managed_disk" "Server-osdisk" {
resource_group_name = "rgroup"
location = "West Europe"
create_option = "FromImage"
image_reference_id = "${data.azurerm_platform_image.server2016.id}"
disk_size_gb = "127"
name = "Server-osdisk"
storage_account_type = "Standard_LRS"
}
然后在azurerm_virtual_machine
resource "azurerm_virtual_machine" "main" {
# ...
os_profile {
computer_name = "Server"
admin_username = ""
admin_password = ""
}
storage_os_disk {
managed_disk_id = "${azurerm_managed_disk.Server-osdisk.id}"
# os_type = "Windows"
managed_disk_type = "Premium_LRS"
caching = "ReadWrite"
create_option = "Attach"
name = "Server"
}
}
投掷
状态= 400代码=“ InvalidParameter”消息=“必需参数 缺少“ osDisk.osType”(空)。“ Target =” osDisk.osType“
如果在其中添加os_type
,则说明计算机名,用户名和密码都不能包含os_profile
有同样问题的人
Terraform creating VM from managed disk image made in Packer
尝试解决方案,但抛出上述错误
我在这方面想念什么?
答案 0 :(得分:0)
对于您的问题,我尝试解决。您将事情更改为自己的,这只是一个例子。此处的文件:
resource "azurerm_resource_group" "main" {
name = "acctestRG"
location = "West Europe"
}
data "azurerm_platform_image" "linux" {
location = "West Europe"
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
}
resource "azurerm_managed_disk" "source" {
name = "acctestmd1"
location = "West Europe"
resource_group_name = "${azurerm_resource_group.main.name}"
storage_account_type = "Standard_LRS"
create_option = "FromImage"
image_reference_id = "${data.azurerm_platform_image.linux.id}"
tags {
environment = "staging"
}
}
resource "azurerm_virtual_network" "main" {
name = "azuretestvnet"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
}
resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = "${azurerm_resource_group.main.name}"
virtual_network_name = "${azurerm_virtual_network.main.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "main" {
name = "azuretestnic"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.internal.id}"
private_ip_address_allocation = "dynamic"
}
}
resource "azurerm_virtual_machine" "main" {
name = "azurevm"
location = "West Europe"
resource_group_name = "${azurerm_resource_group.main.name}"
network_interface_ids = ["${azurerm_network_interface.main.id}"]
vm_size = "Standard_DS1_v2"
storage_os_disk {
os_type = "Linux"
name = "acctestmd1"
managed_disk_type = "Standard_LRS"
caching = "ReadWrite"
create_option = "Attach"
managed_disk_id = "${azurerm_managed_disk.source.id}"
}
os_profile_linux_config {
disable_password_authentication = false
}
}
我遇到了一些事情,我想你应该注意它们。
希望这会对您有所帮助。