-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_machines.tf
More file actions
128 lines (108 loc) · 3.14 KB
/
virtual_machines.tf
File metadata and controls
128 lines (108 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Define common VM configuration as a local value
locals {
common_vm_config = {
description = "Managed by Terraform"
tags = ["terraform"]
cpu_type = "x86-64-v2-AES"
file_format = "raw"
interface = "virtio0"
os_type = "l26" # Linux Kernel 2.6 - 5.X.
agent_enabled = false # TODO: can't get qemu-guest-agent running in the VM.
stop_on_destroy = true # # if agent is not enabled, the VM may not be able to shutdown properly, and may need to be forced off
}
}
# First create control plane nodes
resource "proxmox_virtual_environment_vm" "control_planes" {
for_each = var.node_data.controlplanes
# Common attributes
name = each.value.hostname
description = local.common_vm_config.description
tags = local.common_vm_config.tags
node_name = each.value.pve_node
on_boot = each.value.start_on_boot
vm_id = each.value.pve_id
cpu {
cores = each.value.cores
type = local.common_vm_config.cpu_type
}
memory {
dedicated = each.value.memory
}
agent {
enabled = local.common_vm_config.agent_enabled
}
stop_on_destroy = local.common_vm_config.stop_on_destroy
network_device {
bridge = each.value.network_bridge
}
disk {
datastore_id = each.value.datastore_id
file_id = proxmox_virtual_environment_download_file.talos_image.id
file_format = local.common_vm_config.file_format
interface = local.common_vm_config.interface
size = each.value.disk_size
}
operating_system {
type = local.common_vm_config.os_type
}
initialization {
datastore_id = each.value.datastore_id
ip_config {
ipv4 {
address = "${each.key}/24"
gateway = var.default_gateway
}
ipv6 {
address = "dhcp"
}
}
}
}
# Then create worker nodes with a simple dependency
resource "proxmox_virtual_environment_vm" "workers" {
for_each = var.node_data.workers
depends_on = [proxmox_virtual_environment_vm.control_planes]
# Common attributes
name = each.value.hostname
description = local.common_vm_config.description
tags = local.common_vm_config.tags
node_name = each.value.pve_node
on_boot = each.value.start_on_boot
vm_id = each.value.pve_id
cpu {
cores = each.value.cores
type = local.common_vm_config.cpu_type
}
memory {
dedicated = each.value.memory
}
agent {
enabled = local.common_vm_config.agent_enabled
}
stop_on_destroy = local.common_vm_config.stop_on_destroy
network_device {
bridge = each.value.network_bridge
}
disk {
datastore_id = each.value.datastore_id
file_id = proxmox_virtual_environment_download_file.talos_image.id
file_format = local.common_vm_config.file_format
interface = local.common_vm_config.interface
size = each.value.disk_size
}
operating_system {
type = local.common_vm_config.os_type
}
initialization {
datastore_id = each.value.datastore_id
ip_config {
ipv4 {
address = "${each.key}/24"
gateway = var.default_gateway
}
ipv6 {
address = "dhcp"
}
}
}
}