diff --git a/tf/providers.tf b/tf/providers.tf index 3175979..e858290 100644 --- a/tf/providers.tf +++ b/tf/providers.tf @@ -11,9 +11,19 @@ terraform { provider "proxmox" { + alias = "cessy" insecure = true endpoint = "https://proxmox-cessy.lan.k3s.fr:8006/" ssh { agent = true } } + +provider "proxmox" { + alias = "cranves" + insecure = true + endpoint = "https://proxmox-cranves.lan.k3s.fr:8006/" + ssh { + agent = true + } +} diff --git a/tf/servers.tf b/tf/servers.tf new file mode 100644 index 0000000..5e04982 --- /dev/null +++ b/tf/servers.tf @@ -0,0 +1,29 @@ +module "ntp_serv_ces" { + source = "./vm" + providers = { + proxmox = proxmox.cessy + } + px_node = var.px_node_cessy + px_vmid = var.px_vmid_cessy + + hostname = "ntp-s2-ces" + + ipv4_addr = "192.168.43.123" + ipv4_gw = "192.168.43.254" + px_vlanid = null +} + +module "ntp_serv_cra" { + source = "./vm" + providers = { + proxmox = proxmox.cranves + } + px_node = var.px_node_cranves + px_vmid = var.px_vmid_cranves + + hostname = "ntp-s2-cra" + + ipv4_addr = "192.168.21.123" + ipv4_gw = "192.168.21.254" + px_vlanid = 21 +} \ No newline at end of file diff --git a/tf/vars.tf b/tf/vars.tf index 08fd1a5..1562ca7 100644 --- a/tf/vars.tf +++ b/tf/vars.tf @@ -1,10 +1,18 @@ -variable "proxmox_node_name" { +variable "px_node_cessy" { type = string default = "n00" } - -variable "proxmox_vmid" { +variable "px_vmid_cessy" { type = number - default = 150 + default = 123 +} + +variable "px_node_cranves" { + type = string + default = "fatty" # Coz backuped by chronos +} +variable "px_vmid_cranves" { + type = number + default = 123 } diff --git a/tf/cloud-init.tpl.cfg b/tf/vm/cloud-init.tpl.cfg similarity index 97% rename from tf/cloud-init.tpl.cfg rename to tf/vm/cloud-init.tpl.cfg index 7b15818..e0b0b39 100644 --- a/tf/cloud-init.tpl.cfg +++ b/tf/vm/cloud-init.tpl.cfg @@ -16,7 +16,7 @@ write_files: version: 2 ethernets: ens18: - addresses: [ ${ipv4_addr_cidr} ] + addresses: [ ${ipv4_addr}/24 ] gateway4: ${ipv4_gw} nameservers: addresses: [ 192.168.21.254, 192.168.43.254 ] diff --git a/tf/ntp.tf b/tf/vm/ntp.tf similarity index 57% rename from tf/ntp.tf rename to tf/vm/ntp.tf index eb47e1e..c529d65 100644 --- a/tf/ntp.tf +++ b/tf/vm/ntp.tf @@ -1,27 +1,46 @@ +terraform { + required_providers { + proxmox = { + source = "bpg/proxmox" + version = "0.58.1" + } + } +} +variable "hostname" { +} +variable "ipv4_addr" { +} +variable "ipv4_gw" { +} +variable "px_node" { +} +variable "px_vmid" { +} +variable "px_vlanid" {} resource "proxmox_virtual_environment_file" "this" { content_type = "snippets" datastore_id = "local" - node_name = var.proxmox_node_name + node_name = var.px_node source_raw { data = templatefile("${path.module}/cloud-init.tpl.cfg", { - hostname = "ntp-s2", - ipv4_addr_cidr = "192.168.43.15/24" - ipv4_gw = "192.168.43.254" + hostname = var.hostname, + ipv4_addr = var.ipv4_addr, + ipv4_gw = var.ipv4_gw, }) - file_name = "ntp-s2.cloud-config.yaml" + file_name = "${var.hostname}.cloud-config.yaml" } } resource "proxmox_virtual_environment_vm" "this" { - name = "ntp-s2" + name = var.hostname description = "Managed by Terraform" started = true on_boot = true - node_name = var.proxmox_node_name - vm_id = var.proxmox_vmid + node_name = var.px_node + vm_id = var.px_vmid cpu { cores = 1 @@ -38,7 +57,7 @@ resource "proxmox_virtual_environment_vm" "this" { file_format = "qcow2" interface = "scsi0" file_id = "local:iso/noble-server-cloudimg-amd64.img" - size = "20" + size = "10" } initialization { @@ -48,5 +67,6 @@ resource "proxmox_virtual_environment_vm" "this" { network_device { bridge = "vmbr0" + vlan_id = var.px_vlanid } }