forked from fediversity/fediversity
188 lines
5.5 KiB
HCL
188 lines
5.5 KiB
HCL
terraform {
|
|
required_providers {
|
|
proxmox = {
|
|
source = "bpg/proxmox"
|
|
version = "= 0.81.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
locals {
|
|
# dump_name = "vzdump-qemu-nixos-fediversity-${var.category}.vma.zst"
|
|
dump_name = "vzdump-qemu-nixos-fediversity-${var.category}.raw"
|
|
# dump_name = "vzdump-qemu-nixos-fediversity-${var.category}.qcow2"
|
|
}
|
|
|
|
# https://registry.terraform.io/providers/bpg/proxmox/latest/docs
|
|
provider "proxmox" {
|
|
endpoint = "https://${var.host}:8006/"
|
|
insecure = true
|
|
|
|
ssh {
|
|
agent = true
|
|
# uncomment and configure if using api_token instead of password
|
|
username = "root"
|
|
# node {
|
|
# name = "${var.node_name}"
|
|
# address = "${var.host}"
|
|
# # port = 22
|
|
# }
|
|
}
|
|
|
|
# # Choose one authentication method:
|
|
# api_token = var.virtual_environment_api_token
|
|
# # OR
|
|
username = var.proxmox_user
|
|
password = var.proxmox_password
|
|
# # OR
|
|
# auth_ticket = var.virtual_environment_auth_ticket
|
|
# csrf_prevention_token = var.virtual_environment_csrf_prevention_token
|
|
}
|
|
|
|
# # FIXME move to host
|
|
# # FIXME add proxmox
|
|
# data "external" "base-hash" {
|
|
# program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ${path.module}/../common/nixos/base.nix)\\\"}\""]
|
|
# }
|
|
|
|
# # hash of our code directory, used to trigger re-deploy
|
|
# # FIXME calculate separately to reduce false positives
|
|
# data "external" "hash" {
|
|
# program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ..)\\\"}\""]
|
|
# }
|
|
|
|
# FIXME move to host
|
|
# FIXME switch to base image shared between jobs as upload seems a bottleneck? e.g. by:
|
|
# - recursive TF
|
|
# - hash in name over overwrite
|
|
resource "proxmox_virtual_environment_file" "upload" {
|
|
# # https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts
|
|
# timeouts {
|
|
# create = "60m"
|
|
# }
|
|
|
|
# content_type - (Optional) The content type. If not specified, the content type will be inferred from the file extension. Valid values are:
|
|
# backup (allowed extensions: .vzdump, .tar.gz, .tar.xz, tar.zst)
|
|
# iso (allowed extensions: .iso, .img)
|
|
# snippets (allowed extensions: any)
|
|
# import (allowed extensions: .raw, .qcow2, .vmdk)
|
|
# vztmpl (allowed extensions: .tar.gz, .tar.xz, tar.zst)
|
|
# content_type = "backup"
|
|
content_type = "import"
|
|
# https://192.168.51.81:8006/#v1:0:=storage%2Fnode051%2Flocal:4::=contentIso:::::
|
|
# PVE -> Datacenter -> Storage -> local -> Edit -> General -> Content -> check Import + Disk Images -> OK
|
|
# that UI action also adds it in `/etc/pve/storage.cfg`
|
|
datastore_id = "local"
|
|
# datastore_id = "local-lvm"
|
|
# datastore_id = "backup"
|
|
node_name = var.node_name
|
|
overwrite = true
|
|
# timeout_upload = 3600
|
|
timeout_upload = 1
|
|
|
|
source_file {
|
|
# path = "/tmp/proxmox-image/${local.dump_name}"
|
|
path = var.image
|
|
file_name = local.dump_name
|
|
}
|
|
}
|
|
|
|
# resource "proxmox_virtual_environment_download_file" "latest_ubuntu_22_jammy_qcow2_img" {
|
|
# content_type = "import"
|
|
# datastore_id = "local"
|
|
# node_name = var.node_name
|
|
# url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
|
|
# # need to rename the file to *.qcow2 to indicate the actual file format for import
|
|
# file_name = "jammy-server-cloudimg-amd64.qcow2"
|
|
# }
|
|
|
|
resource "proxmox_virtual_environment_vm" "nix_vm" {
|
|
# lifecycle {
|
|
# replace_triggered_by = [
|
|
# proxmox_virtual_environment_file.upload,
|
|
# ]
|
|
# }
|
|
|
|
node_name = var.node_name
|
|
pool_id = var.pool_id
|
|
description = var.description
|
|
started = true
|
|
|
|
# # https://wiki.nixos.org/wiki/Virt-manager#Guest_Agent
|
|
# # services.qemuGuest.enable = true;
|
|
# # QEMU guest agent is not running
|
|
# agent {
|
|
# enabled = true
|
|
# # timeout = "15m"
|
|
# }
|
|
|
|
cpu {
|
|
type = "x86-64-v2-AES"
|
|
cores = var.cores
|
|
sockets = var.sockets
|
|
numa = true
|
|
}
|
|
|
|
memory {
|
|
dedicated = var.memory
|
|
}
|
|
|
|
disk {
|
|
# datastore_id = "linstor_storage"
|
|
datastore_id = "local"
|
|
file_format = "raw"
|
|
interface = "scsi0"
|
|
discard = "on"
|
|
iothread = true
|
|
size = var.disk_size
|
|
ssd = true
|
|
backup = false
|
|
cache = "none"
|
|
|
|
# BdsDxe: failed to load Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x5,0x0)/Pci(0x1,0x0)/Scsi(0x0,0x0): Not Found
|
|
# BdsDxe: No bootable option or device was found.
|
|
# BdsDxe: Press any key to enter the Boot Manager Menu.
|
|
# import_from = "local:import/vzdump-qemu-nixos-fediversity-test.qcow2"
|
|
# import_from = "local:import/vzdump-qemu-nixos-fediversity-test.raw"
|
|
import_from = proxmox_virtual_environment_file.upload.id
|
|
# import_from = proxmox_virtual_environment_download_file.latest_ubuntu_22_jammy_qcow2_img.id
|
|
}
|
|
|
|
efi_disk {
|
|
# datastore_id = "linstor_storage"
|
|
datastore_id = "local"
|
|
file_format = "raw"
|
|
type = "4m"
|
|
}
|
|
|
|
network_device {
|
|
model = "virtio"
|
|
bridge = "vnet1306"
|
|
}
|
|
|
|
operating_system {
|
|
type = "l26"
|
|
}
|
|
|
|
scsi_hardware = "virtio-scsi-single"
|
|
bios = "ovmf"
|
|
}
|
|
|
|
# module "nixos-rebuild" {
|
|
# depends_on = [
|
|
# proxmox_virtual_environment_vm.nix_vm
|
|
# ]
|
|
|
|
# source = "../tf-single-host"
|
|
|
|
# system = var.system
|
|
# username = var.ssh_user
|
|
# host = proxmox_virtual_environment_vm.nix_vm.ipv4_addresses[0] # needs guest agent installed
|
|
# module = var.module
|
|
# args = var.args
|
|
# key_file = var.key_file
|
|
# deployment_name = var.deployment_name
|
|
# root_path = var.root_path
|
|
# ssh_opts = var.ssh_opts
|
|
# deployment_type = var.deployment_type
|
|
# }
|