Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive_file produces a corrupted zip file #282

Closed
1 task done
AbirHamzi opened this issue Dec 3, 2023 · 5 comments
Closed
1 task done

archive_file produces a corrupted zip file #282

AbirHamzi opened this issue Dec 3, 2023 · 5 comments
Labels

Comments

@AbirHamzi
Copy link

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

  • I agree to follow this project's Code of Conduct
@AbirHamzi AbirHamzi added the bug label Dec 3, 2023
@AbirHamzi AbirHamzi changed the title archive_file produces a corrupt zip file archive_file produces a corrupted zip file Dec 3, 2023
@bendbennett
Copy link
Contributor

Hi @AbirHamzi 👋

Sorry you ran into trouble here.

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

@nicolasiscoding
Copy link

I am seeing the same issue

@bendbennett bendbennett added the waiting-response Issues or pull requests waiting for an external response label Dec 5, 2023
@ricardo-vargas-globant
Copy link

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

  • Download terraform (version 1.5.4),
  • Run script to install as part of the lambda function the dependencies
  • Run terraform init (use archive version 2.4.0)
  • Run terraform plan (here detects changes in lambda and dependencies even when nothing has changed)
  • Run terraform apply (fails bc the zip fail can be unzipped)
  ~ 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.

@github-actions github-actions bot removed the waiting-response Issues or pull requests waiting for an external response label Dec 14, 2023
@AbirHamzi
Copy link
Author

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

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants