generated from CC/VMServiceTemplate
n8n ansible base
This commit is contained in:
@@ -2,6 +2,20 @@ 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.vm[k].vm_ipv4_address
|
||||
vm_tags = concat(
|
||||
try(v.vm_tags, []),
|
||||
["terraform", "docker", v.service_name, "ip-${replace(module.vm[k].vm_ipv4_address, ".", "-")}"]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module "vm-n8n" {
|
||||
@@ -23,3 +37,15 @@ module "vm-n8n" {
|
||||
)
|
||||
vm_user_sshkey = var.vm_defaults.vm_user_sshkey
|
||||
}
|
||||
|
||||
module "inventory" {
|
||||
source = "./modules/proxmox_ansible_inventory"
|
||||
filename = "${path.module}/ansible/inventory/inventory.yml"
|
||||
instances = local.vm_created
|
||||
}
|
||||
|
||||
module "vm_data" {
|
||||
source = "./modules/proxmox_vm_data"
|
||||
filename = "${path.module}/terraform/vm_data.yml"
|
||||
instances = local.vm_created
|
||||
}
|
||||
|
||||
26
terraform/modules/proxmox_ansible_inventory/main.tf
Normal file
26
terraform/modules/proxmox_ansible_inventory/main.tf
Normal file
@@ -0,0 +1,26 @@
|
||||
locals {
|
||||
inventory = {
|
||||
all = {
|
||||
vars = {
|
||||
ansible_user = "cloud"
|
||||
}
|
||||
children = {
|
||||
for svc in distinct([for k, v in var.instances : v.service_name]) :
|
||||
svc => {
|
||||
hosts = {
|
||||
for k, v in var.instances :
|
||||
v.vm_name => {
|
||||
ansible_host = v.ipv4_address
|
||||
}
|
||||
if v.service_name == svc
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "local_file" "inventory" {
|
||||
filename = var.filename
|
||||
content = yamlencode(local.inventory)
|
||||
}
|
||||
7
terraform/modules/proxmox_ansible_inventory/outputs.tf
Normal file
7
terraform/modules/proxmox_ansible_inventory/outputs.tf
Normal file
@@ -0,0 +1,7 @@
|
||||
output "filename" {
|
||||
value = local_file.inventory.filename
|
||||
}
|
||||
|
||||
output "content" {
|
||||
value = local_file.inventory.content
|
||||
}
|
||||
13
terraform/modules/proxmox_ansible_inventory/variables.tf
Normal file
13
terraform/modules/proxmox_ansible_inventory/variables.tf
Normal file
@@ -0,0 +1,13 @@
|
||||
variable "filename" {
|
||||
description = "Path to write the inventory.yml file"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "instances" {
|
||||
description = "Normalized instance map keyed by instance key"
|
||||
type = map(object({
|
||||
service_name = string
|
||||
vm_name = string
|
||||
ipv4_address = string
|
||||
}))
|
||||
}
|
||||
17
terraform/modules/proxmox_vm_data/main.tf
Normal file
17
terraform/modules/proxmox_vm_data/main.tf
Normal file
@@ -0,0 +1,17 @@
|
||||
locals {
|
||||
vm_data = {
|
||||
vm_tag_data = {
|
||||
for k, v in var.instances :
|
||||
k => {
|
||||
node_name = v.node_name
|
||||
vm_name = v.vm_name
|
||||
tags = v.vm_tags
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "local_file" "vm_data" {
|
||||
filename = var.filename
|
||||
content = yamlencode(local.vm_data)
|
||||
}
|
||||
7
terraform/modules/proxmox_vm_data/outputs.tf
Normal file
7
terraform/modules/proxmox_vm_data/outputs.tf
Normal file
@@ -0,0 +1,7 @@
|
||||
output "filename" {
|
||||
value = local_file.vm_data.filename
|
||||
}
|
||||
|
||||
output "content" {
|
||||
value = local_file.vm_data.content
|
||||
}
|
||||
15
terraform/modules/proxmox_vm_data/variables.tf
Normal file
15
terraform/modules/proxmox_vm_data/variables.tf
Normal file
@@ -0,0 +1,15 @@
|
||||
variable "filename" {
|
||||
description = "Path to write the vm_data.yml file"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "instances" {
|
||||
description = "Normalized instance map keyed by instance key"
|
||||
type = map(object({
|
||||
service_name = string
|
||||
vm_name = string
|
||||
node_name = string
|
||||
ipv4_address = string
|
||||
vm_tags = list(string)
|
||||
}))
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
instance_mode = "single"
|
||||
|
||||
instance = {
|
||||
service_name = "n8n"
|
||||
vm_name = "n8n-01"
|
||||
node_name = "pop"
|
||||
app_port = 5678
|
||||
app_image = "docker.n8n.io/n8nio/n8n"
|
||||
vm_tags = ["agentic"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user