Problems baking additional EBS dives into an AWS Windows AMI


I’m new to Packer and I’m really struggling with my first work task.

I need to create a Windows AMI from our Server 2019 base image. That AMI has a 30GB C boot volume and needs to have 2 additional drives D (10GB) (Apps) and E (100GB) (Data). I’m using Powershell as a provisioner.

source "amazon-ebs" "firstrun-windows" {
  launch_block_device_mappings {
    delete_on_termination = true
    device_name           = "xvdg"
    volume_size           = 10
    volume_type           = "gp3"
  launch_block_device_mappings {
    delete_on_termination = true
    device_name           = "xvdh"
    volume_size           = 100
    volume_type           = "gp3"

The provisioner is supposed to find the two raw drives then initialise and partition them. It fails to do so and the symptoms are strange:

  • If I put Get-Disk > a_file.txt in the Powershell code, it only shows the C drive (from the source AMI) and the 10GB D drive
  • If I put Start-Sleep -Seconds 60 in the Powershell code to give the E drive time to come ready in case it takes longer, the whole rest of the Powershell script fails to run and the final AMI shows both drives but they’re uninitialized
  • If I put in Update-StorageProviderCache -DiscoveryLevel Full that breaks it in different ways
  • I did notice in one attempt that Packer said it wrote 60 (presumably important) bytes to STDERR but I can’t see what they were
  • I’ve used launch-block-device-mappings with and without ami-block-device-mappings. Neither helps

After this, the provisioner is supposed to install AWSCLI then download various installers and zip files containing the empty directory structures which get expanded to populate the D and E drives.

I’m clearly falling into some “newbie prat trap.” Can you please tell me what I might have done wrong or point me to a working example of an HCL Packer file that creates multiple extra Windows drives?

Thank you,

Have you made any progress on this? I am running into the same problem and failing to find a solution. Packer builds my image however the powershell initialization doesn’t seem to be happening.