-
Notifications
You must be signed in to change notification settings - Fork 63
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 different results on different OSs #34
Comments
I had encountered this issue too. |
I noticed that the produced zip file differs depending on the permissions of the source file. Why would the source file permissions be different? One common case is having a different umask between systems. For example, my laptop's default umask is Prior to realizing that archive_file worked for directories, I wrote a little tool to produce deterministic zip files. To handle permissions it either sets all files in the zip to be The reason for these permissions is, as according to the lambda documentation all files should have global read permissions. While it's not explicitly stated, I interpret that to mean any executables thus need to have global execute permissions. Hence why I think zip files created by this tool should apply consistent permissions to all users (i.e., user, group, other sections). Edit: I'm going to see I can quickly make a PR for this. I've never worked with go, but it seems straightforward enough. |
I came across this issue where my centos 7 VM has different permissions for mounted volumes and was removing the execute bit. Annoyingly, trying to change the permissions doesn't work (see https://superuser.com/questions/1083393/virtualbox-guest-shared-folder-ignoring-umask) some kind of parameter on the archive_file data source block to set the execute bit would make sense as its generating the zip, but wouldn't work for my scenario. |
perhaps a better solution would be to provide a source hash i.e. After all, the source_code_hash element is used to trigger an update on change so inspecting the source rather than the exported binary zip should fulfill the same requirement. |
I think you misunderstand. AWS does indeed confirm the hash of the uploaded binary(https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html) but I expect this is intended to confirm that the binary has uploaded correctly. However, according to the terraform docs the source_code_hash element in aws_lambda_function is "Used to trigger updates". so it would be good to have a trigger that can identify that the code has changed separate from the hash result of the binary. Of course this doesn't answer the question, why is the binary output different across OS's. And if terraform is verifying the hash of the binary in the background anyway this still needs to be resolved. |
That only works when you're only archiving a single file. What if you're archiving a directory? |
I submitted this PR some time ago but haven't heard anything from maintainers of the project. 🤷♂ |
This is not an easy or straight forward task (even if it looks like it) and I seriously doubt that Terraform is going to fix it. A couple of years ago a new project called TorrentZip was created by the MAME community to tackle this exact problem (reproducible zip files across multiple operating systems). More information here: http://rescene.wikidot.com/torrentzip It seems that someone implemented a Go version of it: https://github.com/uwedeportivo/torrentzip |
@appilon @radeksimko Any chance we could get this merged into the module? This issue has been around for awhile and has the most upvotes/comments |
Still having the issue today |
I can confirm this behavior still exists as the patch from @saveriomiroddi wasn't merged (sadly). With out these changes the archive_file production isn't idempotent. At a minimum this should be reflected in the documentation so that appropriate steps can be taken to avoid the problem |
Hello all, apologies for the long time without any word. Unfortunately solving this problem is inherently difficult, we recently setup multi-os testing in #71 to try and have a better chance at catching problems such as this, but this issue specifically isn't something that we can practically catch in CI. We are evaluating the solutions proposed in #41 and #47, but in this circumstance trying to code against operating system or library defaults just so a common pattern for a different provider is resolved, might not be something we want to set precedent for in an individual provider (our apologies if that is a frustrating stance to take). With that said, we are still looking at the two proposed PRs, and will be attempting to either come up with a solution, or provide a final word/guidance. UPDATE: #53 is likely the enhancement we want to make to try and remedy the problem. |
@appilon Thanks so much for the update. Looking forward to a hopeful resolution soon. |
A workaround we applied was to have:
The Note (in our case) the first column: Linux -
MacOS -
TF code Example
|
Nicely done, that's great @karolkania 👏👏👏 |
While this is a 2 year old comment (hashicorp/terraform#18422 (comment)), it suggests that zip files should be created by a build process. It would be great if Hashicorp would give an official status on if |
Yeah, I'd love to see some traction on this issue. I don't think this is out of scope of Terraform though. As this thread has mentioned, there are tons of workarounds to get it working. Just need Hashicorp to actually put some resources on this and get it working. |
Hi there! I've deleted all of my comments are closed the PR; please don't (manually) CC me. |
There is a proposed workaround for this issue in #90, which adds an optional I would be very grateful if some of you experiencing this could test this fix by running @virgofx's provider locally. @virgofx has kindly provided binaries from his branch for testing: #90 (comment) You can find instructions for using a locally built provider here: https://www.terraform.io/docs/cli/config/config-file.html#development-overrides-for-provider-developers |
The workaround in #90 has been released in terraform-provider-archive v2.2.0. If |
This didn't fix it for me:
However, the zips I were having the problem with were zips created inside a module that's used multiple times... If anyone reading this is also having a problem in this scenario, check out my comment @ #31 (comment) |
Here's something that I've been doing for some time now, and is working reliably cross-platform (local runs on darwin, CI runs on linux):
I.e. instead of using |
worked for me as well. Thanks @davidalger |
@davidalger cam across this one. we are uploading our compiled go code into the zip, but the hashes are unstable (like the whole internet has this problem). sadly |
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. |
Affected Resource(s)
archive_file
aws_lambda_function
Terraform Configuration Files
After applying on Windows, planning on Mac indicates that
source_code_hash
has changed, even though the content of the code has not changed. This is becausearchive_file
produces equivalent but not identical results on Mac and Windows.Expected Behavior
The lambda updates IFF the source code changes
Actual Behavior
The lambda updates when the source code changes OR if you run terraform on a different OS
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform apply
on Windowsterraform plan
on MacThe text was updated successfully, but these errors were encountered: