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 657 forks source link

Lambda packaging suddenly failing. #430

Closed spliskamatyshak-w3 closed 1 year ago

spliskamatyshak-w3 commented 1 year ago

Description

I can't honestly explain what is going on because it worked Friday and today it doesn't. I see no significant changes to anything related to this code. Already tried backing out to aws provider 4.56.0. Same exact messages.

│ Error: External Program Execution Failed
│ 
│   with module.edge_lambda.data.external.archive_prepare[0],
│   on .terraform/modules/edge_lambda/package.tf line 10, in data "external" "archive_prepare":
│   10:   program = [local.python, "${path.module}/package.py", "prepare"]
│ 
│ The data source received an unexpected error while attempting to execute the program.
│ 
│ Program: /usr/local/bin/python3
│ Error Message: Traceback (most recent call last):
│   File "/Users/spliskamatyshak/Documents/GitHub/discover-api/infrastructure/pipelines/acct-infra/.terraform/modules/edge_lambda/package.py", line 1627, in <module>
│     main()
│   File "/Users/spliskamatyshak/Documents/GitHub/discover-api/infrastructure/pipelines/acct-infra/.terraform/modules/edge_lambda/package.py", line 1623, in main
│     exit(args.command(args))
│          ^^^^^^^^^^^^^^^^^^
│   File "/Users/spliskamatyshak/Documents/GitHub/discover-api/infrastructure/pipelines/acct-infra/.terraform/modules/edge_lambda/package.py", line 1433, in prepare_command
│     content_hash.update(hash_extra.encode())
│                         ^^^^^^^^^^^^^^^^^
│ AttributeError: 'NoneType' object has no attribute 'encode'
│ 
│ State: exit status 1

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

Steps to reproduce the behavior:

module "edge_lambda" {
  source  = "terraform-aws-modules/lambda/aws"
  version = "~> 4.10"

  function_name  = "within3-discover-headers"
  description    = "Edge lambda for auth0"
  handler        = "index.header"
  runtime        = "nodejs16.x"
  lambda_at_edge = true
  source_path    = "${path.root}/../../fixtures/edge"
}

Expected behavior

Should package the lambda as it has until today.

Actual behavior

See error above.

Terminal Output Screenshot(s)

Additional context

kunalmbm commented 1 year ago

I am also facing this issue for our prod deployment on version 1.38.0. Did anyone found the root cause or fix for this issue?

pneigel-ca commented 1 year ago

It appears this could be related to the external provider used for the data source.

Link to relevant issue and discussion: https://github.com/hashicorp/terraform-provider-external/issues/193

drewclardy commented 1 year ago

Setting the hash_extra input to an arbitrary value got around this issue.

pneigel-ca commented 1 year ago

Updating to v2.3.1 of the external provider fixed the issue for my team.

If you are obtaining the latest provider/not setting constraints, the next deployment should detect this from registry.

spliskamatyshak-w3 commented 1 year ago

I ended up blowing away my repo locally and recloning before things started working again. I'm guessing ultimately, it was the external provider update that actually fixed this.

spliskamatyshak-w3 commented 1 year ago

It appears it was the external provider causing this. Since that has been rectified, I'm closing this.

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