I’m trying to learn Packer for Windows after using it with Linux for about a year. I don’t know Windows well; but I can’t seem to upload files with Packer to my Windows instance. The file says it uploads, but when I start the instance; the file is not there. What am I doing wrong?
poc.json:
{
"variables": {
"environment": "redacted",
"contact": "redacted",
"service": "redacted"
},
"builders": [
{
"profile": "nonprod",
"region": "us-west-2",
"type": "amazon-ebs",
"subnet_id": "redacted",
"security_group_id": "redacted",
"source_ami": "redacted",
"instance_type": "t2.micro",
"communicator": "winrm",
"winrm_username": "Administrator",
"ami_name": "{{user `service`}}-v7.0-{{user `environment`}}-Packer-{{timestamp}}",
"tags": {
"Name": "{{user `service`}}-v7.0-{{user `environment`}}-Packer-{{timestamp}}",
"Service": "{{user `service`}}",
"Environment": "{{user `environment`}}",
"Contact": "{{user `contact`}}",
"Packer": "true"
},
"run_tags": {
"Name": "{{user `service`}} Packer Builder",
"Service": "{{user `service`}}",
"Environment": "{{user `environment`}}",
"Contact": "{{user `contact`}}",
"Packer": "true"
},
"launch_block_device_mappings": [
{
"device_name": "xvdb",
"volume_size": 500,
"volume_type": "gp2",
"delete_on_termination": true
}
]
}
],
"provisioners": [
{
"type": "powershell",
"inline": [
"C:/ProgramData/Amazon/EC2-Windows/Launch/Scripts/InitializeInstance.ps1 -Schedule",
"C:/ProgramData/Amazon/EC2-Windows/Launch/Scripts/SysprepInstance.ps1 -NoShutdown",
"Get-Disk | where partitionstyle -eq \"raw\" | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel \"Data Drive\" -Confirm:$false",
"mkdir C:/Packer/",
"mkdir C:/Packer/Misc_Installers/"
]
},
{
"type": "file",
"source": "./files/startup.ps1",
"destination": "C:\\Packer\\"
}
]
}
PACKER_LOG=1 packer build poc.json:
2020/05/20 08:04:05 [INFO] (telemetry) Starting provisioner file
==> amazon-ebs: Uploading ./files/startup.ps1 => C:\Packer\
2020/05/20 08:04:05 packer-builder-amazon-ebs plugin: Uploading file to 'C:\Packer\startup.ps1'
2020/05/20 08:04:05 packer-provisioner-file plugin: [INFO] 1515 bytes written for 'uploadData'
2020/05/20 08:04:05 [INFO] 1515 bytes written for 'uploadData'
startup.ps1 1.48 KiB / 1.48 KiB [=====================================================================================================] 100.00%
startup.ps1 1.48 KiB / 1.48 KiB [=====================================================================================================] 100.00%
2020/05/20 08:04:08 packer-builder-amazon-ebs plugin: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>#< CLIXML
2020/05/20 08:04:08 packer-provisioner-file plugin: closing
2020/05/20 08:04:08 closing
2020/05/20 08:04:08 packer-builder-amazon-ebs plugin: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><startup.ps1 1.48 KiB / 1.48 KiB [==================================================================================================] 100.00% 2s
2020/05/20 08:04:08 [INFO] (telemetry) ending file