Expected Behaviour
How can I use the ssh_private_keys within the connection to connect and execute inline scripts within a linux VM ?
Affected Resource(s)
azurerm_v2.77.0
Terraform Configuration Files
resource “azurerm_linux_virtual_machine” “jumpbox” {
name = “jumpboxvm”
location = var.location
resource_group_name = var.resource_group
network_interface_ids = [azurerm_network_interface.vm_nic.id]
size = “Standard_DS1_v2”
computer_name = “jumpboxvm”
admin_username = var.vm_user
#admin_password = var.vm_password
#disable_password_authentication = falseadmin_ssh_key {
username = var.vm_user
public_key = var.SSH_PUBLIC_KEY # file(“~/.ssh/id_rsa.pub”)
}
os_disk {
name = “jumpboxOsDisk”
caching = “ReadWrite”
storage_account_type = “Standard_LRS”
}source_image_reference {
publisher = “Canonical”
offer = “UbuntuServer”
sku = “16.04.0-LTS”
version = “latest”
}
connection {
host = self.public_ip_addresshost = self.private_ip_address
type = "ssh" user = var.vm_user private_key = var.SSH_PRIVATE_KEY
private_key = file(/home/vsts/work/_temp/id_rsa)
public_key = var.SSH_PUBLIC_KEY
password = var.vm_password
}
provisioner “remote-exec” {
inline = [
“sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2”,
“curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -”,
“echo ‘deb https://apt.kubernetes.io/ kubernetes-xenial main’ | sudo tee -a /etc/apt/sources.list.d/kubernetes.list”,
“sudo apt-get update”,
“sudo apt-get install -y kubectl”,
“curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash”
]
}
}
# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp
# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp
Debug Output
Panic Output
Error when using it in Azure Devops Pipeline :
2021-09-23T23:18:51.0172874Z �[0m�[1mmodule.jumpbox.azurerm_private_dns_zone_virtual_network_link.hublink: Still creating... [30s elapsed]�[0m�[0m
2021-09-23T23:18:53.5387983Z �[0m�[1mmodule.jumpbox.azurerm_private_dns_zone_virtual_network_link.hublink: Creation complete after 33s [id=/subscriptions/xxx/resourceGroups/MC_nopublicipaks_private-aks_eastus/providers/Microsoft.Network/privateDnsZones/xx.privatelink.eastus.azmk8s.io/virtualNetworkLinks/hubnetdnsconfig]�[0m
2021-09-23T23:18:53.8607160Z �[31m╷�[0m�[0m
2021-09-23T23:18:53.8607928Z �[31m│�[0m �[0m�[1m�[31mError: �[0m�[0m�[1mremote-exec provisioner error�[0m
2021-09-23T23:18:53.8609151Z �[31m│�[0m �[0m
2021-09-23T23:18:53.8610162Z �[31m│�[0m �[0m�[0m with module.jumpbox.azurerm_linux_virtual_machine.jumpbox,
2021-09-23T23:18:53.8611265Z �[31m│�[0m �[0m on modules/jumpbox/main.tf line 92, in resource "azurerm_linux_virtual_machine" "jumpbox":
2021-09-23T23:18:53.8612179Z �[31m│�[0m �[0m 92: provisioner "remote-exec" �[4m{�[0m�[0m
2021-09-23T23:18:53.8613002Z �[31m│�[0m �[0m
2021-09-23T23:18:53.8613721Z �[31m│�[0m �[0mFailed to read ssh private key: no key found
2021-09-23T23:18:53.8614428Z �[31m╵�[0m�[0m
2021-09-23T23:18:53.9877154Z ##[error]Error: The process '/opt/hostedtoolcache/terraform/1.0.7/x64/terraform' failed with exit code 1
2021-09-23T23:18:53.9889142Z ##[section]Finishing: Terraform : DEPLOY