While trying to launch a new vm with the azurerm provider it reports back with a "400 Bad Request" error.
resource "azurerm_virtual_machine" "chef_test_vm_linux" {
name = "chef_test_vm_linux"
location = "West Europe"
resource_group_name = "${azurerm_resource_group.chef_test_rg.name}"
network_interface_ids = ["ExpressRouteVNETwe"]
vm_size = "Standard_A1"
# azure vm image list westeurope openlogic
storage_image_reference {
publisher = "OpenLogic"
offer = "CentOS"
sku = "7.2"
version = "7.2.20160308"
}
storage_os_disk {
name = "disk1"
vhd_uri = "${azurerm_storage_account.chef_test_storage.primary_blob_endpoint}${azurerm_storage_container.chef_linux_container.name}/disk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
os_type = "linux"
}
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags {
env = "test"
}
}
azurerm_virtual_machine.chef_test_vm_linux: Creating...
availability_set_id: "" => "<computed>"
license_type: "" => "<computed>"
location: "" => "westeurope"
name: "" => "chef_test_vm_linux"
network_interface_ids.#: "" => "1"
network_interface_ids.2058567140: "" => "ExpressRouteVNETwe"
os_profile.#: "" => "1"
os_profile.1173764063.admin_password: "" => "Password1234!"
os_profile.1173764063.admin_username: "" => "testadmin"
os_profile.1173764063.computer_name: "" => "hostname"
os_profile.1173764063.custom_data: "" => "<computed>"
os_profile_linux_config.#: "" => "1"
os_profile_linux_config.2972667452.disable_password_authentication: "" => "false"
os_profile_linux_config.2972667452.ssh_keys.#: "" => "0"
plan.#: "" => "<computed>"
resource_group_name: "" => "chef_test_rg"
storage_image_reference.#: "" => "1"
storage_image_reference.509829681.offer: "" => "CentOS"
storage_image_reference.509829681.publisher: "" => "OpenLogic"
storage_image_reference.509829681.sku: "" => "7.2"
storage_image_reference.509829681.version: "" => "7.2.20160308"
storage_os_disk.#: "" => "1"
storage_os_disk.21370517.caching: "" => "ReadWrite"
storage_os_disk.21370517.create_option: "" => "FromImage"
storage_os_disk.21370517.image_uri: "" => ""
storage_os_disk.21370517.name: "" => "disk1"
storage_os_disk.21370517.os_type: "" => "linux"
storage_os_disk.21370517.vhd_uri: "" => "https://cts20160524.blob.core.windows.net/linuxdisk/disk1.vhd"
tags.#: "" => "2"
tags.env: "" => "test"
vm_size: "" => "Standard_A1"
Error applying plan:
1 error(s) occurred:
* azurerm_virtual_machine.chef_test_vm_linux: autorest:DoErrorUnlessStatusCode 400 PUT https://management.azure.com/subscriptions/bd3c2aed-e279-4bd2-81d3-e4bebb6f4ad2/resourceGroups/chef_test_rg/providers/Microsoft.Compute/virtualMachines/chef_test_vm_linux?api-version=2015-06-15 failed with 400 Bad Request
Have you checked the audit log of your resource group in the azure portal? This might display an error stating why the deployment fails.
If I'd have to guess this would have something to do with the VHD file already existing on the storage account
I also had problems creating a VM, it turns out the computer_name is not optional as mentioned in the AzureRM documentation:
statusCode:BadRequest serviceRequestId:ffc32d14-4d10-4841-aaaa-8fce329470be statusMessage:{"error":{"code":"InvalidParameter","target":"computerName","message":"Required parameter 'computerName' is missing (null)."}}
@enieuw The Audit Log for the corresponding resource group does not contain any pointers to an error. In fact it only shows Informational messages. Other Audit logs show no feedback as well.
@edevil As you can see in my supplied test code, computer_name is supplied.
Hi @dpnl87
Apologies for the error here. While looking at this issue I saw that you specified to use an image for your disk, then also specified the os_type
Please re-run your terraform config without the os_type. os_type should only be used with custom VHD
If this works for you, I will update the documentation
Paul
Hi @stack72
After I remove the os_type the run still falls with the exact same error.
The console output:
azurerm_virtual_machine.chef_test_vm_linux: Creating...
availability_set_id: "" => "<computed>"
license_type: "" => "<computed>"
location: "" => "westeurope"
name: "" => "chef_test_vm_linux"
network_interface_ids.#: "" => "1"
network_interface_ids.2058567140: "" => "ExpressRouteVNETwe"
os_profile.#: "" => "1"
os_profile.175093281.admin_password: "" => "Password1234!"
os_profile.175093281.admin_username: "" => "testadmin"
os_profile.175093281.computer_name: "" => "chef_test_vm_linux"
os_profile.175093281.custom_data: "" => "<computed>"
os_profile_linux_config.#: "" => "1"
os_profile_linux_config.2972667452.disable_password_authentication: "" => "false"
os_profile_linux_config.2972667452.ssh_keys.#: "" => "0"
plan.#: "" => "<computed>"
resource_group_name: "" => "chef_test_rg"
storage_image_reference.#: "" => "1"
storage_image_reference.509829681.offer: "" => "CentOS"
storage_image_reference.509829681.publisher: "" => "OpenLogic"
storage_image_reference.509829681.sku: "" => "7.2"
storage_image_reference.509829681.version: "" => "7.2.20160308"
storage_os_disk.#: "" => "1"
storage_os_disk.21370517.caching: "" => "ReadWrite"
storage_os_disk.21370517.create_option: "" => "FromImage"
storage_os_disk.21370517.image_uri: "" => ""
storage_os_disk.21370517.name: "" => "disk1"
storage_os_disk.21370517.os_type: "" => ""
storage_os_disk.21370517.vhd_uri: "" => "https://cts20160524.blob.core.windows.net/linuxdisk/disk1.vhd"
tags.#: "" => "2"
tags.env: "" => "test"
vm_size: "" => "Standard_A1"
Error applying plan:
1 error(s) occurred:
* azurerm_virtual_machine.chef_test_vm_linux: autorest:DoErrorUnlessStatusCode 400 PUT https://management.azure.com/subscriptions/bd3c2aed-e279-4bd2-81d3-e4bebb6f4ad2/resourceGroups/chef_test_rg/providers/Microsoft.Compute/virtualMachines/chef_test_vm_linux?api-version=2015-06-15 failed with 400 Bad Request
ok, the issue is this line:
network_interface_ids = ["ExpressRouteVNETwe"]
The network_interface_ids should be an actual ID rather than just a name, something like this
/subscriptions/34ca515c-4629-458e-bf7c-738d77e0d0ea/resourceGroups/1Demo/providers/Microsoft.Network/networkInterfaces/nicdemo
Is Terraform managing this network interface for you?
ping @dpnl87
Any thoughts on my question above? I have been able to reproduce the issue and that is certainly the issue
We just merged some changes to the SDK that surface errors better from the SDK now:
* azurerm_virtual_machine.chef_test_vm_linux: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: azure: Service returned an error. Code="LinkedInvalidPropertyId" Message="Property id 'ExpressRouteVNETwe' at path 'properties.networkProfile.networkInterfaces[0].id' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}'." Status=400
Paul
Hi @stack72
I can confirm that your solution works! 👍
Please don't update the docs yet, I love to have a go at it.
Should be able to have something to merge within a few days.
Thnx!
Brilliant :) Would happily accept the PR here to fix it up :)
I will go ahead and close this one out now so that we know it is fixed
P.
@stack72 My statement a few days ago seems to be inaccurate 😞 . I still get an error on the above code even when I use the ID.
After building the 0.7.0+CHANGES version I get a nice error:
* azurerm_virtual_machine.chef_test_vm_linux: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: azure: Service returned an error. Code="InvalidParameter" Message="Linux host name cannot exceed 64 characters in length or contain the following characters: ~ ! @ # $ % ^ & * ( ) = + _ [ ] { } \ | ; : ' \" , < > / ?." Status=400`
I will fix this one, and do some extra testing to check the solution.
After changing the TF code to
resource "azurerm_virtual_machine" "ctl" {
name = "chef-linux"
location = "West Europe"
resource_group_name = "${azurerm_resource_group.chef_test_rg.name}"
network_interface_ids = ["/subscriptions/bd3c2aed-e279-4bd2-81d3-e4bebb6f4ad2/resourceGroups/Default-Networking/providers/Microsoft.ClassicNetwork/virtualNetworks/ExpressRouteVNETwe"]
vm_size = "Standard_A1"
# azure vm image list westeurope openlogic
storage_image_reference {
publisher = "OpenLogic"
offer = "CentOS"
sku = "7.2"
version = "7.2.20160308"
}
storage_os_disk {
name = "disk1"
vhd_uri = "${azurerm_storage_account.chef_test_storage.primary_blob_endpoint}${azurerm_storage_container.chef_linux_container.name}/disk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "chef-linux"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags {
env = "test"
}
}
It returns a parse error
* azurerm_virtual_machine.ctl: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: azure: Service returned an error. Code="InvalidRequestFormat" Message="Cannot parse the request." Status=400
This time the Audit Logs from the Azure console actually contain some useful information. The error seems to be related to the fact that the Expressroute is created with the Classic manager.
Exact error from the Audit log:
statusCode:BadRequest serviceRequestId:504c4237-a26a-42f7-b454-5c008450c108 statusMessage:{"error":{"details":[{"code":"InvalidJsonReferenceWrongType","message":"Reference Id /subscriptions/bd3c2aed-e279-4bd2-81d3-e4bebb6f4ad2/resourceGroups/Default-Networking/providers/Microsoft.ClassicNetwork/virtualNetworks/ExpressRouteVNETwe is referencing resource of a wrong type. The Id is expected to reference resources of type networkInterfaces, or virtualMachineScaleSets/virtualMachines/networkInterfaces. Path Properties.NetworkProfile.networkInterfaces[0]."}],"code":"InvalidRequestFormat","message":"Cannot parse the request."}}
Hi @dpnl87
So I have to be honest here, I have never tried to use classic resources with ARM resources. Do you know if this even works via the portal?
This is an error in either the azure SDK or the API. I will raise it there but I'm not hopeful of getting a decent response soon
I'm sorry this is blocking you
P.
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.