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 control to use timestamp to trigger the package creation or not (useful for CI/CD) #521

Closed samuel-phan closed 5 months ago

samuel-phan commented 6 months ago

Description

Add a variable trigger_on_package_timestamp (boolean - defaults to true) to whether use timestamp to trigger the package creation or not.

Motivation and Context

Problem

  1. Use the lambda module to create a lambda. Run terraform apply. The lambda is created.
  2. Delete the builds directory (to simulate a CICD job with an empty environment).
  3. Run terraform plan again, it will detect a drift because the timestamp has changed.

One solution was to add the variable recreate_missing_package = false, but when the CICD job (without any builds directory) runs terraform apply will face this error:

│ Error: Provider produced inconsistent final plan
│
│ When expanding the plan for module.foo_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("cqn6fMnsZk+KB1YcvY+mV9lVQvKZ7T7n+vpBjv/qg3s="), but now
│ cty.StringVal("mM6yOCDC4GsOEw8Sqyb7t1aZPQqbwu/g27igFYoF6ko=").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Solution

Add a variable trigger_on_package_timestamp (boolean - defaults to true) to whether use timestamp to trigger the package creation or not.

Fix #396

Breaking Changes

None.

How Has This Been Tested?

I have added an example/simple-cicd with a test.sh inside to run the test scenario.

github-actions[bot] commented 5 months ago

This PR has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this PR will be closed in 10 days

samuel-phan commented 5 months ago

@antonbabenko Would you have some time to take a look at this PR please? 🙇

antonbabenko commented 5 months ago

This PR is included in version 6.7.0 :tada:

github-actions[bot] commented 4 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.