1
votes

I have an image in my Azure Shared Image Gallery (myGallery) named myImage and version 1.0.0.

I am attempting to create a Virtual Machine via Terraform for this image in the gallery and am receiving the following error:

Error: creating Linux Virtual Machine "testingvm" (Resource Group "myrg"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"

  • Azure CLI Version: 2.26.1
  • Terraform Version: 1.0.0
  • Azure Terraform Provider Version: 2.69.0

My Terraform for the Virtual Machine looks like this:

resource "azurerm_linux_virtual_machine" "testingvm" {
  name                        = "testingvm"
  resource_group_name         = var.resource_group_name
  location                    = var.location

  size                        = "Standard_D2s_v4"
  network_interface_ids       = [azurerm_network_interface.testingvm.id]

  admin_username              = "azureuser"

  source_image_id             = "/subscriptions/MY_SUBSCRIPTION/resourceGroups/myrg/providers/Microsoft.Compute/galleries/myGallery/images/myImage/versions/1.0.0"

  os_disk {
    name                      = "testingvm-os"
    caching                   = "ReadWrite"
    storage_account_type      = "Premium_LRS"
  }

  admin_ssh_key {
    username                  = "azureuser"
    public_key                = module.vm_key_pair.pair_key_pub_value_openssh
  }
}

I tried this using both of these with no luck (I believe the latter is what is recommended):

I tried referencing this Stack Overflow entry without any luck as well.

What am I doing wrong here?


Another Attempt

I also tried using this:

source_image_reference {
  publisher                 = "myPublisher"
  offer                     = "myOffer"
  sku                       = "mySKU"
  version                   = "1.0.0"
}

After viewing the output of this, where the identifier block spits out matching parameters:

az sig image-definition show \
  --gallery-image-definition myImage \
  --gallery-name myGallery
  --resource-group myrg

That results in:

Error: creating Linux Virtual Machine "testingvm" (Resource Group "myrg"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="PlatformImageNotFound" Message="The platform image 'myPublisher:myOffer:mySKU:1.0.0' is not available. Verify that all fields in the storage profile are correct. For more details about storage profile information, please refer to https://aka.ms/storageprofile" Target="imageReference"

1
You need to use az sig image-definition show-shared for shared images docs.microsoft.com/en-us/cli/azure/sig/…Kyle Hale
And osProfile is not allowed means you're providing an SSH key to a specialized image version. (See docs.microsoft.com/en-us/azure/virtual-machines/… )Kyle Hale
See also this blog post for how to identify the issues in your storage profile configuration: medium.com/@rafique82.ai/…Kyle Hale
@KyleHale that worked like a charmel n00b

1 Answers

1
votes

Thanks to @KyleHale, I was able to sort this out:

resource "azurerm_virtual_machine" "testingvm" {
  name                        = "testingvm"
  resource_group_name         = var.resource_group_name
  location                    = var.location

  vm_size                     = "Standard_D2s_v4"
  network_interface_ids       = [azurerm_network_interface.testingvm.id]

  storage_image_reference {
    id = "THE_ID_I_LISTED_BEFORE"
  }

  storage_os_disk {
    name                      = "testingvm-os"
    caching                   = "ReadWrite"
    create_option             = "FromImage"
    managed_disk_type         = "Standard_LRS"
  }
}