commit 920835d6622dce102e59bdda63cc658fc5c05bda Author: kjuulh Date: Fri Nov 29 23:51:35 2024 +0100 feat: add module Signed-off-by: kjuulh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..b891f02 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,2 @@ +kind: template +load: cuddle-empty-plan.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f25a228 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.cuddle/ +*.tfvars +.terraform/ +.terraform.lock.hcl +.env +*.secret.txt +**/id_rsa* diff --git a/cuddle.yaml b/cuddle.yaml new file mode 100644 index 0000000..2017821 --- /dev/null +++ b/cuddle.yaml @@ -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 + diff --git a/node.tf b/node.tf new file mode 100644 index 0000000..72963ec --- /dev/null +++ b/node.tf @@ -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 + ] + } +} diff --git a/provider.tf b/provider.tf new file mode 100644 index 0000000..d74a32e --- /dev/null +++ b/provider.tf @@ -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 +} + diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..7190a60 --- /dev/null +++ b/renovate.json @@ -0,0 +1,3 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json" +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..3ce0669 --- /dev/null +++ b/variables.tf @@ -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. @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 +}