-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Terraform does not accept source_code_hash #17989
Comments
Hi @andormarkus , thank you for raising this issue and apologies you ran into this behavior. Looking at the resource code, the |
Hi @anGie44 Our deployment workflow for lambda python looks like this: The developer provides the source code of the function and puts every third party (pip) dependencies into the When a pip package is not a pure python package like Due this behaviour the hash of the package will be always different despite the hash of the source code does not change. Please let me know if you need more information.
Thanks, |
Would really like to see this changed... At present either my lambdas always update (because I use the source_code_hash), or never update when I don't, even when the code has changed. If I had control of this value, I wouldn't need to worry about it. I'm probably going to need to just do this myself and then programmatically update the source_code_hash when my own stored hash changes. Really shouldn't be necessary though :/ This issue doubles my build time (the terraform component goes from what should be nearly 0 to trying to push around 50 lambdas...) The value returned by AWS isn't going to be useful for everyone. My lambda zip will change every single build because of unique values in the build process (due to codebuild) that are picked up by various NPM packages and inserted into various package.json files. Would be great if I could tell terraform to only look at certain files (basically my files that exist prior to my build process...). |
With respect to Recently, while trying to implement a new lambda (via a downloaded go zip package) I kept running into a behavior where in the source_code_hash is repeatedly changing. Given TF: resource "aws_lambda_function" "this" {
function_name = module.label.id
filename = "${path.module}/${shell_script.pkg.output["filename"]}"
#source_code_hash = base64encode(shell_script.pkg.output["hash"])
source_code_hash = "NGI3MWUwZWQ5OGEwMmZjODBlM2ZhYzI1YzY3NmE4NjNmOWQ2NjcyMjI0Zjg1YjJjOGE5N2M3NjYwNjE5ZDdjNg=="
runtime = "go1.x"
handler = "app"
timeout = 300 # seconds
role = aws_iam_role.lambda.arn
tags = module.label.tags
}
The apply churns on the
The computed value:
vs The given value:
This confused me mighty until I read the code and found this ticket. If it's computed and has (apparently) no real relationship to the actual archive's sha256 digest, should that be explicitly documented? In fact, the example given even goes out of it's way to compute this value. So I'm not sure what to make of this behavior or if I'm just holding it wrong (which it totally feels like right now) |
I'm encountering the same issue using python lambdas. I've refactored our deployment process to remove any code that might be introducing unexpected changes to the hash (dist-info, pyc files etc). I've also downloaded the resulting zip files and diff'd the contents which shows they're exactly the same but are still generating different hashes. Maybe I'm missing something obvious? |
Even I am facing same issue with my node js lambdas . Any resolution/solution proposed by the team ? |
Hi there, I am facing the same issue with source_code_hash for lambda function, source_code_hash value is changing every time we run it and there is no actual change happened to the file. when i read the thread i got to understand why this is happening, when we can expect to be resolved? Thanks, |
I am facing the same issue where TF plan shows over and over again the lambda source_code_hash being changed from and original value to an updated value. src and dst source_code_hash have been the same between builds as mentioned above. Any knows about where Hashicorp stands on the fix and whether there are any workarounds to this. |
Has there been any update on this issue? |
Any updates on this? We need a way to give terraform a hash that we control so that lambdas don't get updated every time when there hasn't been a change. Alternatively, anybody know a way to force the build process and zipping process to always produce files with the same hashes, if the file content hasn't changed? |
What I ended up doing was pointing terraform at an s3_bucket location and only updating if there was a change in that S3 object. I skipped building and updating that object when possible by doing the hashing myself prior to any build activity from NPM by storing the result of |
Any updates? This is a pretty old issue |
My lambda is triggering drift every day. |
still an issue in 2024. any updates ? |
Any work around for this? |
The issue persists despite using the latest version of Terraform, 1.8.2 |
Warning This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them. Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed. |
This functionality has been released in v5.51.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
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. |
This issue was originally opened by @andormarkus as hashicorp/terraform#28018. It was migrated here as a result of the provider split. The original body of the issue is below.
Hi All,
We are on Terraform 0.14.6 and experiencing the following issue.
We are providing source_code_hash for the aws_lambda_layer_version in the plan terraform accepts it but writes totally different to the state file.
In the plan the source_code_hash is
FyN0P9BvuTm023dkHFaWvAGmyD0rlhujGsPCTqaBGyw=
however in the state file it becamesc3forIEso3mJh74PY6HrhFK94GfJvQ4zG9rEIgBCBhw=
.When I check the layer in AWS CLI the "CodeSha256":
c3forIEso3mJh74PY6HrhFK94GfJvQ4zG9rEIgBCBhw=
,Based on this it does not matter what kind of source_code_hash I can not overwrite hash of filename.
TF config.
TF plan looks like this
However in the statefile I see the following
The text was updated successfully, but these errors were encountered: