initial template

This commit is contained in:
CC
2026-05-20 22:59:27 +01:00
commit b45851e888
8 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
name: Deploy VM and App
on:
workflow_dispatch:
jobs:
terraform:
runs-on: ubuntu-latest
defaults:
run:
working-directory: terraform
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- name: Terraform init
run: terraform init
- name: Terraform apply
run: terraform apply -auto-approve
- name: Write inventory from output
run: |
IP=$(terraform output -raw vm_ipv4_address)
mkdir -p ../ansible/inventory
printf '[app]\n%s ansible_user=cloud\n' "$IP" > ../ansible/inventory/hosts.ini
- name: Write tags file
run: |
TAGS=$(terraform output -json vm_tags)
echo "$TAGS" > ../terraform/vm_tags.json
deploy:
needs: terraform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Ansible
run: |
python3 -m pip install --upgrade pip
pip install ansible community.docker
- name: Deploy app
run: ansible-playbook -i ansible/inventory/hosts.ini ansible/playbooks/deploy.yml

2
compose/.env Normal file
View File

@@ -0,0 +1,2 @@
APP_NAME=myservice
APP_PORT=8080

View File

@@ -0,0 +1,9 @@
services:
app:
image: your-image:latest
container_name: ${APP_NAME}
restart: unless-stopped
ports:
- "${APP_PORT}:8080"
environment:
- TZ=Europe/London

18
terraform/backend.tf Normal file
View File

@@ -0,0 +1,18 @@
terraform {
backend "s3" {
bucket = "terraform"
key = "template/terraform.tfstate"
access_key = "GK242d456c0692a9d4cc102206"
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
region = "garage"
endpoints = {
s3 = "http://192.168.10.109:3900"
}
skip_credentials_validation = true
skip_requesting_account_id = true
skip_metadata_api_check = true
skip_region_validation = true
use_path_style = true
use_lockfile = true
}
}

20
terraform/main.tf Normal file
View File

@@ -0,0 +1,20 @@
module "vm" {
source = "git::https://your-git-server/infra/modules/proxmox_ubuntu_cloudinit.git//?ref=v1.0.0"
vm_name = var.vm_name
node_name = var.node_name
node_datastore = var.node_datastore
bridge = var.bridge
vm_cpu = var.vm_cpu
vm_ram = var.vm_ram
vm_size = var.vm_size
vm_bios = var.vm_bios
vm_machine = var.vm_machine
vm_tags = local.all_tags
vm_user_sshkey = var.vm_user_sshkey
}
locals {
ip_tag = "ip-${replace(module.vm.vm_ipv4_address, ".", "-")}"
all_tags = concat(var.vm_tags, ["terraform", "docker"], [local.ip_tag])
}

11
terraform/output.tf Normal file
View File

@@ -0,0 +1,11 @@
output "vm_name" {
value = var.vm_name
}
output "vm_ipv4_address" {
value = module.vm.vm_ipv4_address
}
output "vm_tags" {
value = local.all_tags
}

33
terraform/providers.tf Normal file
View File

@@ -0,0 +1,33 @@
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"
}
}
}
provider "proxmox" {
endpoint = var.pm_api_url
api_token = var.pm_api_token
insecure = true
# === FIX THIS ===
ssh {
agent = true
username = "root"
password = "Ishimaru17"
}
}
provider "aws" {
region = "garage"
access_key = "GK242d456c0692a9d4cc102206"
secret_key = "1d7e22b7a8892cb11b569017659aa511b37b53287c4d1699c310d9f8ac76df09"
# shared_credentials_files = ["$HOME/.aws/credentials"]
}

13
terraform/variables.tf Normal file
View File

@@ -0,0 +1,13 @@
variable "vm_name" { type = string }
variable "node_name" { type = string }
variable "node_datastore" { type = string }
variable "bridge" { type = string, default = "vmbr0" }
variable "vm_cpu" { type = number, default = 2 }
variable "vm_ram" { type = number, default = 4096 }
variable "vm_size" { type = string, default = "20G" }
variable "vm_bios" { type = string, default = "ovmf" }
variable "vm_machine" { type = string, default = "q35" }
variable "vm_tags" { type = list(string), default = ["terraform"] }
variable "vm_user_sshkey" { type = string }
variable "app_name" { type = string, default = "myservice" }
variable "app_port" { type = number, default = 8080 }