Hi Rickard,
Thanks, that PR looks quite promising! Would you consider re-opening it?
I personally do not mind the extra time involved with launching a new instance and conducting the tests there. I considered running the tests within the packer instance, before creating the AMI, but our process makes it a little difficult... We use userdata to pivot /root to tmpfs (in memory), and then re-partition the root EBS volume and use chroot to complete the build. This is the only mechanism* we've found that allows us to re-partition the root volume and preserve the billing product code. So, I'm not sure what hurdles we'd run into getting the tests to execute against the chroot. (*Well, we could also chroot a secondary volume, then shutdown the instance, detach both root and secondary volumes, attach the secondary volume as root, and then create the image...but that is even more cumbersome and wouldn't address this problem.)
Also, the tests are sometimes dependent on the instance type, such as validating that the image is supporting detection of the network interface speed at 10Gbps. So we'd likely want to launch a new instance anyway, possibly several, to test different scenarios.
I can look into Terraform, also; I don't have any experience with it currently. Does it also handle the setup and teardown of resources around launching the instance, running some commands, and terminating the instance (i.e. create/delete keypair, security group, etc)? The EBS builder in Packer is _almost_ purpose-built for this...and there is already the null builder, which serves a sortof-similar use case.
Cheers,
-Loren