-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathwindows.pkr.hcl
122 lines (109 loc) · 3.02 KB
/
windows.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
121
122
packer {
required_version = ">= 1.7.0"
required_plugins {
qemu = {
version = "~> 1.0"
source = "github.com/hashicorp/qemu"
}
}
}
variable "headless" {
type = bool
default = false
description = "Whether VNC viewer should not be launched."
}
variable "disk_size" {
type = string
default = "32G"
}
variable "iso_path" {
type = string
default = ""
}
variable "ovmf_suffix" {
type = string
default = "_4M"
}
variable "filename" {
type = string
default = "windows.dd.gz"
description = "The filename of the tarball to produce"
}
variable "is_vhdx" {
type = bool
default = false
description = "Whether we are building using a VHDX disk."
}
variable "use_tpm" {
type = string
default = ""
description = "Whether we are building using a virtual tpm device."
}
variable "timeout" {
type = string
default = "1h"
}
locals {
baseargs = [
["-cpu", "host"],
["-serial", "stdio"],
["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=/usr/share/OVMF/OVMF_CODE${var.ovmf_suffix}.ms.fd"],
["-drive", "if=pflash,format=raw,id=ovmf_vars,file=OVMF_VARS.fd"],
["-drive", "file=output-windows_builder/packer-windows_builder,format=raw"],
["-cdrom", "${var.iso_path}"],
["-drive", "file=drivers.iso,media=cdrom,index=3"],
["-boot", "d"]
]
tpmargs = [
["-chardev", "socket,id=chrtpm,path=/tmp/swtpm/swtpm-sock"],
["-tpmdev", "emulator,id=tpm0,chardev=chrtpm"],
["-device", "tpm-tis,tpmdev=tpm0"]
]
}
source "qemu" "windows_builder" {
accelerator = "kvm"
boot_command = ["<return>"]
boot_wait = "2s"
communicator = "none"
disk_interface = "sata"
disk_image = "${var.is_vhdx}"
disk_size = "${var.disk_size}"
floppy_files = ["./http/Autounattend.xml", "./http/logon.ps1", "./http/rh.cer"]
floppy_label = "flop"
format = "raw"
headless = "${var.headless}"
http_directory = "http"
iso_checksum = "none"
iso_url = "${var.iso_path}"
machine_type = "q35"
memory = "4096"
cpus = "2"
net_device = "e1000"
qemuargs = concat(local.baseargs, (var.use_tpm == "yes" ? local.tpmargs : []))
shutdown_timeout = "${var.timeout}"
vnc_bind_address = "0.0.0.0"
}
build {
sources = ["source.qemu.windows_builder"]
post-processor "shell-local" {
inline = [
"echo 'Syncing output-windows_builder/packer-windows_builder...'",
"sync -f output-windows_builder/packer-windows_builder",
"IMG_FMT=raw",
"source scripts/setup-nbd",
"TMP_DIR=$(mktemp -d /tmp/packer-maas-XXXX)",
"echo 'Adding curtin-hooks to image...'",
"mount -t ntfs $${nbd}p4 $TMP_DIR",
"mkdir -p $TMP_DIR/curtin",
"cp ./curtin/* $TMP_DIR/curtin/",
"sync -f $TMP_DIR/curtin",
"umount $TMP_DIR",
"qemu-nbd -d $nbd",
"rmdir $TMP_DIR"
]
inline_shebang = "/bin/bash -e"
}
post-processor "compress" {
output = "${var.filename}"
}
}