Terraform CLI and Provider Versions
Terraform v1.10.4
on linux_amd64
- provider registry.terraform.io/hashicorp/archive v2.7.0
Use Cases or Problem Statement
I'm currently using the archive_file resource to create a zip of a folder with multiple nested folders.
Example structure of folder:
parent_folder/
| - folder1/
| | - file1_in_folder1
| | - file2_in_folder1
| - folder2/
| | - file1_in_folder2
| - file1
| - file2
| - file3
| - ...
Terraform:
resource "archive_file" "mydir" {
type = "zip"
output_path = "mydir.zip"
source_dir = "./parent_folder/"
}
archive_file includes the parent_folder, with all the files within it, i.e., when the archive is extracted, there is a parent_folder at the root. However, for my usecase, the requirement is that the parent_folder should not be included, i.e., file1 should be at the root when the file is unzipped.
I tried source_dir = "parent_folder/*", but that threw an error.
I'm working around this by specifying each file in its own source block instead, but this become unscalable with complex directory structures.
Proposal
Perhaps something like:
resource "archive_file" "mydir" {
type = "zip"
output_path = "mydir.zip"
source_dir = "./parent_folder"
skip_parent = true
}
where if skip_parent is true, the archive includes only the files within the directory and not the directory itself.
====
An alternative would be to preserve parent if there is no trailing forward-slash, and exclude parent if there is (as suggested in this related issue: #66 (comment)).
resource "archive_file" "mydir" {
type = "zip"
output_path = "mydir.zip"
source_dir = "./parent_folder" // preserves parent folder
}
resource "archive_file" "mydir" {
type = "zip"
output_path = "mydir.zip"
source_dir = "./parent_folder/" // excludes parent folder
}
How much impact is this issue causing?
Medium
Additional Information
This seems to be the opposite problem to that mentioned in #66, so it seems like things worked differently in a previous version.
Code of Conduct
Terraform CLI and Provider Versions
Terraform v1.10.4
on linux_amd64
Use Cases or Problem Statement
I'm currently using the
archive_fileresource to create a zip of a folder with multiple nested folders.Example structure of folder:
Terraform:
archive_fileincludes the parent_folder, with all the files within it, i.e., when the archive is extracted, there is aparent_folderat the root. However, for my usecase, the requirement is that theparent_foldershould not be included, i.e., file1 should be at the root when the file is unzipped.I tried
source_dir = "parent_folder/*", but that threw an error.I'm working around this by specifying each file in its own
sourceblock instead, but this become unscalable with complex directory structures.Proposal
Perhaps something like:
where if
skip_parentistrue, the archive includes only the files within the directory and not the directory itself.====
An alternative would be to preserve parent if there is no trailing forward-slash, and exclude parent if there is (as suggested in this related issue: #66 (comment)).
How much impact is this issue causing?
Medium
Additional Information
This seems to be the opposite problem to that mentioned in #66, so it seems like things worked differently in a previous version.
Code of Conduct