hashicorp / terraform-provider-archive

Utility provider that provides a data source that can create zip archives for individual files or collections of files.
https://registry.terraform.io/providers/hashicorp/archive/latest/docs
Mozilla Public License 2.0
90 stars 63 forks source link

Using exclude_symlink_directories also skips all directories lexically greater than the symlinked directory in the parent dir. #361

Open metmikel opened 2 months ago

metmikel commented 2 months ago

Terraform CLI and Provider Versions

Terraform v1.9.4 on windows_amd64

Terraform Configuration

# Achive the files to include in the function app package
data "archive_file" "functionapp_archive" {
  type        = "zip"
  source_dir = "${path.module}/function"
  # This also skips all directories lexically greater than the symlinked directory in the parent directory
  exclude_symlink_directories = true
  output_path = "${path.module}/function-app.zip"
  # Excludes list drawn from .funcignore file
  excludes = [
    "**/*.js.map",
    "**/*.ts",
    ".git*",
    ".vscode",
    "__azurite_db*__.json",
    "__blobstorage__",
    "__queuestorage__",
    "local.settings.json",
    "test",
    "tsconfig.json"
  ]
}

Expected Behavior

I am zipping up the contents of a Typescript package to run as an Azure Function. To do this successfully I need to exclude the symlink to the package root directory that npm install creates under node_modules, but I need all the other directories and files present under node_modules to be included.

Actual Behavior

If I use exclude_symlink_directories = true to skip the symlink to the package root directory that npm install creates, then all remaining directories that are lexically greater than the symlink name in node_modules are skipped too.

Steps to Reproduce

  1. Create a default Typescript Azure Function under a directory called "function"
  2. Run npm install in the "function" directory to install the required node modules under node_modules.
  3. Create a Terraform script to zip up the "function" directory (using the Terraform snippet above)
  4. terraform init && terraform plan
  5. Examine the zip file created - note that under the node_modules directory, every directory lexically greater than the symlinked directory in the original directory has been skipped from the zip file.

How much impact is this issue causing?

Medium

Logs

No response

Additional Information

A workaround is to include the symlink in the excludes block.

Code of Conduct

metmikel commented 2 months ago

I believe I have fixed this in https://github.com/hashicorp/terraform-provider-archive/pull/362