generated from CC/VMServiceTemplate
Compare commits
26 Commits
7f679b6ae2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e785930578 | |||
|
|
92f9bd459d | ||
|
|
8518bd6064 | ||
|
|
3c7a22032a | ||
|
|
a363aafd97 | ||
|
|
e40fb6742a | ||
|
|
da2362d0a9 | ||
|
|
684a86385b | ||
|
|
eded1b9777 | ||
|
|
80c611ecda | ||
|
|
2d27326cbc | ||
|
|
325d61bef0 | ||
|
|
4bff0f9703 | ||
| 2f505e5062 | |||
|
|
d73dd0919d | ||
|
|
ba593526bd | ||
|
|
adc4188918 | ||
|
|
5e4d5c82d8 | ||
|
|
31cc759d4d | ||
|
|
afbd95d765 | ||
|
|
ae70feaaf3 | ||
|
|
d68ab4b309 | ||
|
|
1cb81833d7 | ||
|
|
bf11724516 | ||
|
|
317bf4be62 | ||
|
|
edaff5a978 |
@@ -1,6 +1,8 @@
|
|||||||
name: Deploy VM and App
|
name: Deploy VM and App
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
tfvars_file:
|
tfvars_file:
|
||||||
@@ -21,11 +23,11 @@ jobs:
|
|||||||
- name: Check files & Select tfvars
|
- name: Check files & Select tfvars
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
pwd
|
#rm ansible/inventory/inventory.yml
|
||||||
mkdir -p ansible/inventory
|
mkdir -p ansible/inventory
|
||||||
cd terraform
|
cd terraform
|
||||||
cp ${{ inputs.tfvars_file }} terraform.tfvars
|
#rm vm_data.yml
|
||||||
ls
|
cp "${{ inputs.tfvars_file || 'single.tfvars.example' }}" terraform.tfvars
|
||||||
|
|
||||||
- uses: hashicorp/setup-terraform@v4
|
- uses: hashicorp/setup-terraform@v4
|
||||||
|
|
||||||
@@ -40,6 +42,27 @@ jobs:
|
|||||||
run: terraform apply -auto-approve
|
run: terraform apply -auto-approve
|
||||||
working-directory: "terraform"
|
working-directory: "terraform"
|
||||||
|
|
||||||
|
- name: Install Ansible
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y ansible rsync
|
||||||
|
|
||||||
|
- name: Set up SSH
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/vlans_rsa
|
||||||
|
chmod 600 ~/.ssh/vlans_rsa
|
||||||
|
cat > ~/.ssh/config <<'EOF'
|
||||||
|
Host *
|
||||||
|
StrictHostKeyChecking no
|
||||||
|
UserKnownHostsFile=/dev/null
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Run playbook
|
||||||
|
run: |
|
||||||
|
ansible-playbook ansible/playbooks/docker_copy.yml -i ansible/inventory/inventory.yml -u cloud --private-key ~/.ssh/vlans_rsa
|
||||||
|
|
||||||
- name: Configure Git
|
- name: Configure Git
|
||||||
run: |
|
run: |
|
||||||
git config user.name "git-bot"
|
git config user.name "git-bot"
|
||||||
@@ -53,26 +76,3 @@ jobs:
|
|||||||
git push origin HEAD:main
|
git push origin HEAD:main
|
||||||
env:
|
env:
|
||||||
GITEA_USERNAME: git-bot # or your bot account
|
GITEA_USERNAME: git-bot # or your bot account
|
||||||
|
|
||||||
- name: Install Ansible
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y ansible
|
|
||||||
|
|
||||||
- name: Set up SSH
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
echo -e "Host *\n\tStrictHostKeyChecking no\n\tUserKnownHostsFile=/dev/null\n" > ~/.ssh/config
|
|
||||||
|
|
||||||
- name: Setup Ansible Directories
|
|
||||||
run: |
|
|
||||||
pwd
|
|
||||||
cat ansible/inventory/inventory.yml
|
|
||||||
ls -r
|
|
||||||
|
|
||||||
- name: Run playbook
|
|
||||||
run: |
|
|
||||||
ansible-playbook ansible/playbooks/docker_copy.yml -i ansible/inventory/inventory.yml -u cloud --private-key ~/.ssh/id_rsa
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
"n8n":
|
"n8n":
|
||||||
"hosts":
|
"hosts":
|
||||||
"n8n-01":
|
"n8n-01":
|
||||||
"ansible_host": "192.168.10.117"
|
"ansible_host": "192.168.10.107"
|
||||||
"vars":
|
"vars":
|
||||||
"ansible_user": "cloud"
|
"ansible_user": "cloud"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ locals {
|
|||||||
|
|
||||||
module "vm-n8n" {
|
module "vm-n8n" {
|
||||||
for_each = local.instance_map
|
for_each = local.instance_map
|
||||||
source = "./modules/proxmox_ubuntu_cloudinit_template"
|
source = "./modules/proxmox_ubuntu_cloudinit_clone"
|
||||||
|
|
||||||
vm_name = each.value.vm_name
|
vm_name = each.value.vm_name
|
||||||
node_name = each.value.node_name
|
node_name = each.value.node_name
|
||||||
|
|||||||
123
terraform/modules/proxmox_ubuntu_cloudinit_clone/main.tf
Normal file
123
terraform/modules/proxmox_ubuntu_cloudinit_clone/main.tf
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
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_clone" {
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
clone {
|
||||||
|
vm_id = local.selected_instance.vmid # ID of the source template
|
||||||
|
node_name = local.selected_instance.crispy_name # Node of the source template
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
disk {
|
||||||
|
datastore_id = var.node_datastore # Datastore to hold the disk
|
||||||
|
interface = "scsi0" # Primary disk interface
|
||||||
|
size = var.vm_size
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycle {
|
||||||
|
ignore_changes = [ # Ignore initialization section after first depoloyment for idempotency
|
||||||
|
initialization
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
output "vm_ipv4_address" {
|
||||||
|
value = proxmox_virtual_environment_vm.ubuntu_22_minimal_clone.ipv4_addresses[1][0]
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
140
terraform/modules/proxmox_ubuntu_cloudinit_clone/variables.tf
Normal file
140
terraform/modules/proxmox_ubuntu_cloudinit_clone/variables.tf
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
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 "os_type" {
|
||||||
|
default = "alpine"
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "900" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
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,10 +1,14 @@
|
|||||||
variable "instance_mode" {
|
variable "instance_mode" {
|
||||||
type = string
|
type = string
|
||||||
default = "single"
|
description = "single or multiple"
|
||||||
|
|
||||||
|
validation {
|
||||||
|
condition = contains(["single", "multiple"], var.instance_mode)
|
||||||
|
error_message = "instance_mode must be either single or multiple."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instance" {
|
variable "instance" {
|
||||||
description = "Single instance definition"
|
|
||||||
type = object({
|
type = object({
|
||||||
service_name = string
|
service_name = string
|
||||||
vm_name = string
|
vm_name = string
|
||||||
@@ -12,15 +16,14 @@ variable "instance" {
|
|||||||
vm_cpu = optional(number)
|
vm_cpu = optional(number)
|
||||||
vm_ram = optional(number)
|
vm_ram = optional(number)
|
||||||
vm_size = optional(string)
|
vm_size = optional(string)
|
||||||
app_port = number
|
|
||||||
app_image = string
|
|
||||||
vm_tags = optional(list(string))
|
vm_tags = optional(list(string))
|
||||||
})
|
})
|
||||||
default = null
|
default = null
|
||||||
|
nullable = true
|
||||||
|
description = "Used only when instance_mode = single."
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instances" {
|
variable "instances" {
|
||||||
description = "Multiple instance definitions"
|
|
||||||
type = map(object({
|
type = map(object({
|
||||||
service_name = string
|
service_name = string
|
||||||
vm_name = string
|
vm_name = string
|
||||||
@@ -28,13 +31,14 @@ variable "instances" {
|
|||||||
vm_cpu = optional(number)
|
vm_cpu = optional(number)
|
||||||
vm_ram = optional(number)
|
vm_ram = optional(number)
|
||||||
vm_size = optional(string)
|
vm_size = optional(string)
|
||||||
app_port = number
|
|
||||||
app_image = string
|
|
||||||
vm_tags = optional(list(string))
|
vm_tags = optional(list(string))
|
||||||
}))
|
}))
|
||||||
default = {}
|
default = {}
|
||||||
|
nullable = false
|
||||||
|
description = "Used only when instance_mode = multiple."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
variable "vm_defaults" {
|
variable "vm_defaults" {
|
||||||
type = object({
|
type = object({
|
||||||
node_datastore = string
|
node_datastore = string
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
- "terraform"
|
- "terraform"
|
||||||
- "docker"
|
- "docker"
|
||||||
- "n8n"
|
- "n8n"
|
||||||
- "ip-192-168-10-117"
|
- "ip-192-168-10-107"
|
||||||
"vm_name": "n8n-01"
|
"vm_name": "n8n-01"
|
||||||
|
|||||||
Reference in New Issue
Block a user