-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.pkr.hcl
120 lines (105 loc) · 2.78 KB
/
build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
variable "cluster" {
type = string
default = "${var.VSPHERE_CLUSTER}"
}
variable "datacenter" {
type = string
default = "${var.VSPHERE_DATACENTER}"
}
variable "datastore" {
type = string
default = "${var.VSPHERE_DATASTORE}"
}
variable "folder" {
type = string
default = "${var.VSPHERE_FOLDER}"
}
variable "iso_path" {
type = string
default = "${var.VSPHERE_ISO_PATH}"
}
variable "packer_bastion_host" {
type = string
default = "${var.PACKER_BASTION_HOST}"
}
variable "packer_bastion_key" {
type = string
default = "${var.PACKER_BASTION_KEY}"
}
variable "password" {
type = string
default = "${var.VSPHERE_PASSWORD}"
}
variable "template_name" {
type = string
default = "${var.VSPHERE_TEMPLATE_NAME}"
}
variable "template_network" {
type = string
default = "${var.VSPHERE_NETWORK}"
}
variable "vcenter_server" {
type = string
default = "${var.VSPHERE_SERVER}"
}
variable "vcenter_username" {
type = string
default = "${var.VSPHERE_USERNAME}"
}
# "timestamp" template function replacement
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
source "vsphere-iso" "vmware-builder" {
CPUs = 4
RAM = 4096
RAM_reserve_all = true
boot_command = ["<enter><enter><f6><esc><wait> ", "ipv6.disable=1 autoinstall ds=nocloud", "<enter><wait>"]
boot_order = "disk,cdrom"
cluster = "${var.cluster}"
boot_wait = "5s"
convert_to_template = true
datacenter = "${var.datacenter}"
datastore = "${var.datastore}"
disk_controller_type = "pvscsi"
floppy_files = ["./user-data", "./meta-data"]
floppy_label = "cidata"
folder = "${var.folder}"
guest_os_type = "ubuntu64Guest"
insecure_connection = true
ip_settle_timeout = "5s"
ip_wait_timeout = "15m"
iso_paths = "[${var.datastore}] ${var.iso_path}"
network_adapters {
network = "${var.template_network}"
network_card = "vmxnet3"
}
password = "${var.password}"
ssh_handshake_attempts = 20
ssh_password = "ubuntu"
ssh_timeout = "20m"
ssh_username = "ubuntu"
storage {
disk_size = 40000
disk_thin_provisioned = true
}
username = "${var.vcenter_username}"
vcenter_server = "${var.vcenter_server}"
vm_name = "${var.template_name}"
}
build {
sources = ["source.vsphere-iso.vmware-builder"]
provisioner "ansible" {
extra_arguments = ["-b"]
playbook_file = "./playbooks/standard.yml"
user = "ubuntu"
}
provisioner "shell" {
script = "./scripts/cleanup.sh"
override = {
vmware-builder = {
execute_command = "sudo bash {{.Path}}"
}
}
}
}