Hello community out there,
I am very new here even new to terraform.
I am provising vm for Proxmox .
I am getting below error:
Error: remote-exec provisioner error
│
│ with proxmox_vm_qemu.test_server[0],
│ on main.tf line 84, in resource "proxmox_vm_qemu" "test_server":
│ 84: provisioner "remote-exec" {
│
│ Failed to read ssh private key: no key found
at end main.tf file:
# the ${count.index + 1} thing appends text to the end of the ip address
# in this case, since we are only adding a single VM, the IP will
# be 10.98.1.91 since count.index starts at 0. this is how you can create
# multiple VMs and have an IP assigned to each (.91, .92, .93, etc.)
ipconfig0 = "ip=192.168.0.49/24,gw=192.98.0.1"
# sshkeys set using variables. the variable contains the text of the key.
sshkeys = <<EOF
${var.ssh_key}
EOF
# Configuring connection details
connection {
host = "192.168.0.49"
type = "ssh"
port = 22
user = "mgms-admin"
private_key = file("/home/mgms-admin/terraform/.ssh/id_rsa.pub")
timeout = "1m"
}
# Remotely executing a command on the server
provisioner "remote-exec" {
inline = ["sudo apt -y install nginx"]
}
}
vars.tf
variable "ssh_key" {
default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDQSxEbJ>
}
variable "proxmox_host" {
default = "homeserver"
}
variable "template_name" {
default = "ubuntu-2004-cloudinit-template"
}
ssh key location:
admin@terraform:~/terraform$ cat .ssh/id_rsa
id_rsa id_rsa.pub
I am able to create vm but i would like to provision vm like install list of packages which is defined in remote-exec provisioner, or do we have some other smart way to install via script like .sh file and how to define this in main.tf.
thanks in advance!