-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindows10-Ent-Build.pkr.hcl
243 lines (211 loc) · 7.2 KB
/
Windows10-Ent-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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
packer {
required_plugins {
windows-update = {
version = "0.14.1"
source = "github.com/rgl/windows-update"
}
}
}
variable "iso_url" {
type = string
}
variable "iso_checksum" {
type = string
}
variable "vm_name" {
type = string
}
variable "guest_os_type" {
type = string
}
variable "autounattend" {
type = string
default = "./Answers/10/autounattend.xml"
}
variable "output_directory" {
type = string
}
variable "winrm_username" {
type = string
}
variable "winrm_password" {
type = string
sensitive = true
}
source "vmware-iso" "win10-iso" {
# ISO vars
iso_checksum = "${var.iso_checksum}"
iso_url = "${var.iso_url}"
# WinRM connection information
communicator = "winrm"
winrm_username = "${var.winrm_username}"
winrm_password = "${var.winrm_password}"
winrm_timeout = "3h"
vmx_data = {
"ehci.present" : "TRUE",
"firmware" : "efi",
"hpet0.present" : "TRUE",
"ich7m.present" : "TRUE",
"smc.present" : "TRUE"
}
# Machine information
vm_name = var.vm_name
cpus = "2"
cores = "2"
memory = "6192"
disk_size = "61440"
disk_adapter_type = "lsisas1068"
guest_os_type = "${var.guest_os_type}"
headless = true
usb = true
# Mount files
cd_files = [
"${var.autounattend}", # NOTE The autounattend file must be specified
"./Scripts/Set-NetworkTypeToPrivate.ps1",
"./Scripts/Set-WinRMSettings.ps1"
]
cd_label = "cidata"
# Other
skip_compaction = false
boot_wait = "3s" # NOTE This needs to be set as Windows takes longer to finish initialization
boot_command = [
"<enter><enter>"
]
output_directory = "${var.output_directory}/${var.vm_name}"
shutdown_timeout = "30m"
shutdown_command = "C:\\Windows\\Temp\\Packer-Shutdown.cmd"
# shutdown_command = "shutdown /s /t 10 /f /d p:4:1"
}
# Unpack and Provision Image
build {
name = "gold"
source "sources.vmware-iso.win10-iso" {
}
provisioner "file" {
source = "Resources\\Images\\wallpapers"
destination = "C:\\windows\\web\\wallpaper\\Better-Images"
}
provisioner "file" {
source = "Resources\\Images\\users"
destination = "C:\\windows\\web\\wallpaper\\Better-Images"
}
provisioner "file" {
source = "Resources\\DoD_Root_Certificates.p7b"
destination = "C:\\windows\\Temp\\DoD_Root_Certificates.p7b"
}
provisioner "powershell" {
inline = [
"Write-Host 'INFO: Setting default user account image...'",
"New-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer' -Name 'UseDefaultTile' -PropertyType DWORD -Value '1' | Out-Null",
"",
"Write-Host 'INFO: Disabling Internet Explorer and Cortana...'",
"Disable-WindowsOptionalFeature -FeatureName Internet-Explorer-Optional-amd64 -Online -NoRestart | Out-Null",
"New-Item -Path 'HKLM:\\SOFTWARE\\Policies\\Microsoft\\Windows\\' -Name 'Windows Search' | Out-Null",
"New-ItemProperty -Path 'HKLM:\\SOFTWARE\\Policies\\Microsoft\\Windows\\Windows Search' -Name 'AllowCortana' -PropertyType DWORD -Value '0' | Out-Null",
"",
"Write-Host 'INFO: Turning off weather and news on taskbar...'",
"Stop-Process -Name 'explorer' -Force",
"Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Feeds' -Name 'ShellFeedsTaskbarViewMode' -Value '2'",
"Start-Process 'explorer'",
"",
"Write-Host 'INFO: Turning off hibernation feature...'",
"powercfg -h off"
]
}
# Grab required modules
provisioner "powershell" {
inline = [
"Write-Host 'INFO: Installing required packages...'",
"",
"Write-Host 'INFO: Installing NuGet Package...'",
"Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null", # Grab NuGet provider to interact with NuGet-based repositories
"",
"Write-Host 'INFO: Installing PSDscResources...'",
"Install-Module PSDscResources -Force",
"",
"Write-Host 'INFO: Installing VMWare Power CLI...'",
"Install-Module -Name VMWare.PowerCLI -SkipPublisherCheck -Force",
"",
"Write-Host 'INFO: Installing PowerStig...'",
"Install-Module PowerStig -SkipPublisherCheck -Force"
]
}
# Import DoD_Root_Certificates
provisioner "powershell" {
inline = [
"Write-Host 'INFO: Installing DoD Root Certificates...'",
"Import-Certificate -FilePath \"$env:Windir/Temp/DoD_Root_Certificates.p7b\" -CertStoreLocation Cert:/LocalMachine/Root"
]
}
# Run scripts
provisioner "powershell" {
scripts = [
"./Scripts/Set-Wallpaper.ps1",
"./Scripts/Set-UserImage.ps1",
"./Scripts/Debloat-Windows.ps1",
"./Scripts/Uninstall-OneDrive.ps1",
"./Scripts/Set-TLSSecureConfig.ps1",
"./Scripts/Enable-RemoteDesktop.ps1",
"./Scripts/DSC/LocalDSCConfig.ps1",
"./Scripts/DSC/DotNetFrameworkConfiguration.ps1",
"./Scripts/DSC/MicrosoftEdgeConfiguration.ps1",
"./Scripts/DSC/WindowsDefenderConfiguration.ps1",
"./Scripts/DSC/WindowsFirewallConfiguration.ps1",
"./Scripts/DSC/WindowsClientConfiguration.ps1"
]
}
# Install VMwareTools
provisioner "powershell" {
only = ["vmware-vmx.win10-vmx"]
scripts = [
"./Scripts/Install-VMwareTools.ps1"
]
}
# Run DscConfiguration
provisioner "powershell" {
inline = [
"Write-Host 'INFO: Initiating DSC configuration...'",
"Set-DscLocalConfigurationManager -Path \"$env:windir\\Temp\\DSC-Configs\\LCMConfig\" -Force",
"Publish-DscConfiguration -Path \"$env:windir\\Temp\\DSC-Configs\\DotNetFrameworkConfiguration\" -Force",
"Publish-DscConfiguration -Path \"$env:windir\\Temp\\DSC-Configs\\MicrosoftEdgeConfiguration\" -Force",
"Publish-DscConfiguration -Path \"$env:windir\\Temp\\DSC-Configs\\WindowsDefenderConfiguration\" -Force",
"Publish-DscConfiguration -Path \"$env:windir\\Temp\\DSC-Configs\\WindowsFirewallConfiguration\" -Force",
"Publish-DscConfiguration -Path \"$env:windir\\Temp\\DSC-Configs\\WindowsClientConfiguration\" -Force",
"Start-DscConfiguration -UseExisting -Wait -Verbose"
]
}
# Update help information for powershell cmdlets
provisioner "powershell" {
inline = [
"Write-Host 'INFO: Grabbing latest help files for powershell modules...'",
"Update-Help -UICulture en-us -ErrorAction Ignore -Force"
]
}
# Update Windows
# NOTE: References for update GUIDS https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ff357803(v=vs.85)
provisioner "windows-update" {
search_criteria = "AutoSelectOnWebSites=1 and IsInstalled=0"
filters = [
"exclude:$_.Title -like '*Preview*'",
"include:$true"
]
update_limit = 25
}
# Setup packer shutdown
provisioner "file" {
source = "Scripts\\Packer-Shutdown.cmd"
destination = "C:\\Windows\\Temp\\Packer-Shutdown.cmd"
}
# Placing SetupComplete
provisioner "file" {
source = "Scripts\\SetupComplete.cmd"
destination = "C:\\Windows\\Setup\\Scripts\\SetupComplete.cmd"
}
# Defrag cleanup
provisioner "powershell" {
inline = [
"Write-Host 'INFO: Defragging Volume...'",
"defrag.exe c: /U /V | Out-Null"
]
}
}