TF: be modularized
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
parent
cb753ef08b
commit
86a215c074
5 changed files with 81 additions and 14 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
29
tf/servers.tf
Normal file
29
tf/servers.tf
Normal 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
|
||||
}
|
16
tf/vars.tf
16
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
|
||||
}
|
||||
|
|
|
@ -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 ]
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue