Problem
When using the archive_file data source in a Terraform configuration, you may encounter the following error if the target directory contains symbolic links.
error archiving directory: error reading file for archival: read dir_with_symlink/symlinked: is a directory
Cause
This error occurs when the value provided for the source_file attribute points to a directory that contains symbolic links, and you are using a version of the archive provider older than 2.4.0.
Solution
To resolve this issue, update your configuration to use version 2.4.0 or newer of the archive provider. This version includes a fix that correctly handles symbolic links during the archiving process.
Example configuration block specifying the required provider version:
terraform {
required_providers {
archive = {
source = "hashicorp/archive"
version = ">= 2.4.0"
}
}
}After updating your configuration, run terraform init -upgrade to download the new provider version.
Additional Information
- For more details on the fix, refer to the release notes for version 2.4.0 of the archive provider.
- For more information on using this data source, please see the official documentation for the
archive_filedata source.