Skip to content

Commit de728c4

Browse files
Added vm for truenas with terraform (#66)
1 parent 95fb27d commit de728c4

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "proxmox_virtual_environment_download_file" "latest_truenas_iso" {
2+
content_type = "iso"
3+
datastore_id = "local"
4+
node_name = "gryffindor"
5+
url = "https://download.sys.truenas.net/TrueNAS-SCALE-ElectricEel/24.10.2/TrueNAS-SCALE-24.10.2.iso"
6+
checksum = "33e29ed62517bc5d4aed6c80b9134369e201bb143e13fefdec5dbf3820f4b946"
7+
checksum_algorithm = "sha256"
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
terraform {
2+
required_version = "1.11.1"
3+
required_providers {
4+
proxmox = {
5+
source = "bpg/proxmox"
6+
version = "0.73.1"
7+
}
8+
}
9+
}
10+
11+
provider "proxmox" {
12+
endpoint = var.endpoint
13+
api_token = var.api_token
14+
insecure = true
15+
16+
ssh {
17+
agent = true
18+
username = var.ssh_user
19+
password = var.ssh_password
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "ssh_user" {
2+
type = string
3+
}
4+
5+
variable "ssh_password" {
6+
type = string
7+
sensitive = true
8+
}
9+
10+
variable "endpoint" {
11+
type = string
12+
}
13+
14+
variable "api_token" {
15+
type = string
16+
sensitive = true
17+
}
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
locals {
2+
datastore_id = "local-zfs"
3+
}
4+
5+
resource "proxmox_virtual_environment_vm" "truenas_vm" {
6+
name = "truenas"
7+
description = "Managed by Terraform"
8+
tags = ["terraform", "truenas"]
9+
10+
node_name = "gryffindor"
11+
vm_id = 1000
12+
13+
keyboard_layout = "sv"
14+
15+
bios = "ovmf"
16+
machine = "q35"
17+
on_boot = true
18+
boot_order = ["virtio0", "ide2", "net0"]
19+
20+
agent {
21+
enabled = true
22+
}
23+
24+
# This is added to prevent Terraform from killing the VM forcefully and risk
25+
# data corruption.
26+
stop_on_destroy = false
27+
migrate = true
28+
29+
cpu {
30+
cores = 6
31+
type = "host"
32+
units = 100
33+
}
34+
35+
memory {
36+
dedicated = 32768
37+
}
38+
39+
cdrom {
40+
file_id = proxmox_virtual_environment_download_file.latest_truenas_iso.id
41+
interface = "ide2"
42+
}
43+
44+
disk {
45+
datastore_id = local.datastore_id
46+
interface = "virtio0"
47+
iothread = true
48+
size = 50
49+
file_format = "raw"
50+
}
51+
52+
efi_disk {
53+
datastore_id = local.datastore_id
54+
type = "4m"
55+
pre_enrolled_keys = false
56+
}
57+
58+
initialization {
59+
datastore_id = local.datastore_id
60+
61+
ip_config {
62+
ipv4 {
63+
address = "dhcp"
64+
}
65+
}
66+
}
67+
68+
network_device {
69+
bridge = "vmbr0"
70+
}
71+
72+
operating_system {
73+
type = "l26"
74+
}
75+
76+
tpm_state {
77+
datastore_id = local.datastore_id
78+
version = "v2.0"
79+
}
80+
81+
hostpci {
82+
device = "hostpci0"
83+
mapping = "HBA"
84+
pcie = true
85+
}
86+
87+
hostpci {
88+
device = "hostpci1"
89+
mapping = "NIC1"
90+
pcie = true
91+
}
92+
93+
hostpci {
94+
device = "hostpci2"
95+
mapping = "NIC2"
96+
pcie = true
97+
}
98+
}
99+

shell.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
pkgs ? import <nixpkgs> { config.allowUnfree=true; }
33
}:
44
pkgs.mkShell {
5-
nativeBuildInputs = with pkgs.buildPackages; [terraform ansible];
5+
nativeBuildInputs = with pkgs.buildPackages; [terraform ansible packer];
66
}

0 commit comments

Comments
 (0)