TF: be modularized

Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-06-18 20:21:22 +02:00
parent cb753ef08b
commit 86a215c074
5 changed files with 81 additions and 14 deletions

View file

@ -11,9 +11,19 @@ terraform {
provider "proxmox" { provider "proxmox" {
alias = "cessy"
insecure = true insecure = true
endpoint = "https://proxmox-cessy.lan.k3s.fr:8006/" endpoint = "https://proxmox-cessy.lan.k3s.fr:8006/"
ssh { ssh {
agent = true agent = true
} }
} }
provider "proxmox" {
alias = "cranves"
insecure = true
endpoint = "https://proxmox-cranves.lan.k3s.fr:8006/"
ssh {
agent = true
}
}

29
tf/servers.tf Normal file
View file

@ -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
}

View file

@ -1,10 +1,18 @@
variable "proxmox_node_name" { variable "px_node_cessy" {
type = string type = string
default = "n00" default = "n00"
} }
variable "px_vmid_cessy" {
variable "proxmox_vmid" {
type = number 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
} }

View file

@ -16,7 +16,7 @@ write_files:
version: 2 version: 2
ethernets: ethernets:
ens18: ens18:
addresses: [ ${ipv4_addr_cidr} ] addresses: [ ${ipv4_addr}/24 ]
gateway4: ${ipv4_gw} gateway4: ${ipv4_gw}
nameservers: nameservers:
addresses: [ 192.168.21.254, 192.168.43.254 ] addresses: [ 192.168.21.254, 192.168.43.254 ]

View file

@ -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" { resource "proxmox_virtual_environment_file" "this" {
content_type = "snippets" content_type = "snippets"
datastore_id = "local" datastore_id = "local"
node_name = var.proxmox_node_name node_name = var.px_node
source_raw { source_raw {
data = templatefile("${path.module}/cloud-init.tpl.cfg", { data = templatefile("${path.module}/cloud-init.tpl.cfg", {
hostname = "ntp-s2", hostname = var.hostname,
ipv4_addr_cidr = "192.168.43.15/24" ipv4_addr = var.ipv4_addr,
ipv4_gw = "192.168.43.254" 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" { resource "proxmox_virtual_environment_vm" "this" {
name = "ntp-s2" name = var.hostname
description = "Managed by Terraform" description = "Managed by Terraform"
started = true started = true
on_boot = true on_boot = true
node_name = var.proxmox_node_name node_name = var.px_node
vm_id = var.proxmox_vmid vm_id = var.px_vmid
cpu { cpu {
cores = 1 cores = 1
@ -38,7 +57,7 @@ resource "proxmox_virtual_environment_vm" "this" {
file_format = "qcow2" file_format = "qcow2"
interface = "scsi0" interface = "scsi0"
file_id = "local:iso/noble-server-cloudimg-amd64.img" file_id = "local:iso/noble-server-cloudimg-amd64.img"
size = "20" size = "10"
} }
initialization { initialization {
@ -48,5 +67,6 @@ resource "proxmox_virtual_environment_vm" "this" {
network_device { network_device {
bridge = "vmbr0" bridge = "vmbr0"
vlan_id = var.px_vlanid
} }
} }