terraform-provider-archive
terraform-provider-archive copied to clipboard
Feature Request: Maintain Parent Directory of source_dir
Trying to create a lambda layer consisting of just the ./node_modules fails, because the zip file created strips away the node_module parent directory (example). Ideally, source_dir should maintain the parent directory structure and allow you to strip away the parent directory using a value such as ./path/to/dir/**, but this would not be backwards compatible. Ways this could be solved without breaking backwards compatibility would be to add an ignore attribute that would be a regex, a target_dir attribute that would set the name of the parent directory inside of the zip file, or a boolean attribute save_parent_dir to copy the parent directory structure as well.
Terraform Version
Terraform v0.12.24
+ provider.archive v1.3.0
+ provider.aws v2.54.0
Affected Resource(s)
- data.archive_file
Terraform Configuration Files
data "archive_file" "node_modules" {
type = "zip"
output_path = "./.cache/${var.name}_node_module.zip"
source_dir = "${var.source_dir}/node_modules"
}
Is there a known workaround for this?
I was expecting source_dir to preserve the directory when not providing a trailing /. In other words:
/my/path/node_modules- produces a zip withnode_modulesat the root/my/path/node_modules/- produces a zip with the contents ofnode_modulesat the root
In my case, I'm trying to add a python package to a zip, preserving the package parent directory.
This is also a problem when you use source blocks:
data "http" "this" {
# ...
}
data "archive_file" "this" {
type = "zip"
output_path = "${path.root}/zipfiles"
source {
content = data.http.this.body
filename = "my-certs/cert-ca.pem"
}
}
will place the cert file at the root of the zip package.