1
- /**
2
- * Template will define how many VMs to create, their names and IDs, cores and memory, boot storage, IP address, and run ansible playbook
3
- * Additional settings can be added/modified
4
- *
5
- * placeholders:
6
- * -------------
7
- * [~name~]: Name of the resource, also name of ansible playbook
8
- * [~count~]: Number of resources to create (1-9)
9
- * [~prefix~]: Prefix for the resource (0-9)
10
- * [~cores~]: Number of cores
11
- * [~memory~]: Amount of memory
12
- * [~storage~]: Storage to use
13
- * [~size~]: Size of storage
14
- *
15
- **/
16
-
17
1
resource "proxmox_vm_qemu" "~name~" {
18
2
count = ~count~
19
- name = ~count~ > 1 ? "~name~-${count.index + 1}" : ~name~
3
+ locals {
4
+ id = "1~prefix~${count.index}"
5
+ }
6
+ name = ~count~ > 1 ? "~name~-${count.index + 1}" : "~name~"
20
7
target_node = var.pm_target_node
21
- vmid = "~prefix~${count.index}"
8
+ vmid = "1 ~prefix~${count.index}"
22
9
clone = var.pm_clone_name
23
10
24
11
cores = ~cores~
@@ -28,23 +15,23 @@ resource "proxmox_vm_qemu" "~name~" {
28
15
29
16
agent = 1
30
17
cpu = "kvm64"
31
- hotplug = "network,disk,usb,cpu,memory "
32
-
18
+ hotplug = "network,disk,usb,cpu"
19
+
33
20
network {
34
21
bridge = "vmbr0"
35
22
model = "virtio"
36
23
}
37
-
24
+
38
25
ipconfig0 = "ip=10.0.0.1~prefix~${count.index}/24,gw=10.0.0.1"
39
-
26
+
40
27
disk {
41
28
type = "virtio"
42
- storage = ~storage~
43
- size = ~size~
29
+ storage = " ~storage~"
30
+ size = " ~size~"
44
31
}
45
32
46
33
os_type = "cloud-init"
47
-
34
+
48
35
#creates ssh connection to check when the CT is ready for ansible provisioning
49
36
connection {
50
37
host = "10.0.0.1~prefix~${count.index}"
@@ -55,23 +42,18 @@ resource "proxmox_vm_qemu" "~name~" {
55
42
}
56
43
57
44
provisioner "remote-exec" {
58
- # Leave this here so we know when to start with Ansible local-exec
45
+ # Leave this here so we know when to start with Ansible local-exec
59
46
inline = [ "echo 'Ready for provisioning'"]
60
47
}
61
-
48
+
62
49
provisioner "local-exec" {
63
50
working_dir = "../ansible/"
64
51
command = "ansible-playbook -u ${var.user} --key-file ${var.ssh_key_private} -i 10.0.0.1~prefix~${count.index}, provision.yaml"
65
52
}
66
-
67
-
53
+
54
+
68
55
provisioner "local-exec" {
69
56
working_dir = "../ansible/"
70
57
command = "ansible-playbook -u ${var.user} --key-file ${var.ssh_key_private} -i 10.0.0.1~prefix~${count.index}, ~name~.yaml"
71
58
}
72
-
73
- provisioner "local-exec" {
74
- working_dir = "../ansible/"
75
- command = "ansible-playbook -u ${var.user} --key-file ${var.ssh_key_private} -i 10.0.0.1~prefix~${count.index}, install-qemu-guest-agent.yaml"
76
- }
77
- }
59
+ }
0 commit comments