-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows2022.pkr.hcl
More file actions
107 lines (92 loc) · 2.85 KB
/
windows2022.pkr.hcl
File metadata and controls
107 lines (92 loc) · 2.85 KB
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
# Packer template for Windows Server 2022 on VirtualBox with WinRM (HTTP/HTTPS) and RDP
packer {
required_plugins {
virtualbox = {
version = ">= 1.0.4"
source = "github.com/hashicorp/virtualbox"
}
vagrant = {
source = "github.com/hashicorp/vagrant"
version = "~> 1"
}
}
}
variable "iso_url" {
type = string
default = "https://software-static.download.prss.microsoft.com/sg/download/888969d5-f34g-4e03-ac9d-1f9786c66749/SERVER_EVAL_x64FRE_en-us.iso"
# default = "images/windows-srv-2022.iso"
}
variable "iso_checksum" {
type = string
default = "sha256:3e4fa6d8507b554856fc9ca6079cc402df11a8b79344871669f0251535255325"
description = "SHA256 checksum of the ISO"
}
variable "vm_name" {
type = string
default = "windows-server-2022"
}
source "virtualbox-iso" "windows2022" {
iso_url = var.iso_url
iso_checksum = var.iso_checksum
guest_os_type = "Windows2022_64"
communicator = "winrm"
winrm_username = "vagrant"
winrm_password = "vagrant"
winrm_timeout = "6h"
winrm_insecure = true
winrm_use_ssl = false
winrm_port = 5985
shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\""
guest_additions_mode = "attach"
headless = false
vm_name = var.vm_name
disk_size = 61440
memory = 4096
cpus = 2
boot_wait = "3s"
# Secondary ISO with Autounattend.xml attached as CD (more reliable than floppy in VirtualBox)
cd_files = [
"Autounattend.xml"
]
# Serve scripts via HTTP instead of CD/floppy
http_directory = "scripts"
http_port_min = 8100
http_port_max = 8100
# VirtualBox settings for minimal network configuration
vboxmanage = [
["modifyvm", "{{.Name}}", "--natpf1", "winrm,tcp,,5985,,5985"],
["modifyvm", "{{.Name}}", "--natpf1", "winrm-ssl,tcp,,5986,,5986"],
["modifyvm", "{{.Name}}", "--natpf1", "rdp,tcp,,3389,,3389"],
["modifyvm", "{{.Name}}", "--boot1", "dvd"],
["modifyvm", "{{.Name}}", "--boot2", "disk"]
]
}
build {
sources = ["source.virtualbox-iso.windows2022"]
# WinRM already enabled by Autounattend.xml, so skip the redundant call
# Enable RDP
provisioner "powershell" {
script = "scripts/enable-rdp.ps1"
}
# Install VirtualBox Guest Additions
provisioner "powershell" {
script = "scripts/install-guest-additions.ps1"
}
# Setup for Ansible
provisioner "powershell" {
script = "scripts/setup-ansible.ps1"
}
# Restart to apply changes
provisioner "windows-restart" {
restart_timeout = "5m"
}
# Final cleanup
provisioner "powershell" {
script = "scripts/cleanup.ps1"
}
# Create Vagrant box
post-processor "vagrant" {
compression_level = 9
output = "builds/windows-server-2022.box"
}
}