Skip to content

Commit 92e9049

Browse files
committed
Adding support for EC2Launch used by 2016 and 2019 images
1 parent 5420d22 commit 92e9049

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Private/UserDataEC2Launch.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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>

Public/New-PackerBaseAMI.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)