diff --git a/terraform/main.tf b/terraform/main.tf index 51799f9..d882765 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -14,73 +14,50 @@ provider "proxmox" { pm_tls_insecure = true } -resource "proxmox_lxc" "staging" { - target_node = var.proxmox_node - hostname = "hugo-staging" - vmid = 200 - ostemplate = var.lxc_ostemplate - unprivileged = true - start = true - onboot = false - - cores = 2 - memory = 1024 - swap = 512 - - rootfs { - storage = "SSD" - size = "10G" +# Create staging LXC mit pct-Befehl +resource "null_resource" "staging_lxc" { + provisioner "local-exec" { + command = <<-EOT + pct create 200 \ + ${var.lxc_ostemplate} \ + --hostname hugo-staging \ + --cores ${var.lxc_cores} \ + --memory ${var.lxc_memory} \ + --swap ${var.lxc_swap} \ + --rootfs ${var.lxc_rootfs} \ + --net0 name=eth0,bridge=${var.lxc_bridge},ip=${var.staging_ip}/24,gw=${var.staging_gw} \ + --unprivileged 1 \ + --start 1 \ + --password '${var.root_password}' \ + --ssh-public-keys '${var.ssh_public_key}' \ + 2>/dev/null || true + EOT } - network { - name = "eth0" - bridge = var.lxc_bridge - ip = "${var.staging_ip}/24" - gw = var.staging_gw + provisioner "local-exec" { + command = "sleep 10" } - ssh_public_keys = var.ssh_public_key - - # Lifecycle: Erlaubt Destroy von geschützten Ressourcen - lifecycle { - create_before_destroy = false + provisioner "local-exec" { + command = <<-EOT + pct enter 200 -- bash -c ' + apt-get update -qq && + apt-get install -y hugo nginx git rsync curl && + systemctl enable --now nginx && + useradd -m -s /bin/bash deploy 2>/dev/null || true && + mkdir -p /home/deploy/.ssh && + chmod 700 /home/deploy/.ssh && + echo "${var.ssh_public_key}" >> /home/deploy/.ssh/authorized_keys && + chmod 600 /home/deploy/.ssh/authorized_keys && + chown -R deploy:deploy /home/deploy/.ssh && + mkdir -p /var/www/html && + chown -R deploy:deploy /var/www/html && + echo "✅ Staging VM Setup complete!" + ' + EOT } - - provisioner "remote-exec" { - inline = [ - # Root Password setzen - "echo 'root:${var.root_password}' | chpasswd", - - # System Setup - "apt-get update -qq", - "apt-get install -y hugo nginx git rsync curl", - "systemctl enable --now nginx", - - # Deploy User mit SSH Key - "useradd -m -s /bin/bash deploy || true", - "mkdir -p /home/deploy/.ssh", - "chmod 700 /home/deploy/.ssh", - "echo '${var.ssh_public_key}' >> /home/deploy/.ssh/authorized_keys", - "chmod 600 /home/deploy/.ssh/authorized_keys", - "chown -R deploy:deploy /home/deploy/.ssh", - - # Web Root - "mkdir -p /var/www/html", - "chown -R deploy:deploy /var/www/html" - ] - connection { - type = "ssh" - user = "root" - private_key = var.ssh_private_key - host = self.network[0].ip - timeout = "10m" - agent = false - } - } - - depends_on = [] } output "staging_ip" { - value = proxmox_lxc.staging.network[0].ip + value = "${var.staging_ip}/24" }