add template vm in proxmox [ci skip]

This commit is contained in:
Viktor Barzin 2025-10-11 17:07:47 +00:00
parent 52638b3783
commit 9831fe1bc3
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
5 changed files with 68 additions and 18 deletions

View file

@ -0,0 +1,22 @@
#cloud-config
hostname: terraform-vm
users:
- name: wizard
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- ${authorized_ssh_key}
passwd: ${passwd}
lock_passwd: false # enable passwd login
package_update: true
package_upgrade: true
packages:
- htop
- vim
- curl
- jq
- tcpdump
- tree
- tmux
- wget
- net-tools
- zsh

View file

@ -7,6 +7,8 @@ variable "template_id" {
default = 8000
}
variable "template_name" { type = string }
variable "snippet_name" { type = string }
variable "user_passwd" { type = string } # hashed pw
# SSH connection to Proxmox
resource "null_resource" "create_template_remote" {
@ -39,3 +41,25 @@ resource "null_resource" "create_template_remote" {
]
}
}
resource "null_resource" "upload_cloud_init" {
connection {
type = "ssh"
host = var.proxmox_host
user = var.proxmox_user
private_key = file("~/.ssh/id_ed25519")
}
provisioner "remote-exec" {
inline = ["mkdir -p /var/lib/vz/snippets"]
}
provisioner "file" {
destination = "/var/lib/vz/snippets/${var.snippet_name}"
content = templatefile("${path.module}/cloud_init.yaml", { authorized_ssh_key = file("~/.ssh/id_ed25519.pub"), passwd = var.user_passwd })
}
triggers = {
file_hash = filesha256("${path.module}/cloud_init.yaml")
}
}