toowoxx / terraform-provider-packer

Terraform Provider for HashiCorp Packer
Mozilla Public License 2.0
32 stars 7 forks source link

Recursively hash files in directory for `packer_files` data source #6

Closed karelorigin closed 2 years ago

karelorigin commented 2 years ago
data "packer_files" "foo" {
  directory = "${path.module}/image"
  file      = "${path.module}/image/foo.pkr.hcl"
  file_dependencies = [
    "${path.module}/foo",
  ]
}

Is kind of the boilerplate for a simple image with one file dependency, but I have many files in subdirectories that require an image rebuild. Any chance that we can get an option for hashing directories (recursively)?

simaotwx commented 2 years ago

You can do this using the Terraform built-in function fileset:

data "packer_files" "vm_image_files" {
  file              = "image.pkr.hcl"
  file_dependencies = fileset(".", "assets/**")
}

Note that the file denoted by file is already taken into account so you don't need to reference that one in file_dependencies (although, you can).

Let me know if this solves your use case.

karelorigin commented 2 years ago

Actually, yes, I think that might solve it. Thank you! :D

simaotwx commented 2 years ago

You're welcome! :)