Generated archive contents include an extra (empty) file when output_path
is configured within same directory as source_dir
.
#173
Labels
output_path
is configured within same directory as source_dir
.
#173
Terraform CLI and Provider Versions
All Terraform versions covered by the CI test suite (
0.12.31
,0.13.7
,0.14.11
,0.15.1
).Terraform Configuration
Expected Behavior
The output archive
bar.zip
's contents should exactly replicate the files contained in/foo
prior to Terraform execution.For example, if the
/foo
directory structure looks like:then the expected output archive contents should look like:
Specifically, if the
/foo
source directory does not contain an empty file namedbar.zip
prior to Terraform execution, then the output archivebar.zip
's contents should also not contain an empty file namedbar.zip
.Also, ideally, if the
/foo
source directory does contain a file namedbar.zip
prior to Terraform execution, then the output archivebar.zip
's contents should also contain a file namedbar.zip
with the same file contents.Actual Behavior
The output archive
bar.zip
's contents includes an extra (empty) file namedbar.zip
.For example, if the
/foo
directory structure looks like:then the actual output archive contents looks like:
Steps to Reproduce
This can be replicated with an extra unit test in
internal/provider/zip_archiver_test.go
:which produces the following test output:
How much impact is this issue causing?
Medium
Logs
No response
Additional Information
The reason this bug occurs is because in the
ArchiveDir()
implementation (seeinternal/provider/zip_archiver.go
),a.open()
is called beforefilepath.Walk()
.a.open()
callsos.Create(a.filepath)
and therefore creates the empty file in the source directory.filepath.Walk()
then proceeds to iterate through the source directory including this new empty file.Potential solutions
Replace
os.Create(a.filepath)
withos.CreateTemp("", "*.zip")
to initially build the archive file in a temporary location. Once built, callos.Rename()
(orio.Copy()
plusos.Remove()
) to move the archive file to the target path.Dynamically append the output path
a.filepath
to the excludes list, so that it will exclude itself. (However, this solution won't handle the scenario when there is a legitimate source file at patha.filepath
that needs to be included.)Code of Conduct
The text was updated successfully, but these errors were encountered: