azure linux terraform ssh Archives - For all your terraform needs https://terraformarchitect.com/tag/azure-linux-terraform-ssh/ Automation cannot be an afterthought (TM) Wed, 08 Mar 2023 00:42:42 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 Error: Error decoding “admin_ssh_key.0.public_key” for public key data https://terraformarchitect.com/known-issues-terraform/error-error-decoding-admin_ssh_key-0-public_key-for-public-key-data/?utm_source=rss&utm_medium=rss&utm_campaign=error-error-decoding-admin_ssh_key-0-public_key-for-public-key-data https://terraformarchitect.com/known-issues-terraform/error-error-decoding-admin_ssh_key-0-public_key-for-public-key-data/#respond Tue, 06 Sep 2022 13:36:26 +0000 https://terraformarchitect.com/?p=246 This is an error I encountered while trying to set the admin ssh key for a linux instance – and attempting to use an existing pub key in my .ssh […]

The post Error: Error decoding “admin_ssh_key.0.public_key” for public key data appeared first on For all your terraform needs.

]]>
This is an error I encountered while trying to set the admin ssh key for a linux instance – and attempting to use an existing pub key in my .ssh folder (puttygen can be used to create ssh key pairs)

resource "azurerm_linux_virtual_machine" "myvm" {

  name                = local.vm_name

  resource_group_name = azurerm_resource_group.rg_des.name

  location            = azurerm_resource_group.rg_des.location

  size                = var.vm_size

  admin_username      = "adminuser"

  network_interface_ids = [

    azurerm_network_interface.myvm.id,

  ]

  admin_ssh_key {

    username   = "adminuser"

    #public_key = file("~/.ssh/id_rsa.pub")

     public_key = tls_private_key.linux_test_ssh.public_key_openssh

  }

Instead of doing it through an existing key pair, I used terraform to create the ssh key pair. This worked – no error

# Create (and display) an SSH key

resource "tls_private_key" "linux_test_ssh" {

  algorithm = "RSA"

  rsa_bits  = 4096

}
Summary
If you encounter this error on trying to create linux VMs on azure – Error decoding “admin_ssh_key.0.public_key” for public key data, try creating the key pair directly as a terraform resource.

The post Error: Error decoding “admin_ssh_key.0.public_key” for public key data appeared first on For all your terraform needs.

]]>
https://terraformarchitect.com/known-issues-terraform/error-error-decoding-admin_ssh_key-0-public_key-for-public-key-data/feed/ 0