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
89 stars 62 forks source link

archive_file produces a corrupted zip file #282

Closed AbirHamzi closed 9 months ago

AbirHamzi commented 9 months ago

Terraform CLI and Provider Versions

Terraform v1.6.5 Provider v2.4.0

Terraform Configuration

resource "archive_file" "my-archive" {
  type             = "zip"
  source_dir       = "my-code"
  output_path      = "my-code.zip"

}

Expected Behavior

I expect to see the same number of compressed files as the CLI zip command and I can run the unzip command without problems.

Actual Behavior

my-code.zip: compressed by archive_file my-code1.zip: compressed by the zip command

$ zipinfo my-code.zip 2184 files, 21307869 bytes uncompressed, 13355944 bytes compressed: 37.3%

$ zipinfo my-code1.zip 3057 files, 21307869 bytes uncompressed, 13302202 bytes compressed: 37.6%

Steps to Reproduce

  1. terraform apply

How much impact is this issue causing?

High

Logs

No response

Additional Information

No response

Code of Conduct

bendbennett commented 9 months ago

Hi @AbirHamzi 👋

Sorry you ran into trouble here.

Can you provide some further details on the discrepancy between the archive generated by using _archivefile versus the archive produced by running the zip command directly? Specifically, which files are being excluded from the archive when _archivefile is used compared to using the zip command?

nicolasiscoding commented 9 months ago

I am seeing the same issue

ricardo-vargas-globant commented 9 months ago

hi, I am facing the same issue with this module, this is happening in aws code pipeline when I am trying to deploy a lambda function compressing the code. These are the steps my pipeline does

  ~ resource "aws_lambda_function" "executor" {
        id                             = "XXXX-XXX"
      ~ last_modified                  = "2023-12-14T18:26:58.114+0000" -> (known after apply)
      ~ source_code_hash               = "TLjOA7sHL0aqCELeiTvHOvgQ5udziIsqT0jzRw4fX7c=" -> "ktFmbHiFVN26iyGz0ULweoAV8lnUibpMDgN/79GrfWc=" # For some reason shows different hash code
        tags                           = {
            "Name"         =  "XXXX-XXX"
            "app"          = "data"
            "creation_app" = "terraform"
            "env"          = "d1"
            "site"         = "aue1"
            "tier"         = "data"
            "zone"         = "z1"
        }
        # (21 unchanged attributes hidden)

        # (4 unchanged blocks hidden)
    }

Error during the apply

Error: updating Lambda Function ("XXXX-XXX") code: operation error Lambda: UpdateFunctionCode, https response error StatusCode: 400, RequestID: 8a818ada-9e06-4126-8666-8ef6270629d2, InvalidParameterValueException: Failed to unzip archive: An error in the archive format was detected. Please fix the error and retry;

I tried to replicate this locally and I did it once, after that the module have been working as expected.

As @AbirHamzi mentioned, the size of the generated file is smaller than the expected and it's not possible to open the file.

AbirHamzi commented 9 months ago

I'm closing this issue because my problem has been resolved. Even though the number of files compressed with 'archive_file' is not the same as those compressed with the 'zip' command, it was not the reason why my file is corrupted

github-actions[bot] commented 3 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.