hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.51k stars 4.6k forks source link

The SKU for Azure Linux Ubuntu VM doesn't work with "20.04-LTS" #22078

Open heenafroz opened 1 year ago

heenafroz commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

Terraform v1.4.6 on windows_amd64

AzureRM Provider Version

3.59.0

Affected Resource(s)/Data Source(s)

azurerm_linux_virtual_machine

Terraform Configuration Files

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_virtual_network" "example" {
  name                = "example-network"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_subnet" "example" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "example" {
  name                = "example-nic"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.example.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_linux_virtual_machine" "example" {
  name                = "example-machine"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  size                = "Standard_F2"
  admin_username      = "adminuser"
  network_interface_ids = [
    azurerm_network_interface.example.id,
  ]

  admin_ssh_key {
    username   = "adminuser"
    public_key = file("~/.ssh/id_rsa.pub")
  }

  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "20.04-LTS"
    version   = "latest"
  }
}

Debug Output/Panic Output

+ source_image_reference {
          + offer     = "UbuntuServer"
          + publisher = "Canonical"
          + sku       = "20.04-LTS"
          + version   = "latest"
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.
azurerm_linux_virtual_machine.linuxvm["linux-1"]: Creating...
azurerm_linux_virtual_machine.linuxvm["linux-2"]: Creating...
╷
│ Error: creating Linux Virtual Machine: (Name "host-linux-vm1" / Resource Group "linuxrg"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="PlatformImageNotFound" Message="The platform image 'Canonical:UbuntuServer:20.04-LTS:latest' 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"
│
│   with azurerm_linux_virtual_machine.linuxvm["linux-1"],
│   on mian.tf line 46, in resource "azurerm_linux_virtual_machine" "linuxvm":
│   46: resource "azurerm_linux_virtual_machine" "linuxvm" {

Expected Behaviour

VM creation with Ubuntu 20.04-LTS image

Actual Behaviour

No response

Steps to Reproduce

https://github.com/Azure/azure-powershell/issues/20732 - Issue has already been reported

Important Factoids

No response

References

https://github.com/Azure/azure-powershell/issues/20732 -2023

Instead use below as per https://www.kiloroot.com/where-did-microsoft-put-the-latest-azure-virtual-machine-ubuntu-images/ offer = "0001-com-ubuntu-server-focal" publisher = "Canonical" sku = "20_04-lts-gen2"

myc2h6o commented 1 year ago

Hi @heenafroz the image you are using looks not correct, 20.04 images have different offer names and sku format, could you try below image?

source_image_reference {
    publisher = "Canonical"
    offer     = "0001-com-ubuntu-server-focal"
    sku       = "20_04-lts"
    version   = "latest"
}

Ref: https://ubuntu.com/server/docs/find-ubuntu-images-on-azure