initial template v1
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
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])
|
||||
instance_map = var.instance_mode == "single" ? {
|
||||
main = var.instance
|
||||
} : var.instances
|
||||
}
|
||||
|
||||
module "vm" {
|
||||
for_each = local.instance_map
|
||||
source = "git::https://tea.charcarservices.uk/CC/TerraformModules.git//proxmox_ubuntu_cloudinit_template?ref=main"
|
||||
|
||||
vm_name = each.value.vm_name
|
||||
node_name = each.value.node_name
|
||||
node_datastore = var.vm_defaults.node_datastore
|
||||
bridge = var.vm_defaults.bridge
|
||||
vm_cpu = coalesce(try(each.value.vm_cpu, null), var.vm_defaults.vm_cpu)
|
||||
vm_ram = coalesce(try(each.value.vm_ram, null), var.vm_defaults.vm_ram)
|
||||
vm_size = coalesce(try(each.value.vm_size, null), var.vm_defaults.vm_size)
|
||||
vm_bios = var.vm_defaults.vm_bios
|
||||
vm_machine = var.vm_defaults.vm_machine
|
||||
vm_tags = concat(
|
||||
try(each.value.vm_tags, []),
|
||||
["terraform", "docker", each.value.service_name]
|
||||
)
|
||||
vm_user_sshkey = var.vm_defaults.vm_user_sshkey
|
||||
}
|
||||
|
||||
21
terraform/multi.tfvars.example
Normal file
21
terraform/multi.tfvars.example
Normal file
@@ -0,0 +1,21 @@
|
||||
instance_mode = "multi"
|
||||
|
||||
instances = {
|
||||
grafana = {
|
||||
service_name = "grafana"
|
||||
vm_name = "grafana-01"
|
||||
node_name = "pop"
|
||||
app_port = 3000
|
||||
app_image = "grafana/grafana:latest"
|
||||
vm_tags = ["monitoring"]
|
||||
}
|
||||
|
||||
caddy = {
|
||||
service_name = "caddy"
|
||||
vm_name = "caddy-01"
|
||||
node_name = "pop"
|
||||
app_port = 80
|
||||
app_image = "caddy:latest"
|
||||
vm_tags = ["proxy"]
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,20 @@
|
||||
output "vm_name" {
|
||||
value = var.vm_name
|
||||
}
|
||||
|
||||
output "vm_ipv4_address" {
|
||||
value = module.vm.vm_ipv4_address
|
||||
output "vm_ipv4_addresses" {
|
||||
value = {
|
||||
for k, m in module.vm : k => m.vm_ipv4_address
|
||||
}
|
||||
}
|
||||
|
||||
output "vm_tags" {
|
||||
value = local.all_tags
|
||||
value = {
|
||||
for k, m in module.vm : k => concat(
|
||||
try(local.instance_map[k].vm_tags, []),
|
||||
["terraform", "docker", local.instance_map[k].service_name, "ip-${replace(m.vm_ipv4_address, ".", "-")}"]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
output "service_names" {
|
||||
value = {
|
||||
for k, cfg in local.instance_map : k => cfg.service_name
|
||||
}
|
||||
}
|
||||
|
||||
21
terraform/single.tfvars.example
Normal file
21
terraform/single.tfvars.example
Normal file
@@ -0,0 +1,21 @@
|
||||
instance_mode = "single"
|
||||
|
||||
instance = {
|
||||
service_name = "grafana"
|
||||
vm_name = "grafana-01"
|
||||
node_name = "pop"
|
||||
app_port = 3000
|
||||
app_image = "grafana/grafana:latest"
|
||||
vm_tags = ["monitoring"]
|
||||
}
|
||||
|
||||
vm_defaults = {
|
||||
node_datastore = "hlst"
|
||||
vm_bios = "ovmf"
|
||||
vm_machine = "q35"
|
||||
vm_user_sshkey = "ssh-ed25519 AAAA..."
|
||||
bridge = "vmbr0"
|
||||
vm_cpu = 2
|
||||
vm_ram = 4096
|
||||
vm_size = "20G"
|
||||
}
|
||||
@@ -1,13 +1,59 @@
|
||||
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 }
|
||||
variable "instance_mode" {
|
||||
type = string
|
||||
default = "single"
|
||||
}
|
||||
|
||||
variable "instance" {
|
||||
description = "Single instance definition"
|
||||
type = object({
|
||||
service_name = string
|
||||
vm_name = string
|
||||
node_name = string
|
||||
vm_cpu = optional(number)
|
||||
vm_ram = optional(number)
|
||||
vm_size = optional(string)
|
||||
app_port = number
|
||||
app_image = string
|
||||
vm_tags = optional(list(string))
|
||||
})
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "instances" {
|
||||
description = "Multiple instance definitions"
|
||||
type = map(object({
|
||||
service_name = string
|
||||
vm_name = string
|
||||
node_name = string
|
||||
vm_cpu = optional(number)
|
||||
vm_ram = optional(number)
|
||||
vm_size = optional(string)
|
||||
app_port = number
|
||||
app_image = string
|
||||
vm_tags = optional(list(string))
|
||||
}))
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "vm_defaults" {
|
||||
type = object({
|
||||
node_datastore = string
|
||||
vm_bios = string
|
||||
vm_machine = string
|
||||
vm_user_sshkey = string
|
||||
bridge = string
|
||||
vm_cpu = number
|
||||
vm_ram = number
|
||||
vm_size = string
|
||||
})
|
||||
default = {
|
||||
node_datastore = "hlst"
|
||||
vm_bios = "ovmf"
|
||||
vm_machine = "q35"
|
||||
vm_user_sshkey = ""
|
||||
bridge = "vmbr0"
|
||||
vm_cpu = 1
|
||||
vm_ram = 2048
|
||||
vm_size = "20G"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user