terraform-aws-modules / terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws
Apache License 2.0
886 stars 656 forks source link

feat: Add source_code_hash var #509

Closed Octogonapus closed 8 months ago

Octogonapus commented 8 months ago

Description

This PR adds a source_code_hash variable which overrides the computed hash using a user-supplied value.

Motivation and Context

This change is needed when you are using a lambda zip which is created by Terraform. Terraform's plan will pick up the hash from an existing zip file. If the zip file is recreated at apply time, the hash will change and the plan will become inconsistent, leading to an error like this:

╷
│ Error: Provider produced inconsistent final plan
│ 
│ When expanding the plan for module.foo_lambda.module.lambda.aws_lambda_function.this[0] to include new values learned so far during
│ apply, provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .source_code_hash: was cty.StringVal("2v4cb4VO4El5iGo7/SQ3bLn/lEcSUJAI8o4FBB8u6w0="), but now
│ cty.StringVal("MXbLA/B/BhPwZpVrpD81N27nytZJJ9lXxylwWW5aL0M=").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵

There are lots of issues in the AWS provider like this but I'm not sure if they are caused by this exact use case so I won't link them here.

Breaking Changes

No breaking changes; the source code hash is still computed by default.

How Has This Been Tested?

I tested this in my own project.

antonbabenko commented 8 months ago

I don't understand what was the exact problem your PR should fix. Please provide the 100% failing case (code + steps), so that I can verify it.

As of now, I am 99.9% sure that this PR is not necessary.

Related to #396 (probably).

Octogonapus commented 8 months ago

you are right this can be solved another way

github-actions[bot] commented 6 months ago

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.