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

Lambda code does not update even though S3 object (lambda zip) gets a new version #470

Closed ArghyaChakraborty closed 1 year ago

ArghyaChakraborty commented 1 year ago

Description

Steps:

  1. Upload lambda zip in S3 bucket
  2. Use this module to refer to the S3 bucket, S3 object name & version as lambda source
  3. Run terraform apply and the Lambda gets created
  4. Update the lambda zip again in S3
  5. S3 object version (lambda zip) gets updated
  6. But terraform does not detect any changes and does not re-upload lambda code

Possible solution: Right now, we can not provide a source_code_hash string as a module input. The source code hash is automatically computed if the file is uploaded from disk. But even if the code is from S3, we can use something like this: resource "aws_lambda_function" "example" {

other arguments ...

s3_bucket = "your_bucket_name" s3_key = "your_object_key" s3_object_version = data.aws_s3_bucket_object.package.version_id source_code_hash = data.aws_s3_bucket_object.package.version_id } So, request you to allow the source_code_hash as an input as well.

Please provide a clear and concise description of the issue you are encountering, and a reproduction of your configuration (see the examples/* directory for references that you can copy+paste and tailor to match your configs if you are unable to copy your exact configuration). The reproduction MUST be executable by running terraform init && terraform apply without any further changes.

If your request is for a new feature, please use the Feature request template.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

Reproduction Code [Required]

Steps to reproduce the behavior:

Expected behavior

Actual behavior

Terminal Output Screenshot(s)

Additional context

antonbabenko commented 1 year ago

If you update version_id in s3_existing_package then Terraform will see the difference and will redeploy it:

https://github.com/terraform-aws-modules/terraform-aws-lambda/blob/dc9356a4804b98894c5d1bf651e88f5eacdb90d8/examples/complete/main.tf#L189-L193

PS: Please complete the issue template and provide the complete reproducible code next time.

github-actions[bot] commented 12 months ago

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.