Downloading a file with the file provisioner

Hello! I am using Packer to spin up an ephemeral EC2 instance, build an artefact and download it to my machine. I am having some trouble with the file provisioner to download the artefact. My problem is that the artefact has a bit of a random name (e.g. git revisions and dates), so I cannot hardcode it. I realized I cannot use file globbing to fix that, so now instead I am trying to download the directory but I am not having much success with that either.

Here’s my snippet:

  provisioner "file" {
    source      = "./result/sd-image/"
    destination = "./"
    direction   = "download"
  }

I’ve read the file provisioner’s documentation and played around with the suffixed /. My findings are:

  • with ./result/sd-image/ and ./: open sd-image/nixos-21.11.20220310.bacbfd7-aarch64-linux.img.zst: permission denied
  • with ./result/sd-image and ./: open sd-image: is a directory
  • with ./result/sd-image/ and .: open sd-image/nixos-21.11.20220310.bacbfd7-aarch64-linux.img.zst: permission denied
  • with ./result/sd-image and .: open .: is a directory

Hence it seems like I need ./result/sd-image/ and whether or not I suffix the local directory with / is irrelevant. How do I solve the permission issue, though? Note that Packer does create the local sd-image directory, which is owned by my user: dr-xr-xr-x. 1 hjdskes hjdskes 0 26 mar 17.50 sd-image.

As a last resort I can rename the file before attempting to download it, but I’d prefer not having to do that. Can someone help me out? :slight_smile:

Of course right after posting this I realised I hadn’t tried the nixos* glob, only nixos-*.zstd. The latter doesn’t work, the former does :upside_down_face:

Still, I am interested in why I am running into the permissions problem!