File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 1+ <powershell > # XML Tag for EC2ConfigService
2+
3+ # Run Sysprep via EC2Launch scripts
4+ # https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2launch.html#ec2launch-sysprep
5+
6+ Set-Location "$env:ProgramData\Amazon\EC2-Windows\Launch\Scripts"
7+ $command = '.\InitializeInstance.ps1 -Schedule'
8+ Invoke-Expression -Command $command
9+ $command = '.\SysprepInstance.ps1'
10+ Invoke-Expression -Command $command
11+ </powershell >
Original file line number Diff line number Diff line change @@ -146,6 +146,11 @@ function New-PackerBaseAMI {
146146 }
147147
148148 # Build the Packer Template
149+ if ($BaseOS -match ' 2016|2019' ) {
150+ $UserDataFile = " $ ( Split-Path (Get-Module PackerBaseAMI).Path - Parent) \Private\UserDataEC2Launch.xml"
151+ } else {
152+ $UserDataFile = " $ ( Split-Path (Get-Module PackerBaseAMI).Path - Parent) \Private\UserData.xml"
153+ }
149154 $builders = [PSCustomObject ]@ {
150155 type = " amazon-ebs"
151156 communicator = " none"
@@ -157,7 +162,7 @@ function New-PackerBaseAMI {
157162 instance_type = " t2.medium"
158163 source_ami = $AmiToPack.ImageId
159164 ami_name = $NewAMIName
160- user_data_file = " $ ( Split-Path ( Get-Module PackerBaseAMI).Path - Parent ) \Private\UserData.xml "
165+ user_data_file = $UserDataFile
161166 }
162167 $PackerTemplate = [PSCustomObject ]@ {
163168 builders = @ ($builders )
You can’t perform that action at this time.
0 commit comments