feat: add module
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
commit
920835d662
2
.drone.yml
Normal file
2
.drone.yml
Normal file
@ -0,0 +1,2 @@
|
||||
kind: template
|
||||
load: cuddle-empty-plan.yaml
|
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
.cuddle/
|
||||
*.tfvars
|
||||
.terraform/
|
||||
.terraform.lock.hcl
|
||||
.env
|
||||
*.secret.txt
|
||||
**/id_rsa*
|
16
cuddle.yaml
Normal file
16
cuddle.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json
|
||||
|
||||
base: "git@git.front.kjuulh.io:kjuulh/cuddle-empty-plan.git"
|
||||
|
||||
vars:
|
||||
service: "clank-node"
|
||||
registry: kasperhermansen
|
||||
|
||||
please:
|
||||
project:
|
||||
owner: kjuulh
|
||||
repository: "clank-node"
|
||||
branch: main
|
||||
settings:
|
||||
api_url: https://git.front.kjuulh.io
|
||||
|
107
node.tf
Normal file
107
node.tf
Normal file
@ -0,0 +1,107 @@
|
||||
locals {
|
||||
cloud_init_config = templatefile("${path.module}/files/cloud_init_deb12.cloud_config", {
|
||||
hostname = var.name
|
||||
domain = var.domain
|
||||
})
|
||||
}
|
||||
|
||||
# Create a local copy of the file, to transfer to Proxmox
|
||||
resource "local_file" "cloud_init_deb12_node" {
|
||||
content = local.cloud_init_config
|
||||
filename = "${path.module}/files/user_data_cloud_init_deb12_${var.name}.cfg"
|
||||
}
|
||||
|
||||
# Transfer the file to the Proxmox Host
|
||||
resource "null_resource" "cloud_init_deb12_node" {
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = "root"
|
||||
private_key = var.ssh_private
|
||||
host = var.proxmox_ip
|
||||
}
|
||||
|
||||
provisioner "file" {
|
||||
source = local_file.cloud_init_deb12_node.filename
|
||||
destination = "/var/lib/vz/snippets/cloud_init_deb12_node_${var.name}.yml"
|
||||
}
|
||||
|
||||
depends_on = [
|
||||
local_file.cloud_init_deb12_node
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
# Create the VM
|
||||
resource "proxmox_vm_qemu" "node" {
|
||||
## Wait for the cloud-config file to exist
|
||||
|
||||
depends_on = [
|
||||
null_resource.cloud_init_deb12_node
|
||||
]
|
||||
|
||||
name = var.name
|
||||
target_node = var.proxmox_node
|
||||
|
||||
# Clone from debian-cloudinit template
|
||||
clone = var.cloud_init_template
|
||||
os_type = "cloud-init"
|
||||
|
||||
# Cloud init options
|
||||
cicustom = "vendor=local:snippets/cloud_init_deb12_node.yml"
|
||||
ipconfig0 = "ip=${var.ip_address},gw=${var.gateway}"
|
||||
|
||||
cpu = var.cpu
|
||||
memory = var.memory
|
||||
agent = 1
|
||||
|
||||
sshkeys = var.ssh_pub
|
||||
|
||||
bios = "ovmf"
|
||||
|
||||
ciuser = "root"
|
||||
cipassword = var.user_password
|
||||
|
||||
# Set the boot disk paramters
|
||||
bootdisk = "scsi0"
|
||||
scsihw = "virtio-scsi-single"
|
||||
|
||||
serial {
|
||||
id = 0
|
||||
}
|
||||
|
||||
network {
|
||||
id = 0
|
||||
bridge = "vmbr1"
|
||||
model = "virtio"
|
||||
}
|
||||
|
||||
disks {
|
||||
scsi {
|
||||
scsi0 {
|
||||
# We have to specify the disk from our template, else Terraform will think it's not supposed to be there
|
||||
disk {
|
||||
storage = "local"
|
||||
# The size of the disk should be at least as big as the disk in the template. If it's smaller, the disk will be recreated
|
||||
size = "10G"
|
||||
}
|
||||
}
|
||||
}
|
||||
ide {
|
||||
# Some images require a cloud-init disk on the IDE controller, others on the SCSI or SATA controller
|
||||
ide1 {
|
||||
cloudinit {
|
||||
storage = "local"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Ignore changes to the network
|
||||
## MAC address is generated on every apply, causing
|
||||
## TF to think this needs to be rebuilt on every apply
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
network
|
||||
]
|
||||
}
|
||||
}
|
17
provider.tf
Normal file
17
provider.tf
Normal file
@ -0,0 +1,17 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "Telmate/proxmox"
|
||||
version = "3.0.1-rc6"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.13"
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
pm_api_url = var.proxmox_url
|
||||
pm_user = var.proxmox_user
|
||||
pm_password = var.proxmox_password
|
||||
pm_tls_insecure = true
|
||||
}
|
||||
|
3
renovate.json
Normal file
3
renovate.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
66
variables.tf
Normal file
66
variables.tf
Normal file
@ -0,0 +1,66 @@
|
||||
variable "proxmox_url" {
|
||||
description = "full url of the proxmox api"
|
||||
default = "https://proxmox.i.kjuulh.io/api2/json"
|
||||
}
|
||||
|
||||
variable "proxmox_user" {
|
||||
description = "proxmox username (eg. <name>@pve)"
|
||||
}
|
||||
|
||||
variable "proxmox_password" {
|
||||
description = "proxmox password"
|
||||
}
|
||||
|
||||
variable "proxmox_ip" {
|
||||
description = "the ip address of the proxmox instance"
|
||||
default = "10.0.11.0"
|
||||
}
|
||||
|
||||
variable "proxmox_node" {
|
||||
description = "which node is the vm associated"
|
||||
default = "clank-smolboks-0"
|
||||
}
|
||||
|
||||
variable "cloud_init_template" {
|
||||
description = "which cloud init template to be used"
|
||||
default = "debian12-cloudinit"
|
||||
}
|
||||
|
||||
variable "name" {
|
||||
description = "what is the name of the node"
|
||||
}
|
||||
|
||||
variable "domain" {
|
||||
description = "which domain is the host associated with"
|
||||
default = "nodes.kjuulh.io"
|
||||
}
|
||||
|
||||
variable "ip_address" {
|
||||
description = "which ip address should the the host assume (cidr)"
|
||||
}
|
||||
|
||||
variable "gateway" {
|
||||
description = "which ip address serves as the gateway for the host"
|
||||
default = "10.0.11.1"
|
||||
}
|
||||
|
||||
variable "ssh_pub" {
|
||||
default = "ssh public key"
|
||||
}
|
||||
|
||||
variable "ssh_private" {
|
||||
default = "ssh private key"
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "user_password" {
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "cpu" {
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "memory" {
|
||||
default = 512
|
||||
}
|
Loading…
Reference in New Issue
Block a user