Terraform v0.12.24
+ provider.azurerm v2.7.0
azurerm_linux_virtual_machinedata "azurerm_platform_image" "ubuntu_server" {
location = var.location
publisher = "Canonical"
offer = "UbuntuServer"
sku = var.vm_image_sku
}
...
resource "azurerm_linux_virtual_machine" "virtualmachine" {
name = "azl${random_id.randomId.hex}"
resource_group_name = azurerm_resource_group.resourcegroup.name
location = var.location
size = var.vm_size
admin_username = var.admin_username
disable_password_authentication = true
computer_name = "azl${random_id.randomId.hex}"
source_image_id = data.azurerm_platform_image.ubuntu_server.id
tags = var.tags
custom_data = base64encode(data.template_file.linux-vm-cloud-init.rendered)
network_interface_ids = [
azurerm_network_interface.nic.id
]
admin_ssh_key {
username = var.admin_username
public_key = file("~/.ssh/id_rsa.pub")
}
os_disk {
name = "azl${random_id.randomId.hex}_OsDisk"
caching = "ReadWrite"
storage_account_type = "StandardSSD_LRS"
}
boot_diagnostics {
storage_account_uri = azurerm_storage_account.storageaccount.primary_blob_endpoint
}
}
When using source_image_id terraform plan throws the following error message
Error: Can not parse "source_image_id" as a resource id: [ERROR] Unable to parse Image ID "/Subscriptions/<Subscription ID>/Providers/Microsoft.Compute/Locations/westeurope/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/18.04-LTS/Versions/18.04.202004290": No subscription ID found in: "Subscriptions/<Subscription ID>/Providers/Microsoft.Compute/Locations/westeurope/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/18.04-LTS/Versions/18.04.202004290"
Linux virtual machine should be deployed with the given image from the gallery
Deployment fails with above error message
terraform applySeems to be a similar issue but references another error message
Hi @sjohner thanks for this issue!
The root cause of this issue should be the ID of the image is not returned in proper casing from the azure images service. The ID of the image is like this:
/Subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/Providers/Microsoft.Compute/Locations/westus2/Publishers/Canonical/ArtifactTypes/VMImage/Offers/UbuntuServer/Skus/16.04-LTS/Versions/16.04.202004290
But actually for an usual ID, all the segment should start with a lower case letter (such as subscriptions instead of Subscriptions, Providers is similar)
While I open an issue in the azure-rest-api-specs to track this, I will take some time to provide a work around for this, but I am sorry that there is no firm ETA for this.
Hi @sjohner after some investigation, it turns out that you cannot assign an ID from a platform image to the source_image_id attribute. When you are doing this (bypass the validation), the service will return an error:
Code="BadRequest" Message="Id /subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/providers/Microsoft.Compute/locations/westus2/publishers/Canonical/artifactTypes/VMImage/offers/UbuntuServer/skus/16.04-LTS/versions/16.04.202004290 is not a valid resource reference."
indicating that the service does not accept an ID from a platform image.
But instead, you can do this to work around this situation:
data "azurerm_platform_image" "test" {
location = var.location
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
}
# other resources....
resource "azurerm_linux_virtual_machine" "virtualmachine" {
name = var.vm_name
resource_group_name = azurerm_resource_group.test.name
location = var.location
size = "Standard_F2"
admin_username = "adminuser"
disable_password_authentication = true
computer_name = var.computer_name
network_interface_ids = [
azurerm_network_interface.test.id
]
admin_ssh_key {
username = "adminuser"
public_key = file("~/.ssh/id_rsa.pub")
}
os_disk {
name = "azl_OsDisk"
caching = "ReadWrite"
storage_account_type = "StandardSSD_LRS"
}
source_image_reference {
publisher = data.azurerm_platform_image.test.publisher
offer = data.azurerm_platform_image.test.offer
sku = data.azurerm_platform_image.test.sku
version = data.azurerm_platform_image.test.version
}
}
Ok, thanks @ArcturusZhang for investigating on this. Will go with the workaround for the time being.
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!