terraform-provider-archive icon indicating copy to clipboard operation
terraform-provider-archive copied to clipboard

Feature Request: Maintain Parent Directory of source_dir

Open jerroydmoore opened this issue 5 years ago • 2 comments

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"
}

jerroydmoore avatar Mar 27 '20 20:03 jerroydmoore

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 with node_modules at the root
  • /my/path/node_modules/ - produces a zip with the contents of node_modules at the root

In my case, I'm trying to add a python package to a zip, preserving the package parent directory.

beanaroo avatar Jan 13 '21 07:01 beanaroo

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.

delwaterman avatar Mar 23 '21 19:03 delwaterman