mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
feat(tf): ct-config
This commit is contained in:
parent
613c3bb599
commit
69c2b81e3d
8 changed files with 153 additions and 33 deletions
51
tf/system/proxmox/lxc/config/config.tf
Normal file
51
tf/system/proxmox/lxc/config/config.tf
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
variable "connection" {
|
||||
type = map(any)
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "vm_id" {
|
||||
type = number
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "container" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "config" {
|
||||
type = map(list(string))
|
||||
}
|
||||
|
||||
locals {
|
||||
vm_id = var.vm_id != null ? var.vm_id : var.container.vm_id
|
||||
depends_container = var.container != null ? [var.container] : []
|
||||
config = flatten([for key, values in var.config :
|
||||
[for value in values : "${key} '${value}'"]
|
||||
])
|
||||
}
|
||||
|
||||
resource "terraform_data" "config" {
|
||||
depends_on = [
|
||||
local.depends_container,
|
||||
]
|
||||
|
||||
triggers_replace = {
|
||||
container = var.container != null ? var.container.id : tostring(local.vm_id)
|
||||
config = var.config
|
||||
}
|
||||
|
||||
connection {
|
||||
type = coalesce(var.connection["type"], "ssh")
|
||||
user = coalesce(var.connection["user"], "root")
|
||||
password = var.connection["password"]
|
||||
host = var.connection["host"]
|
||||
port = coalesce(var.connection["port"], 22)
|
||||
}
|
||||
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"ct-config ${local.vm_id} ${join(" ", local.config)}",
|
||||
]
|
||||
}
|
||||
}
|
||||
3
tf/system/proxmox/lxc/config/terraform.tf
Normal file
3
tf/system/proxmox/lxc/config/terraform.tf
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
terraform {
|
||||
required_version = ">= 1.6.0"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue