working main.tf

This commit is contained in:
CC
2026-09-12 17:08:24 +01:00
parent 17bc648be3
commit ab79b9c0fa
2 changed files with 30 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
# VM Service Template # VM Service Template - CHANGE BACKEND FILE PATH
This repository is a starter template for deploying one or more service VMs in Proxmox using Terraform, then configuring and launching applications with Ansible and Docker Compose. This repository is a starter template for deploying one or more service VMs in Proxmox using Terraform, then configuring and launching applications with Ansible and Docker Compose.

View File

@@ -4,7 +4,7 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
node_name = var.node_name node_name = var.node_name
source_raw { source_raw {
file_name = "${var.vm_name}_vm.cloud-config.yaml" # The name of the snippet file file_name = "${var.vm_name}_vm.cloud-config.yaml"
data = <<-EOF data = <<-EOF
#cloud-config #cloud-config
hostname: ${var.vm_name} hostname: ${var.vm_name}
@@ -24,7 +24,7 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
- docker - docker
shell: /bin/bash shell: /bin/bash
ssh-authorized-keys: ssh-authorized-keys:
- "${var.vm_user_sshkey}" # +++ Needs to be put into a variable injected by git actions secrets - "${var.vm_user_sshkey}"
sudo: ALL=(ALL) NOPASSWD:ALL sudo: ALL=(ALL) NOPASSWD:ALL
packages: packages:
@@ -36,6 +36,25 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
- lsb-release - lsb-release
- unattended-upgrades - unattended-upgrades
- rsync - rsync
- fish
- nano
bootcmd:
- mkdir -p /home/cloud/${var.service_name}
- chown cloud:cloud /home/cloud/${var.service_name}
write_files:
- path: /home/cloud/${var.service_name}/docker-compose.yml
owner: cloud:cloud
permissions: '0644'
encoding: b64
content: ${var.compose_file_content}
- path: /home/cloud/${var.service_name}/.env
owner: cloud:cloud
permissions: '0600'
encoding: b64
content: ${var.env_file_content}
runcmd: runcmd:
- systemctl enable qemu-guest-agent - systemctl enable qemu-guest-agent
@@ -46,6 +65,9 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
- apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin - apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
- systemctl enable docker - systemctl enable docker
- systemctl start docker - systemctl start docker
- chown -R cloud:cloud /home/cloud/${var.service_name}
- cd /home/cloud/${var.service_name}
- sudo -u cloud docker compose up -d
- reboot - reboot
EOF EOF
} }