-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.pkr.hcl
106 lines (91 loc) · 2.74 KB
/
main.pkr.hcl
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
packer {
required_plugins {
proxmox = {
source = "github.com/hashicorp/proxmox"
version = "1.1.8"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = "1.1.1"
}
}
}
source "proxmox-clone" "template" {
insecure_skip_tls_verify = true
proxmox_url = var.proxmox_url
username = var.proxmox_username
token = var.proxmox_token
node = var.proxmox_node
clone_vm = var.clone_vm
template_description = "Built with Packer on ${timestamp()}"
cpu_type = "kvm64"
cores = 2
sockets = 1
memory = 2048
os = "l26"
scsi_controller = "virtio-scsi-pci"
ssh_username = "ubuntu"
network_adapters {
model = "virtio"
bridge = "vmbr1"
vlan_tag = 13
}
vga {
memory = 0
type = "serial0"
}
}
build {
name = "infra"
source "proxmox-clone.template" {
name = "base"
template_name = "${var.template_name}-${source.name}"
vm_id = var.vm_id_base
}
source "proxmox-clone.template" {
name = "k8s"
template_name = "${var.template_name}-${source.name}"
vm_id = var.vm_id_k8s
}
provisioner "shell" {
inline = ["while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 1; done"]
}
provisioner "ansible" {
user = "ubuntu"
playbook_file = "../ansible/packer_provisioner.yml"
extra_arguments = ["-t ${source.name}"]
ansible_env_vars = ["ANSIBLE_CONFIG=../ansible/ansible.cfg"]
use_proxy = false
}
provisioner "shell" {
execute_command = "sudo -S sh -c '{{ .Vars }} {{ .Path }}'"
scripts = [
"scripts/packer-virt-sysprep/sysprep-op-cloud-init.sh",
"scripts/packer-virt-sysprep/sysprep-op-logfiles.sh",
"scripts/packer-virt-sysprep/sysprep-op-machine-id.sh",
"scripts/packer-virt-sysprep/sysprep-op-tmp-files.sh"
]
}
post-processor "shell-local" {
inline = [<<EOT
curl --silent --insecure \
${var.proxmox_url}/nodes/${var.proxmox_node}/qemu/${var.vm_id_base}/migrate \
--header "Authorization: PVEAPIToken=${var.proxmox_username}=${var.proxmox_token}" \
--data-urlencode target="spsrv" \
--data-urlencode targetstorage="spsrv-proxmox"
EOT
]
only = ["proxmox-clone.base"]
}
post-processor "shell-local" {
inline = [<<EOT
curl --silent --insecure \
${var.proxmox_url}/nodes/${var.proxmox_node}/qemu/${var.vm_id_k8s}/migrate \
--header "Authorization: PVEAPIToken=${var.proxmox_username}=${var.proxmox_token}" \
--data-urlencode target="spsrv" \
--data-urlencode targetstorage="spsrv-proxmox"
EOT
]
only = ["proxmox-clone.k8s"]
}
}