Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to define ssh key when using terraform to create linux vm

I'm trying to use terraform to create linux vm. what I see online is pretty straight forward

resource "tls_private_key" "this" {
  for_each = local.worker_env_map
  algorithm = "RSA"
  rsa_bits  = 4096
}

resource "azurerm_linux_virtual_machine" "example" {
  name                = "worker-machine"
  resource_group_name = "rogertest"
  location            = "australiaeast"
  size                = "Standard_D2_v4"
  admin_username = data.azurerm_key_vault_secret.kafkausername.value
  network_interface_ids = [
    azurerm_network_interface.example.id,
  ]

  admin_ssh_key {
    username   = "adminuser"
    public_key = tls_private_key.this["env1"].public_key_openssh
  }

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

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "18_04-lts-gen2"
    version   = "latest"
  }
}

but i'm keep getting this error

Code="InvalidParameter" Message="Destination path for SSH public keys is currently limited to its default value /home/kafkaadmin/.ssh/authorized_keys  due to a known issue in Linux provisioning agent." 
Target="linuxConfiguration.ssh.publicKeys.path"

but I'm following as exactly outline on this page?

https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-terraform

like image 261
Roger Chen Avatar asked Mar 03 '26 17:03

Roger Chen


1 Answers

You have to give the same value for both username under admin_ssh_key and admin_username

like image 153
Mahmoud El-Sanour Avatar answered Mar 07 '26 08:03

Mahmoud El-Sanour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!