Skip to content

Commit 9b285ce

Browse files
author
Matt Cuneo
authoredDec 16, 2021
Update vm.tf.template
1 parent 68c4f81 commit 9b285ce

File tree

1 file changed

+17
-35
lines changed

1 file changed

+17
-35
lines changed
 

‎terraform/vm.tf.template

+17-35
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
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-
171
resource "proxmox_vm_qemu" "~name~" {
182
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~"
207
target_node = var.pm_target_node
21-
vmid = "~prefix~${count.index}"
8+
vmid = "1~prefix~${count.index}"
229
clone = var.pm_clone_name
2310

2411
cores = ~cores~
@@ -28,23 +15,23 @@ resource "proxmox_vm_qemu" "~name~" {
2815

2916
agent = 1
3017
cpu = "kvm64"
31-
hotplug = "network,disk,usb,cpu,memory"
32-
18+
hotplug = "network,disk,usb,cpu"
19+
3320
network {
3421
bridge = "vmbr0"
3522
model = "virtio"
3623
}
37-
24+
3825
ipconfig0 = "ip=10.0.0.1~prefix~${count.index}/24,gw=10.0.0.1"
39-
26+
4027
disk {
4128
type = "virtio"
42-
storage = ~storage~
43-
size = ~size~
29+
storage = "~storage~"
30+
size = "~size~"
4431
}
4532

4633
os_type = "cloud-init"
47-
34+
4835
#creates ssh connection to check when the CT is ready for ansible provisioning
4936
connection {
5037
host = "10.0.0.1~prefix~${count.index}"
@@ -55,23 +42,18 @@ resource "proxmox_vm_qemu" "~name~" {
5542
}
5643

5744
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
5946
inline = [ "echo 'Ready for provisioning'"]
6047
}
61-
48+
6249
provisioner "local-exec" {
6350
working_dir = "../ansible/"
6451
command = "ansible-playbook -u ${var.user} --key-file ${var.ssh_key_private} -i 10.0.0.1~prefix~${count.index}, provision.yaml"
6552
}
66-
67-
53+
54+
6855
provisioner "local-exec" {
6956
working_dir = "../ansible/"
7057
command = "ansible-playbook -u ${var.user} --key-file ${var.ssh_key_private} -i 10.0.0.1~prefix~${count.index}, ~name~.yaml"
7158
}
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

Comments
 (0)
Failed to load comments.