_This issue was originally opened by @tomasquith as hashicorp/terraform#14211. It was migrated here as part of the provider split. The original body of the issue is below._
0.9.4
azurerm_virtual_machine
azurerm_managed_disk
variable "resource_group_name" {
default = "tom-managed-tf-test"
}
variable "location" {
default = "uksouth"
}
variable "hostname" {
default = "tom-test-vm"
}
variable "source_vhd_path" {
default = ""
}
resource "azurerm_resource_group" "rg" {
name = "${var.resource_group_name}"
location = "${var.location}"
}
resource "azurerm_virtual_network" "vnet" {
name = "toms-vnet"
location = "${var.location}"
address_space = ["10.0.0.0/16"]
resource_group_name = "${azurerm_resource_group.rg.name}"
}
resource "azurerm_subnet" "subnet" {
name = "tom-subnet"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
address_prefix = "10.0.10.0/24"
}
resource "azurerm_network_interface" "nic" {
name = "${var.hostname}-nic"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
ip_configuration {
name = "${var.hostname}-ipconfig"
subnet_id = "${azurerm_subnet.subnet.id}"
private_ip_address_allocation = "Dynamic"
public_ip_address_id = "${azurerm_public_ip.pip.id}"
}
}
resource "azurerm_public_ip" "pip" {
name = "${var.hostname}-ip"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "Dynamic"
}
# import an existing (generalised) vhd to create a managed disk.
resource "azurerm_managed_disk" "osdisk" {
name = "${var.hostname}-osdisk"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
#os_type = "linux"
storage_account_type = "Standard_LRS"
create_option = "Import"
source_uri = "${var.source_vhd_path}"
disk_size_gb = "31"
}
resource "azurerm_managed_disk" "datadisk" {
name = "${var.hostname}-datadisk"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "31"
}
resource "azurerm_virtual_machine" "vm" {
name = "${var.hostname}-vm"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
vm_size = "Standard_A0"
network_interface_ids = ["${azurerm_network_interface.nic.id}"]
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
# attach the managed disk, created from the imported vhd.
storage_os_disk {
name = "${var.hostname}-osdisk"
# if this is provided, os_profile is not allowed
os_type = "linux"
managed_disk_id = "${azurerm_managed_disk.osdisk.id}"
managed_disk_type = "Standard_LRS"
caching = "ReadWrite"
create_option = "Attach"
}
storage_data_disk {
name = "${var.hostname}-datadisk"
managed_disk_id = "${azurerm_managed_disk.datadisk.id}"
managed_disk_type = "Standard_LRS"
disk_size_gb = "31"
create_option = "Attach"
lun = 0
}
os_profile {
computer_name = "${var.hostname}"
admin_username = "centos"
admin_password = "Cent0s"
custom_data = "${base64encode("touch ~/userdatatest.txt")}"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/centos/.ssh/authorized_keys"
key_data = "${file("~/.ssh/id_rsa.pub")}"
}
}
}
I'd expect to use my imported (generalised) vhd - now in managed disk form, attach this to a VM, then run userdata.
I'm not sure if this is an Azure quirk, it seems like some people are having similar issues with the powershell cmdlets or SDKs. I've linked these below.
The PR https://github.com/hashicorp/terraform/pull/13960 seems to address this for my use case.
If the os_type is set on the os_disk (required) then os_profile cannot be provided, meaning I can't run cloud-init or set the computer name.
Please list the steps required to reproduce the issue, for example:
Packer created CentOS 7.3 image, generalised with the following '/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync'
Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:
https://github.com/hashicorp/terraform/issues/11147
https://github.com/Azure/azure-powershell/issues/1597
Any news on this?
Hi Tom,
We are currently looking into this. You can track status of this in the related project
Thanks,
Arun
Hey @tomasquith, it looks like os_type is no longer required for the os_disk. Can you confirm that this is still an issue for you?
Closing this but feel free to reopen if it's still causing you issues
This is still a problem for me. If I omit os_type from the vm resource's storage_os_disk section I get this when I apply:
* azurerm_virtual_machine.vm: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidParameter" Message="Required parameter 'osDisk.osType' is missing (null)."
Here's my config for reference:
resource "azurerm_virtual_machine" "vm" {
name = "${var.rg_prefix}vm"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
vm_size = "${var.vm_size}"
network_interface_ids = ["${azurerm_network_interface.nic.id}"]
storage_os_disk {
name = "${var.hostname}-osdisk"
managed_disk_id = "${azurerm_managed_disk.osdisk.id}"
create_option = "Attach"
}
storage_data_disk {
name = "${var.hostname}-datadisk"
managed_disk_id = "${azurerm_managed_disk.datadisk.id}"
create_option = "Attach"
disk_size_gb = "${azurerm_managed_disk.datadisk.disk_size_gb}"
lun = 0
}
os_profile {
computer_name = "${var.hostname}"
admin_username = "${var.admin_username}"
}
}
This is still a problem for me. If I omit
os_typefrom the vm resource'sstorage_os_disksection I get this when I apply:* azurerm_virtual_machine.vm: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidParameter" Message="Required parameter 'osDisk.osType' is missing (null)."Here's my config for reference:
resource "azurerm_virtual_machine" "vm" { name = "${var.rg_prefix}vm" location = "${var.location}" resource_group_name = "${azurerm_resource_group.rg.name}" vm_size = "${var.vm_size}" network_interface_ids = ["${azurerm_network_interface.nic.id}"] storage_os_disk { name = "${var.hostname}-osdisk" managed_disk_id = "${azurerm_managed_disk.osdisk.id}" create_option = "Attach" } storage_data_disk { name = "${var.hostname}-datadisk" managed_disk_id = "${azurerm_managed_disk.datadisk.id}" create_option = "Attach" disk_size_gb = "${azurerm_managed_disk.datadisk.disk_size_gb}" lun = 0 } os_profile { computer_name = "${var.hostname}" admin_username = "${var.admin_username}" } }
Did you manage to get this working as I still have the issue as well
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!
Most helpful comment
This is still a problem for me. If I omit
os_typefrom the vm resource'sstorage_os_disksection I get this when I apply:Here's my config for reference: