Complex Packer HCL2 scenario

I’m trying to create a complex array of build scenarios, and I would rather not have to resort to external forces (e.g. YAML that I process into JSON) in order to do it. HCL2 is getting me close, but there are several things I can’t do that I need to do in order to get myself over that last hump:

  1. I want to build for two different architectures (x86_64 and ppc64le)
  2. I want to build multiple distro (Fedora, Debian, Ubuntu, CentOS, Arch) and multiple versions (F30-F32, Debian 8-10, Ubuntu {16,18,20}.04, CentOS 6/7/8)
  3. I want to build for multiple providers (qemu, vmware-iso, virtualbox-iso)

A few pain points/questions I’ve come across with HCL2:

  1. x86_64 and ppc64le on QEmu have lots of shared options, but differ in a few ways. I don’t want to have to copy everything shared between them. But I can’t seem to generate a “source” block to satisfy this. Same goes for multiple providers or multiple versions of the same distro. Only small tweaks between them. The “merge()” function gets me most of the way there, but it can’t operate at a top level block, nor I figure out how to drop the final merged results of a block into place after merging it all together as a local variable. Some values, I can template in, such as the value of iso_url by asking for “os” and “arch” as variables, but others I can’t. Also, some combinations are invalid - e.g. some versions of some distros don’t support ppc64le, so a simple pure generator approach isn’t going to work.

  2. The vagrantfile_template argument needs to be different between the two architectures. Thus, I need a way to discover which architecture I’m building for. I’ve tried accepting it as a variable, and then making a build with “source = [‘qemu.${var.arch}’]” but I’m not allowed to have a var there. Likewise I’ve tried figuring out what the source name is in the build block, but I can’t figure out how to query the value of “qemu.ppc64le” in order to pass it to the split function. But that doesn’t seem to work. In the past we could use {{ build_name }}, but that doesn’t seem to be working.

  3. Even if I can get all of these building, how do I find the name of the box to pass to the “-only” or “-except”? So if I want to build all of my boxes but just for qemu + x86_64, then how do I know what to pass on the command line? Is that supposed to be defined in the “source” block? The “build” block? That part doesn’t seem to appear anywhere in the documentation that I can find.

  4. In the past, in order to directly upload to Vagrant Cloud we would have a post-processor that was an array of the vagrant + vagrant-cloud post processor. How do I replicate that syntax, now?

Has anyone gotten HCL2 working for a complex example, yet? I feel like the magic is just within my grasp, without needing to farm out to YAML and use the new JSON syntax, but it’s just not quite there, yet.