generated from CC/VMServiceTemplate
Compare commits
36 Commits
393d5deaf3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a8a7cbdee | ||
|
|
63d86d49a8 | ||
|
|
835e03212d | ||
|
|
076c240fad | ||
|
|
a6cc36c2d6 | ||
|
|
1ebcf068c4 | ||
|
|
60c2ede5e3 | ||
|
|
e6a70d2540 | ||
|
|
570e238ad0 | ||
|
|
0ddc440c68 | ||
|
|
37ec2da77e | ||
|
|
1dda60a98a | ||
|
|
5fb9824444 | ||
|
|
fbb2a53e23 | ||
|
|
1041be3770 | ||
|
|
b2c0a925af | ||
|
|
8180af3b34 | ||
|
|
87a321e8b4 | ||
|
|
1054de6339 | ||
|
|
19cf6588e0 | ||
|
|
697ae3cc0d | ||
|
|
c338aa5743 | ||
|
|
2da68c03e1 | ||
|
|
72c218fe21 | ||
|
|
b5341f866c | ||
|
|
367e65665b | ||
|
|
0580808487 | ||
|
|
26455d4f60 | ||
|
|
097192ec00 | ||
|
|
df00e2cac8 | ||
|
|
5c9cc12ef9 | ||
|
|
c2fcb18fd7 | ||
|
|
872e1e3123 | ||
|
|
17ca08f509 | ||
|
|
64c0e04daf | ||
|
|
0d3bb678f7 |
@@ -1,8 +1,6 @@
|
|||||||
name: Deploy VM and App
|
name: Deploy VM and App
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
tfvars_file:
|
tfvars_file:
|
||||||
@@ -16,27 +14,15 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
terraform-ansible-deploy:
|
terraform-ansible-deploy:
|
||||||
runs-on: frente
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
PROXMOX_VE_API_TOKEN: https://api.staging.example.com
|
|
||||||
PROXMOX_VE_ENDPOINT: true
|
|
||||||
GITEA_BASE_URL: https://api.staging.example.com
|
|
||||||
GITEA_TOKEN: true
|
|
||||||
AWS_ACCESS_KEY_ID: https://api.staging.example.com
|
|
||||||
AWS_SECRET_ACCESS_KEY: true
|
|
||||||
AWS_REGION: garage
|
|
||||||
TF_VAR_vm_ssh_userkey: ${{ secrets.VM_USER_SSHKEY }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Check files & Select tfvars
|
- name: Check files & Select tfvars
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
#rm ansible/inventory/inventory.yml
|
|
||||||
mkdir -p ansible/inventory
|
mkdir -p ansible/inventory
|
||||||
cd terraform
|
cd terraform
|
||||||
#rm vm_data.yml
|
|
||||||
cp "${{ inputs.tfvars_file || 'single.tfvars.example' }}" terraform.tfvars
|
cp "${{ inputs.tfvars_file || 'single.tfvars.example' }}" terraform.tfvars
|
||||||
|
|
||||||
- uses: hashicorp/setup-terraform@v4
|
- uses: hashicorp/setup-terraform@v4
|
||||||
@@ -52,37 +38,37 @@ jobs:
|
|||||||
run: terraform apply -auto-approve
|
run: terraform apply -auto-approve
|
||||||
working-directory: "terraform"
|
working-directory: "terraform"
|
||||||
|
|
||||||
- name: Install Ansible
|
# - name: Install Ansible
|
||||||
shell: bash
|
# shell: bash
|
||||||
run: |
|
# run: |
|
||||||
sudo apt-get update
|
# sudo apt-get update
|
||||||
sudo apt-get install -y ansible rsync
|
# sudo apt-get install -y ansible rsync
|
||||||
|
|
||||||
- name: Set up SSH
|
# - name: Set up SSH
|
||||||
run: |
|
# run: |
|
||||||
mkdir -p ~/.ssh
|
# mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/vlans_rsa
|
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/vlans_rsa
|
||||||
chmod 600 ~/.ssh/vlans_rsa
|
# chmod 600 ~/.ssh/vlans_rsa
|
||||||
cat > ~/.ssh/config <<'EOF'
|
# cat > ~/.ssh/config <<'EOF'
|
||||||
Host *
|
# Host *
|
||||||
StrictHostKeyChecking no
|
# StrictHostKeyChecking no
|
||||||
UserKnownHostsFile=/dev/null
|
# UserKnownHostsFile=/dev/null
|
||||||
EOF
|
# EOF
|
||||||
|
|
||||||
- name: Run playbook
|
# - name: Configure Git
|
||||||
run: |
|
# run: |
|
||||||
ansible-playbook ansible/playbooks/docker_copy.yml -i ansible/inventory/inventory.yml -u cloud --private-key ~/.ssh/vlans_rsa
|
# git config user.name "git-bot"
|
||||||
|
# git config user.email "got-bot@text.com"
|
||||||
|
|
||||||
- name: Configure Git
|
# - name: Commit and push to Gitea
|
||||||
run: |
|
# run: |
|
||||||
git config user.name "git-bot"
|
# git remote set-url origin https://$GITEA_USERNAME:${{ secrets.GIT_BOT_TOKEN }}@tea.charcarservices.uk/CC/N8N.git
|
||||||
git config user.email "got-bot@text.com"
|
# git add terraform/vm_data.yml ansible/inventory/inventory.yml
|
||||||
|
# git diff --cached --quiet || git commit -m "chore: update terraform outputs"
|
||||||
|
# git push origin HEAD:main
|
||||||
|
# env:
|
||||||
|
# GITEA_USERNAME: git-bot # or your bot account
|
||||||
|
|
||||||
- name: Commit and push to Gitea
|
# - name: Run playbook
|
||||||
run: |
|
# run: |
|
||||||
git remote set-url origin https://$GITEA_USERNAME:${{ secrets.GIT_BOT_TOKEN }}@tea.charcarservices.uk/CC/N8N.git
|
# ansible-playbook ansible/playbooks/docker_copy.yml -i ansible/inventory/inventory.yml -u cloud --private-key ~/.ssh/vlans_rsa
|
||||||
git add terraform/vm_data.yml ansible/inventory/inventory.yml
|
|
||||||
git diff --cached --quiet || git commit -m "chore: update terraform outputs"
|
|
||||||
git push origin HEAD:main
|
|
||||||
env:
|
|
||||||
GITEA_USERNAME: git-bot # or your bot account
|
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ on:
|
|||||||
default: "terraform"
|
default: "terraform"
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
|
tfvars_file:
|
||||||
|
description: "Which tfvars file to use"
|
||||||
|
required: true
|
||||||
|
default: "single.tfvars.example"
|
||||||
|
type: choice
|
||||||
|
options:
|
||||||
|
- single.tfvars.example
|
||||||
|
- multi.tfvars.example
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
destroy:
|
destroy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -22,6 +31,12 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Check files & Select tfvars
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cp "${{ inputs.tfvars_file || 'single.tfvars.example' }}" terraform.tfvars
|
||||||
|
cat terraform.tfvars
|
||||||
|
|
||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
uses: hashicorp/setup-terraform@v4
|
uses: hashicorp/setup-terraform@v4
|
||||||
|
|
||||||
|
|||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.terraform*
|
||||||
|
scratch*
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
- hosts: all
|
- hosts: all
|
||||||
become: true
|
become: true
|
||||||
vars:
|
vars:
|
||||||
folder_name: n8n
|
folder_name: music
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- role: docker
|
- role: docker
|
||||||
|
|||||||
@@ -3,15 +3,13 @@
|
|||||||
|
|
||||||
- name: Copy project directory to remote
|
- name: Copy project directory to remote
|
||||||
ansible.builtin.synchronize:
|
ansible.builtin.synchronize:
|
||||||
src: ../compose/{{ folder_name }}
|
src: ../../compose/{{ folder_name }}
|
||||||
dest: /home/cloud/
|
dest: /home/cloud/
|
||||||
mode: push
|
mode: push
|
||||||
|
|
||||||
|
|
||||||
- name: Start Compose stack
|
- name: Start Compose stack
|
||||||
community.docker.docker_compose_v2:
|
community.docker.docker_compose_v2:
|
||||||
project_src: /home/cloud/{{ folder_name }}
|
project_src: /home/cloud/{{ folder_name }}
|
||||||
build: always
|
build: always
|
||||||
pull: always
|
pull: always
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,83 @@
|
|||||||
#Example for compose
|
#Example for compose
|
||||||
|
services:
|
||||||
|
gluetun:
|
||||||
|
image: qmcgaw/gluetun
|
||||||
|
hostname: vpngluetun
|
||||||
|
container_name: vpngluetun
|
||||||
|
cap_add:
|
||||||
|
- NET_ADMIN
|
||||||
|
devices:
|
||||||
|
- /dev/net/tun:/dev/net/tun
|
||||||
|
ports:
|
||||||
|
- 8888:8888/tcp # HTTP proxy
|
||||||
|
- 8000:8000/tcp # Built-in HTTP control server
|
||||||
|
- 8080:8080 # sabnzbd
|
||||||
|
- "5030:5030" # slskd
|
||||||
|
- "5031:5031" # slskd
|
||||||
|
- "50300:50300" # slskd
|
||||||
|
volumes:
|
||||||
|
- ./glutun:/gluetun
|
||||||
|
environment:
|
||||||
|
- VPN_SERVICE_PROVIDER=airvpn
|
||||||
|
- VPN_TYPE=wireguard
|
||||||
|
- WIREGUARD_PRIVATE_KEY=6Ifq8z5jz5GbjCoxMTSQsWMATjotd+qhrU+h+FeU2nw=
|
||||||
|
- WIREGUARD_PRESHARED_KEY=5TpvbMj1DnrJq0skpMw83mawSEYseaJv9M1lmtznzYI=
|
||||||
|
- WIREGUARD_ADDRESSES=10.137.105.215/32
|
||||||
|
- SERVER_COUNTRIES="Germany"
|
||||||
|
- SERVER_ENDPOINT="de4.vpn.airdns.org"
|
||||||
|
- TZ=Europe/London
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- FIREWALL_VPN_INPUT_PORTS=14264
|
||||||
|
restart: "unless-stopped"
|
||||||
|
|
||||||
|
slskd:
|
||||||
|
image: slskd/slskd
|
||||||
|
container_name: slskd
|
||||||
|
environment:
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- SLSKD_REMOTE_CONFIGURATION=true
|
||||||
|
- "SLSKD_SHARED_DIR=/music"
|
||||||
|
volumes:
|
||||||
|
- /home/cloud/library/slskd/organised:/music:rw
|
||||||
|
- /home/cloud/library/slskd/downloads:/downloads:rw
|
||||||
|
- ./slskd:/app
|
||||||
|
network_mode: "service:gluetun"
|
||||||
|
depends_on:
|
||||||
|
- gluetun
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
droppedneedle:
|
||||||
|
image: droppedneedle/droppedneedle:latest
|
||||||
|
container_name: droppedneedle
|
||||||
|
environment:
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- PORT=8688
|
||||||
|
- TZ=Europe/London
|
||||||
|
- SLSKD_DOWNLOADS_PATH=/slskd-downloads
|
||||||
|
ports:
|
||||||
|
- "8688:8688"
|
||||||
|
volumes:
|
||||||
|
- ./droppedneedle/config:/app/config
|
||||||
|
- ./droppedneedle/cache:/app/cache
|
||||||
|
- /home/cloud/library/organised:/music:rw
|
||||||
|
- /home/cloud/library/slskd/downloads:/slskd-downloads:rw
|
||||||
|
- /home/cloud/library/downloads:/sabnzbd-downloads:rw
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
sabnzbd:
|
||||||
|
image: lscr.io/linuxserver/sabnzbd:latest
|
||||||
|
container_name: sabnzbd
|
||||||
|
environment:
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- TZ=Europe/London
|
||||||
|
volumes:
|
||||||
|
- ./sabnzbd/config:/config
|
||||||
|
- /home/cloud/library/downloads:/downloads #optional
|
||||||
|
network_mode: "service:gluetun"
|
||||||
|
depends_on:
|
||||||
|
- gluetun
|
||||||
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
terraform {
|
terraform {
|
||||||
backend "s3" {
|
backend "s3" {
|
||||||
bucket = "terraform"
|
bucket = "terraform"
|
||||||
key = "n8n/terraform.tfstate"
|
key = "music/terraform.tfstate"
|
||||||
access_key = "GK242d456c0692a9d4cc102206"
|
access_key = "GK242d456c0692a9d4cc102206"
|
||||||
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
|
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
|
||||||
region = "garage"
|
region = "garage"
|
||||||
@@ -14,5 +14,5 @@ terraform {
|
|||||||
skip_region_validation = true
|
skip_region_validation = true
|
||||||
use_path_style = true
|
use_path_style = true
|
||||||
use_lockfile = true
|
use_lockfile = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
terraform/locals.tf
Normal file
19
terraform/locals.tf
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
locals {
|
||||||
|
instance_map = var.instance_mode == "single" ? {
|
||||||
|
main = var.instance
|
||||||
|
} : var.instances
|
||||||
|
|
||||||
|
vm_created = {
|
||||||
|
for k, v in local.instance_map :
|
||||||
|
k => {
|
||||||
|
service_name = v.service_name
|
||||||
|
vm_name = v.vm_name
|
||||||
|
node_name = v.node_name
|
||||||
|
ipv4_address = module.proxmox_ubuntu_cloudinit_clone[k].vm_ipv4_address
|
||||||
|
vm_tags = concat(
|
||||||
|
try(v.vm_tags, []),
|
||||||
|
["terraform", "docker", v.service_name, "ip-${replace(module.proxmox_ubuntu_cloudinit_clone[k].vm_ipv4_address, ".", "-")}"]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,9 @@
|
|||||||
locals {
|
module "proxmox_ubuntu_cloudinit_clone" {
|
||||||
instance_map = var.instance_mode == "single" ? {
|
|
||||||
main = var.instance
|
|
||||||
} : var.instances
|
|
||||||
|
|
||||||
vm_created = {
|
|
||||||
for k, v in local.instance_map :
|
|
||||||
k => {
|
|
||||||
service_name = v.service_name
|
|
||||||
vm_name = v.vm_name
|
|
||||||
node_name = v.node_name
|
|
||||||
ipv4_address = module.vm-n8n[k].vm_ipv4_address
|
|
||||||
vm_tags = concat(
|
|
||||||
try(v.vm_tags, []),
|
|
||||||
["terraform", "docker", v.service_name, "ip-${replace(module.vm-n8n[k].vm_ipv4_address, ".", "-")}"]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module "vm-n8n" {
|
|
||||||
for_each = local.instance_map
|
for_each = local.instance_map
|
||||||
source = "./modules/proxmox_ubuntu_cloudinit_clone"
|
source = "./modules/proxmox_ubuntu_cloudinit_clone"
|
||||||
|
|
||||||
vm_name = each.value.vm_name
|
vm_name = each.value.vm_name
|
||||||
|
service_name = each.value.service_name
|
||||||
node_name = each.value.node_name
|
node_name = each.value.node_name
|
||||||
node_datastore = var.vm_defaults.node_datastore
|
node_datastore = var.vm_defaults.node_datastore
|
||||||
bridge = var.vm_defaults.bridge
|
bridge = var.vm_defaults.bridge
|
||||||
@@ -36,16 +17,6 @@ module "vm-n8n" {
|
|||||||
["terraform", "docker", each.value.service_name]
|
["terraform", "docker", each.value.service_name]
|
||||||
)
|
)
|
||||||
vm_user_sshkey = var.vm_defaults.vm_user_sshkey
|
vm_user_sshkey = var.vm_defaults.vm_user_sshkey
|
||||||
}
|
compose_file_content = filebase64("${path.root}/../compose/docker-compose.yml")
|
||||||
|
env_file_content = filebase64("${path.root}/../compose/.env")
|
||||||
module "inventory" {
|
|
||||||
source = "./modules/proxmox_ansible_inventory"
|
|
||||||
filename = "${abspath("${path.root}/..")}/ansible/inventory/inventory.yml"
|
|
||||||
instances = local.vm_created
|
|
||||||
}
|
|
||||||
|
|
||||||
module "vm_data" {
|
|
||||||
source = "./modules/proxmox_vm_data"
|
|
||||||
filename = "${abspath("${path.root}/..")}/terraform/vm_data.yml"
|
|
||||||
instances = local.vm_created
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,13 @@
|
|||||||
selected_instance = one([
|
locals {
|
||||||
|
selected_instance = one([
|
||||||
for cfg in var.instance_configs :
|
for cfg in var.instance_configs :
|
||||||
cfg if cfg.crispy_name == var.node_name
|
cfg if cfg.crispy_name == var.node_name
|
||||||
])
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
resource "proxmox_virtual_environment_file" "cloud_config" {
|
resource "proxmox_virtual_environment_file" "cloud_config" {
|
||||||
content_type = "snippets"
|
content_type = "snippets"
|
||||||
datastore_id = "local"
|
datastore_id = "hlst"
|
||||||
node_name = "pop"
|
node_name = var.node_name
|
||||||
|
|
||||||
source_raw {
|
source_raw {
|
||||||
file_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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,10 +107,16 @@ variable "vm_name" {
|
|||||||
default = "Lab"
|
default = "Lab"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "service_name" {
|
||||||
|
description = "Folder name of the services"
|
||||||
|
type = string
|
||||||
|
default = "Lab"
|
||||||
|
}
|
||||||
|
|
||||||
variable "vm_user_sshkey" {
|
variable "vm_user_sshkey" {
|
||||||
description = "Admin user SSH key of the VM"
|
description = "Admin user SSH key of the VM"
|
||||||
type = string
|
type = string
|
||||||
default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRlWaLBt/qmWY01Cd6jN/YxLnlT+6lg+evEdN/dIajirdTj1rCbAdlG3WYvo+4BpN17HK3/eGQpGUMbgI/8MVd8YPODcD34gaNX0w2v66BwHx+S6BZUpz5T2IoQT0JtSv/TtFICoff5gXdNRpfd4eWsmTioEqLA6oToJLE4dn3jvAzFi9y7fyLqvuoQMmPidYYJjGT30eiULtXNspoEP+GmuWmVEu+znzMWaKDWKdOsii4Cv1aWCRKSDDRzDBrZI2mP+Vm4HDQBdgDYRw4ehumMDtfaSjyJCnrk691bIM+wxzICuIEecg5kq5HcUPvo2mFyWPAEXb5xlXnuopYEBd7 Generated By NeoServer"
|
default = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -138,3 +144,14 @@ variable "vm_user" {
|
|||||||
type = string
|
type = string
|
||||||
default = "cloud"
|
default = "cloud"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "compose_file_content" {
|
||||||
|
description = "Rendered contents of docker-compose.yml to write to the VM"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "env_file_content" {
|
||||||
|
description = "Rendered contents of .env to write to the VM"
|
||||||
|
type = string
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
locals {
|
|
||||||
selected_instance = one([
|
|
||||||
for cfg in var.instance_configs :
|
|
||||||
cfg if cfg.crispy_name == var.node_name
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_file" "cloud_config" {
|
|
||||||
content_type = "snippets"
|
|
||||||
datastore_id = "local"
|
|
||||||
node_name = "pop"
|
|
||||||
|
|
||||||
source_raw {
|
|
||||||
file_name = "vm.cloud-config.yaml" # The name of the snippet file
|
|
||||||
data = <<-EOF
|
|
||||||
#cloud-config
|
|
||||||
hostname: ${var.vm_name}
|
|
||||||
|
|
||||||
package_update: true
|
|
||||||
package_upgrade: true
|
|
||||||
|
|
||||||
system_info:
|
|
||||||
default_user:
|
|
||||||
groups: [ docker ]
|
|
||||||
|
|
||||||
users:
|
|
||||||
- default
|
|
||||||
- name: cloud
|
|
||||||
groups:
|
|
||||||
- sudo
|
|
||||||
- docker
|
|
||||||
shell: /bin/bash
|
|
||||||
ssh-authorized-keys:
|
|
||||||
- "${var.vm_user_sshkey}" # Inject user's SSH key
|
|
||||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
|
||||||
|
|
||||||
packages:
|
|
||||||
- qemu-guest-agent
|
|
||||||
- apt-transport-https
|
|
||||||
- ca-certificates
|
|
||||||
- curl
|
|
||||||
- gnupg
|
|
||||||
- lsb-release
|
|
||||||
- unattended-upgrades
|
|
||||||
|
|
||||||
runcmd:
|
|
||||||
- systemctl enable qemu-guest-agent
|
|
||||||
- mkdir -p /etc/apt/keyrings
|
|
||||||
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
|
||||||
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
||||||
- apt-get update
|
|
||||||
- apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
||||||
- systemctl enable docker
|
|
||||||
- systemctl start docker
|
|
||||||
- reboot
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_vm" "ubuntu_22_minimal_template" {
|
|
||||||
name = var.vm_name # VM name
|
|
||||||
node_name = var.node_name # Proxmox node to deploy the VM
|
|
||||||
tags = var.vm_tags # Optional VM tags for categorization
|
|
||||||
|
|
||||||
agent {
|
|
||||||
enabled = true # Enable the QEMU guest agent
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_on_destroy = true # Ensure VM is stopped gracefully when destroyed
|
|
||||||
|
|
||||||
disk {
|
|
||||||
datastore_id = var.node_datastore # Datastore to hold the disk
|
|
||||||
interface = "scsi0" # Primary disk interface
|
|
||||||
size = var.vm_size
|
|
||||||
file_id = "local:iso/ubuntu-22.04-minimal-cloudimg-amd64.img"
|
|
||||||
}
|
|
||||||
|
|
||||||
efi_disk {
|
|
||||||
datastore_id = var.node_datastore
|
|
||||||
type = "4m"
|
|
||||||
}
|
|
||||||
|
|
||||||
bios = var.vm_bios # BIOS type (e.g., seabios or ovmf)
|
|
||||||
machine = var.vm_machine # Machine type (e.g., q35)
|
|
||||||
|
|
||||||
cpu {
|
|
||||||
cores = var.vm_cpu # Number of CPU cores
|
|
||||||
type = "host" # Use host CPU type for best compatibility/performance
|
|
||||||
}
|
|
||||||
|
|
||||||
memory {
|
|
||||||
dedicated = var.vm_ram # RAM in MB
|
|
||||||
}
|
|
||||||
|
|
||||||
initialization {
|
|
||||||
user_data_file_id = proxmox_virtual_environment_file.cloud_config.id # Link the cloud-init file
|
|
||||||
datastore_id = var.node_datastore
|
|
||||||
interface = "scsi1" # Separate interface for cloud-init
|
|
||||||
ip_config {
|
|
||||||
ipv4 {
|
|
||||||
address = "dhcp" # Get IP via DHCP
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
network_device {
|
|
||||||
bridge = var.bridge # Use the default bridge
|
|
||||||
}
|
|
||||||
|
|
||||||
operating_system {
|
|
||||||
type = "l26" # Linux 2.6+ kernel
|
|
||||||
}
|
|
||||||
|
|
||||||
lifecycle {
|
|
||||||
ignore_changes = [ # Ignore initialization section after first depoloyment for idempotency
|
|
||||||
initialization
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
output "vm_ipv4_address" {
|
|
||||||
value = proxmox_virtual_environment_vm.ubuntu_22_minimal_template.ipv4_addresses[1][0]
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
terraform {
|
|
||||||
required_providers {
|
|
||||||
proxmox = {
|
|
||||||
source = "bpg/proxmox"
|
|
||||||
version = "0.106.0"
|
|
||||||
#url = https://registry.terraform.io/providers/bpg/proxmox/latest/docs/guides/clone-vm
|
|
||||||
}
|
|
||||||
aws = {
|
|
||||||
source = "hashicorp/aws"
|
|
||||||
version = "6.38.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
variable "pm_api_url" { default = "https://192.168.10.201:8006/api2/json" }
|
|
||||||
variable "pm_api_token" { default = "terraform@pve!provider=760580c4-5c1f-462b-986a-dd244c6c95f2" }
|
|
||||||
|
|
||||||
variable "storage" { default = "hlst" }
|
|
||||||
variable "bridge" { default = "vmbr0" }
|
|
||||||
|
|
||||||
|
|
||||||
variable "instance_configs" {
|
|
||||||
type = list(object({
|
|
||||||
crispy_name = string
|
|
||||||
vmid = string
|
|
||||||
}))
|
|
||||||
default = [
|
|
||||||
{ crispy_name = "snap", vmid = "9002" },
|
|
||||||
{ crispy_name = "crackle", vmid = "9000" },
|
|
||||||
{ crispy_name = "pop", vmid = "9001" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "clone_count" {
|
|
||||||
type = number
|
|
||||||
default = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vm_count" { default = 1 }
|
|
||||||
variable "name_prefix" { default = "dev" }
|
|
||||||
variable "vm_ram" { default = 2048 }
|
|
||||||
variable "vm_cpu" { default = 1 }
|
|
||||||
variable "vm_size" { default = 10 }
|
|
||||||
variable "vm_bios" {
|
|
||||||
description = "Type of BIOS used for the VM"
|
|
||||||
type = string
|
|
||||||
default = "ovmf"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vm_machine" {
|
|
||||||
description = "Type of machine used for the VM"
|
|
||||||
type = string
|
|
||||||
default = "q35"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vm_tags" {
|
|
||||||
description = "Tags for the VM"
|
|
||||||
type = list(any)
|
|
||||||
default = ["test", "terraform"]
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "ipconfig0" { default = "ip=dhcp" }
|
|
||||||
|
|
||||||
variable "access_key" {
|
|
||||||
type = string
|
|
||||||
default = "GK242d456c0692a9d4cc102206"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "secret_key" {
|
|
||||||
type = string
|
|
||||||
default = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "region" {
|
|
||||||
type = string
|
|
||||||
default = "garage"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "endpoints_s3" {
|
|
||||||
type = string
|
|
||||||
description = "S3 endpoint"
|
|
||||||
default = "http://192.168.10.109:3909"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "skip_credentials_validation" {
|
|
||||||
type = bool
|
|
||||||
default = true
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "skip_requesting_account_id" {
|
|
||||||
type = bool
|
|
||||||
default = true
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "skip_metadata_api_check" {
|
|
||||||
type = bool
|
|
||||||
default = true
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "skip_region_validation" {
|
|
||||||
type = bool
|
|
||||||
default = true
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "use_path_style" {
|
|
||||||
type = bool
|
|
||||||
default = true
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "use_lockfile" {
|
|
||||||
type = bool
|
|
||||||
default = true
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vm_name" {
|
|
||||||
description = "Hostname of the VM"
|
|
||||||
type = string
|
|
||||||
default = "Lab"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vm_user_sshkey" {
|
|
||||||
description = "Admin user SSH key of the VM"
|
|
||||||
type = string
|
|
||||||
default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRlWaLBt/qmWY01Cd6jN/YxLnlT+6lg+evEdN/dIajirdTj1rCbAdlG3WYvo+4BpN17HK3/eGQpGUMbgI/8MVd8YPODcD34gaNX0w2v66BwHx+S6BZUpz5T2IoQT0JtSv/TtFICoff5gXdNRpfd4eWsmTioEqLA6oToJLE4dn3jvAzFi9y7fyLqvuoQMmPidYYJjGT30eiULtXNspoEP+GmuWmVEu+znzMWaKDWKdOsii4Cv1aWCRKSDDRzDBrZI2mP+Vm4HDQBdgDYRw4ehumMDtfaSjyJCnrk691bIM+wxzICuIEecg5kq5HcUPvo2mFyWPAEXb5xlXnuopYEBd7 Generated By NeoServer"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
variable "node_name" {
|
|
||||||
description = "Proxmox host for the VM"
|
|
||||||
type = string
|
|
||||||
default = "pop"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "node_datastore" {
|
|
||||||
description = "Datastore used for VM storage"
|
|
||||||
type = string
|
|
||||||
default = "hlst"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vm_template" {
|
|
||||||
description = "Template of the VM"
|
|
||||||
type = string
|
|
||||||
default = "ubuntu-cloud"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
variable "vm_user" {
|
|
||||||
description = "Admin user of the VM"
|
|
||||||
type = string
|
|
||||||
default = "cloud"
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
output "vm_ipv4_addresses" {
|
output "vm_ipv4_addresses" {
|
||||||
description = "Map of instance key to VM IPv4 address"
|
description = "Map of instance key to VM IPv4 address"
|
||||||
value = {
|
value = {
|
||||||
for k, m in module.vm-n8n : k => m.vm_ipv4_address
|
for k, m in module.proxmox_ubuntu_cloudinit_clone : k => m.vm_ipv4_address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,12 +30,12 @@ output "vm_tag_data" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output "inventory_file" {
|
# output "inventory_file" {
|
||||||
description = "Path to the generated Ansible inventory"
|
# description = "Path to the generated Ansible inventory"
|
||||||
value = module.inventory.filename
|
# value = module.inventory.filename
|
||||||
}
|
# }
|
||||||
|
|
||||||
output "vm_data_file" {
|
# output "vm_data_file" {
|
||||||
description = "Path to the generated VM data file"
|
# description = "Path to the generated VM data file"
|
||||||
value = module.vm_data.filename
|
# value = module.vm_data.filename
|
||||||
}
|
# }
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ provider "aws" {
|
|||||||
region = "garage"
|
region = "garage"
|
||||||
access_key = "GK242d456c0692a9d4cc102206"
|
access_key = "GK242d456c0692a9d4cc102206"
|
||||||
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
|
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
|
||||||
# shared_credentials_files = ["$HOME/.aws/credentials"]
|
# shared_credentials_files = ["$HOME/.aws/credentials"]
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
instance_mode = "single"
|
instance_mode = "single"
|
||||||
|
|
||||||
instance = {
|
instance = {
|
||||||
service_name = "n8n"
|
service_name = "music"
|
||||||
vm_name = "n8n-01"
|
vm_name = "music-01"
|
||||||
node_name = "pop"
|
node_name = "snap"
|
||||||
app_port = 5678
|
app_port = 8688
|
||||||
app_image = "docker.n8n.io/n8nio/n8n"
|
app_image = "ghcr.io/habirabbu/droppedneedle:latest"
|
||||||
vm_tags = ["agentic"]
|
vm_tags = ["music", "downloader"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ variable "vm_defaults" {
|
|||||||
vm_user_sshkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRlWaLBt/qmWY01Cd6jN/YxLnlT+6lg+evEdN/dIajirdTj1rCbAdlG3WYvo+4BpN17HK3/eGQpGUMbgI/8MVd8YPODcD34gaNX0w2v66BwHx+S6BZUpz5T2IoQT0JtSv/TtFICoff5gXdNRpfd4eWsmTioEqLA6oToJLE4dn3jvAzFi9y7fyLqvuoQMmPidYYJjGT30eiULtXNspoEP+GmuWmVEu+znzMWaKDWKdOsii4Cv1aWCRKSDDRzDBrZI2mP+Vm4HDQBdgDYRw4ehumMDtfaSjyJCnrk691bIM+wxzICuIEecg5kq5HcUPvo2mFyWPAEXb5xlXnuopYEBd7 Generated By NeoServer"
|
vm_user_sshkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRlWaLBt/qmWY01Cd6jN/YxLnlT+6lg+evEdN/dIajirdTj1rCbAdlG3WYvo+4BpN17HK3/eGQpGUMbgI/8MVd8YPODcD34gaNX0w2v66BwHx+S6BZUpz5T2IoQT0JtSv/TtFICoff5gXdNRpfd4eWsmTioEqLA6oToJLE4dn3jvAzFi9y7fyLqvuoQMmPidYYJjGT30eiULtXNspoEP+GmuWmVEu+znzMWaKDWKdOsii4Cv1aWCRKSDDRzDBrZI2mP+Vm4HDQBdgDYRw4ehumMDtfaSjyJCnrk691bIM+wxzICuIEecg5kq5HcUPvo2mFyWPAEXb5xlXnuopYEBd7 Generated By NeoServer"
|
||||||
bridge = "vmbr0"
|
bridge = "vmbr0"
|
||||||
vm_cpu = 2
|
vm_cpu = 2
|
||||||
vm_ram = 4096
|
vm_ram = 8192
|
||||||
vm_size = 20
|
vm_size = 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user