Skip to content

Commit 9be07a9

Browse files
feat(terraform/proxmox-vm): create proxmox/vm terraform module (#13)
1 parent db55343 commit 9be07a9

File tree

13 files changed

+731
-4
lines changed

13 files changed

+731
-4
lines changed

home-lab/terraform/lxc.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ module "immich_lxc" {
142142
}
143143

144144
module "bitwarden_lxc" {
145-
source = "../../terraform-modules/proxmox/lxc"
145+
source = "../../terraform-modules/proxmox/lxc"
146146

147-
node_name = "proxmox"
147+
node_name = "proxmox"
148148

149149
lxc_hostname = "vaultwarden"
150150
# vm_id = 114
@@ -157,7 +157,7 @@ module "bitwarden_lxc" {
157157
lxc_memory = 1024
158158
# lxc_memory_swap = 512
159159

160-
lxc_password = var.default_password
160+
lxc_password = var.default_password
161161
ssh_public_keys = local.default_ssh_public_key
162162

163163
lxc_features_nesting = true

home-lab/terraform/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ terraform {
33
# https://github.com/bpg/terraform-provider-proxmox
44
proxmox = {
55
source = "bpg/proxmox"
6-
version = "0.86.0"
6+
version = "0.89.1"
77
}
88

99
# https://github.com/Telmate/terraform-provider-proxmox

home-lab/terraform/vm.tf

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
module "opnsense" {
2+
source = "../../terraform-modules/proxmox/vm"
3+
4+
proxmox_node = "proxmox"
5+
6+
vm_name = "opnsense"
7+
vm_description = "Managed by Terraform"
8+
9+
vm_cpu_type = "host"
10+
vm_cores = 2
11+
vm_sockets = 1
12+
13+
vm_memory = 4096
14+
15+
vm_scsihw = "virtio-scsi-single"
16+
17+
vm_display = {
18+
type = "serial0"
19+
}
20+
21+
vm_disks = [
22+
{
23+
backup = true
24+
datastore_id = "local"
25+
interface = "ide2"
26+
replicate = true
27+
size = 2
28+
},
29+
{
30+
aio = "io_uring"
31+
backup = true
32+
cache = "writeback"
33+
datastore_id = "nvme4tb"
34+
size = 30
35+
iothread = true
36+
replicate = true
37+
}
38+
]
39+
40+
vm_network_devices = [
41+
{
42+
bridge = "vmbr0"
43+
enable_firewall = false
44+
},
45+
{
46+
bridge = "vmbr1"
47+
enable_firewall = false
48+
}
49+
]
50+
51+
operating_system_type = "l26"
52+
vm_machine_type = "q35"
53+
54+
vm_tags = ["firewall"]
55+
}
56+
57+
58+
module "windows11" {
59+
source = "../../terraform-modules/proxmox/vm"
60+
61+
proxmox_node = "proxmox"
62+
63+
vm_name = "Win11"
64+
vm_description = "Managed by Terraform"
65+
66+
vm_cpu_flags = []
67+
# vm_cpu_units = 0
68+
vm_memory = 4096
69+
70+
vm_scsihw = "virtio-scsi-single"
71+
vm_enable_qemu_agent = true
72+
vm_bios_type = "ovmf" # UEFI
73+
74+
vm_display = {
75+
type = "std"
76+
}
77+
78+
vm_disks = [
79+
# CD/DVD ide0 virtio-win
80+
{
81+
backup = true
82+
datastore_id = "local"
83+
interface = "ide0"
84+
replicate = true
85+
# The size is around 0.7GB but the tf proxmox provider
86+
# (bpg/proxmox:v0.89.1) requires a minimum of 1GB
87+
# I have to manually update the tfstate
88+
size = 1
89+
},
90+
# CD/DVD ide2 Win11.iso
91+
{
92+
backup = true
93+
datastore_id = "local"
94+
interface = "ide2"
95+
replicate = true
96+
size = 7
97+
},
98+
# Hard disk scsi0
99+
{
100+
backup = true
101+
datastore_id = "local-lvm"
102+
interface = "scsi0"
103+
replicate = true
104+
size = 64
105+
iothread = true
106+
},
107+
]
108+
109+
vm_network_devices = [
110+
{
111+
bridge = "vmbr0"
112+
enable_firewall = true
113+
},
114+
]
115+
116+
operating_system_type = "win11"
117+
vm_machine_type = "pc-q35-10.0+pve1"
118+
119+
efi_disk = {
120+
datastore_id = "local-lvm"
121+
file_format = "raw"
122+
pre_enrolled_keys = true
123+
type = "4m"
124+
}
125+
126+
vm_tags = ["windows"]
127+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module "this" {
2+
source = "../../"
3+
4+
proxmox_node = "proxmox"
5+
6+
vm_name = "terraform-provider-proxmox-ubuntu-vm"
7+
vm_description = "Managed by Terraform"
8+
vm_tags = ["ubuntu"]
9+
10+
enable_network = false
11+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
variable "proxmox_api_url" {
2+
description = "Proxmox API URL"
3+
type = string
4+
default = "https://pve01.cloud.local:8006/api2/json"
5+
}
6+
7+
variable "proxmox_api_token_id" {
8+
description = "Proxmox API token ID"
9+
type = string
10+
sensitive = true
11+
}
12+
13+
variable "proxmox_api_token_secret" {
14+
description = "Proxmox API token secret"
15+
type = string
16+
sensitive = true
17+
}
18+
19+
variable "proxmox_tls_insecure" {
20+
description = "Skip TLS verification for Proxmox API"
21+
type = bool
22+
default = true
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
# https://github.com/bpg/terraform-provider-proxmox
6+
proxmox = {
7+
source = "bpg/proxmox"
8+
version = "0.89.1"
9+
}
10+
}
11+
}
12+
13+
provider "proxmox" {
14+
endpoint = "https://proxmox.internal.local:8006"
15+
insecure = var.proxmox_tls_insecure
16+
17+
api_token = "${var.proxmox_api_token_id}=${var.proxmox_api_token_secret}"
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module "this" {
2+
source = "../../"
3+
4+
proxmox_node = "proxmox"
5+
6+
vm_name = "terraform-ubuntu-clone"
7+
vm_description = "Managed by Terraform"
8+
vm_tags = ["ubuntu"]
9+
10+
clone_vm = true
11+
clone_vm_target = {
12+
vm_id = 901
13+
full = true
14+
}
15+
16+
vm_enable_qemu_agent = true
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Proxmox provider
2+
variable "proxmox_api_url" {
3+
description = "Proxmox API URL"
4+
type = string
5+
default = "https://pve01.cloud.local:8006/api2/json"
6+
}
7+
8+
variable "proxmox_api_token_id" {
9+
description = "Proxmox API token ID"
10+
type = string
11+
sensitive = true
12+
}
13+
14+
variable "proxmox_api_token_secret" {
15+
description = "Proxmox API token secret"
16+
type = string
17+
sensitive = true
18+
}
19+
20+
variable "proxmox_tls_insecure" {
21+
description = "Skip TLS verification for Proxmox API"
22+
type = bool
23+
default = true
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
# https://github.com/bpg/terraform-provider-proxmox
6+
proxmox = {
7+
source = "bpg/proxmox"
8+
version = "0.89.1"
9+
}
10+
}
11+
}
12+
13+
provider "proxmox" {
14+
endpoint = "https://proxmox.internal.local:8006"
15+
insecure = var.proxmox_tls_insecure
16+
17+
api_token = "${var.proxmox_api_token_id}=${var.proxmox_api_token_secret}"
18+
}

0 commit comments

Comments
 (0)