Azure provider SSH public keys Destination path restriction

This is my SSH public keys setting under linux/

resource "azurerm_linux_virtual_machine" "mytfvm" {
  name                  = "${}"
  location              = "${var.location}"
  resource_group_name   = "${var.resource_group_name}"
  availability_set_id   = "${var.availability_set_id}"
  network_interface_ids = ["${}"]
  size                  = "${var.vm_size}"

  computer_name  = "${}"
  admin_username = "${var.admin_username}"
  disable_password_authentication = true
  custom_data    = "${var.cloud_config}"
  admin_ssh_key {
    // key_data = "${var.ssh_key}"
    // path     = "/home/${var.admin_username}/.ssh/authorized_keys"
    username   = "azureuser"
    public_key = tls_private_key.example_ssh.public_key_openssh

  os_disk {
    name              = "${}-os"
    caching           = "ReadWrite"
    storage_account_type = "${var.storage_type}"

It is causing the following problems:

module.linux.azurerm_linux_virtual_machine.mytfvm: Creating...
│ Error: creating Linux Virtual Machine: (Name "ubuntu" / Resource Group "paas"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Destination path for SSH public keys is currently limited to its default value /home/foo/.ssh/authorized_keys  due to a known issue in Linux provisioning agent." Target="linuxConfiguration.ssh.publicKeys.path"
│   with module.linux.azurerm_linux_virtual_machine.mytfvm,
│   on linux/ line 78, in resource "azurerm_linux_virtual_machine" "mytfvm":
│   78: resource "azurerm_linux_virtual_machine" "mytfvm" {

The admin_ssh_key setting is copied directly from Quickstart: Use Terraform to create a Linux VM - Azure Virtual Machines | Microsoft Learn, which I’ve made it working. Why it works there but not in my linux module?

How to fix it?

Sorry to bump an older thread, but was a solution ever found for this issue?
I’m having the same problem. It suggests the destination path for the public key cannot be changed from default, but i’m not trying to change the path.

1 Like

I faced the same issue. I found that problem with username. we have to give the same username in the both the places.

1 Like

This worked for me. Thank you for your insight!