Terraform-provider-azurerm: source_image_id unable to parse image id. Error: No subscription ID found

Created on 2 May 2020  ·  4Comments  ·  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.12.24
+ provider.azurerm v2.7.0

Affected Resource(s)

  • azurerm_linux_virtual_machine

Terraform Configuration Files

data "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
    }
}

Error message

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"

Expected Behavior

Linux virtual machine should be deployed with the given image from the gallery

Actual Behavior

Deployment fails with above error message

Steps to Reproduce

  1. terraform apply

References

Seems to be a similar issue but references another error message

  • #5616
question servicvirtual-machine upstream-microsoft

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings