Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added vm for truenas with terraform #66

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gryffindor/1000-truenas/terraform/iso.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "proxmox_virtual_environment_download_file" "latest_truenas_iso" {
content_type = "iso"
datastore_id = "local"
node_name = "gryffindor"
url = "https://download.sys.truenas.net/TrueNAS-SCALE-ElectricEel/24.10.2/TrueNAS-SCALE-24.10.2.iso"
checksum = "33e29ed62517bc5d4aed6c80b9134369e201bb143e13fefdec5dbf3820f4b946"
checksum_algorithm = "sha256"
}
21 changes: 21 additions & 0 deletions gryffindor/1000-truenas/terraform/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
required_version = "1.11.1"
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.73.1"
}
}
}

provider "proxmox" {
endpoint = var.endpoint
api_token = var.api_token
insecure = true

ssh {
agent = true
username = var.ssh_user
password = var.ssh_password
}
}
17 changes: 17 additions & 0 deletions gryffindor/1000-truenas/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "ssh_user" {
type = string
}

variable "ssh_password" {
type = string
sensitive = true
}

variable "endpoint" {
type = string
}

variable "api_token" {
type = string
sensitive = true
}
99 changes: 99 additions & 0 deletions gryffindor/1000-truenas/terraform/vm.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
locals {
datastore_id = "local-zfs"
}

resource "proxmox_virtual_environment_vm" "truenas_vm" {
name = "truenas"
description = "Managed by Terraform"
tags = ["terraform", "truenas"]

node_name = "gryffindor"
vm_id = 1000

keyboard_layout = "sv"

bios = "ovmf"
machine = "q35"
on_boot = true
boot_order = ["virtio0", "ide2", "net0"]

agent {
enabled = true
}

# This is added to prevent Terraform from killing the VM forcefully and risk
# data corruption.
stop_on_destroy = false
migrate = true

cpu {
cores = 6
type = "host"
units = 100
}

memory {
dedicated = 32768
}

cdrom {
file_id = proxmox_virtual_environment_download_file.latest_truenas_iso.id
interface = "ide2"
}

disk {
datastore_id = local.datastore_id
interface = "virtio0"
iothread = true
size = 50
file_format = "raw"
}

efi_disk {
datastore_id = local.datastore_id
type = "4m"
pre_enrolled_keys = false
}

initialization {
datastore_id = local.datastore_id

ip_config {
ipv4 {
address = "dhcp"
}
}
}

network_device {
bridge = "vmbr0"
}

operating_system {
type = "l26"
}

tpm_state {
datastore_id = local.datastore_id
version = "v2.0"
}

hostpci {
device = "hostpci0"
mapping = "HBA"
pcie = true
}

hostpci {
device = "hostpci1"
mapping = "NIC1"
pcie = true
}

hostpci {
device = "hostpci2"
mapping = "NIC2"
pcie = true
}
}

2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
pkgs ? import <nixpkgs> { config.allowUnfree=true; }
}:
pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [terraform ansible];
nativeBuildInputs = with pkgs.buildPackages; [terraform ansible packer];
}