terraform-aws-modules/terraform-aws-lambda

unable to find zip build after the 1st run

yerbaszen opened this issue · 3 comments

Description

I have my infrastructure deployed with github actions. I call the module this way:

module "lambda_functions" {
  version = "4.7.2"
  source  = "terraform-aws-modules/lambda/aws"

  count                                   = length(var.lambda_functions)
  function_name                           = "${var.lambda_functions[count.index].name}-${var.environment}-${var.stage}"
  handler                                 = "index.handler"
  runtime                                 = var.runtime
  timeout                                 = 900
  cloudwatch_logs_retention_in_days       = 7
  attach_policy_json                      = true
  policy_json                             = var.lambda_policy_json
  allowed_triggers                        = var.allowed_triggers
  create_current_version_allowed_triggers = false # required for allowed_triggers to work. 
  description                             = var.lambda_functions[count.index].description
  source_path                             = var.lambda_functions[count.index].source_path
  environment_variables                   = var.lambda_functions[count.index].environment_variables
  vpc_subnet_ids                          = length(var.lambda_functions[count.index].vpc_subnet_ids) != 0 ? var.lambda_functions[count.index].vpc_subnet_ids : null                                                                                  # Conditional vpc setup
  vpc_security_group_ids                  = length(var.lambda_functions[count.index].vpc_security_group_ids) != 0 && length(var.lambda_functions[count.index].vpc_subnet_ids) != 0 ? var.lambda_functions[count.index].vpc_security_group_ids : null # Conditional vpc setup
  tags = {
    environment = var.environment
    stage       = var.stage
  }
  # recreate_missing_package                = false 
}

and I've tried the FAQs suggestions

  • TF_RECREATE_MISSING_LAMBDA_PACKAGE=false as environmennt variable
  • and the recreate_missing_package = false in the module call.

the first time the pipeline runs, it works, It could runs multiple times after that, without making any changes to my lambas, and it is what is expected (no zip file being build, and no detecting any configuration changes to deploy), but if any change is made, or even the lambda is being removed completely, It always ends up throwing this error:

╷
│ Error: reading ZIP file (builds/d2704150671cc205ed0041124995e2fe42484a1e22c409b423288d28b7657439.zip): open builds/d2704150671cc205ed0041124995e2fe42484a1e22c409b423288d28b7657439.zip: no such file or directory
│ 
│   with module.appsync.module.appsync_lambda_authorizer.module.lambda_functions[0].aws_lambda_function.this[0],
│   on .terraform/modules/appsync.appsync_lambda_authorizer.lambda_functions/main.tf line 24, in resource "aws_lambda_function" "this":
│   24: resource "aws_lambda_function" "this" {
│ 
  • [yes] I have searched the open/closed issues and my issue is not listed.

⚠️ 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

  • Module version [Required]: 4.7.2

  • Terraform version:

  • Provider version(s):

(taken from github workflow)

- Installing datadog/datadog v3.20.0...
- Installed datadog/datadog v3.20.0 (signed by a HashiCorp partner, key ID FB70BE941301C3EA)
- Installing hashicorp/tls v4.0.4...
- Installed hashicorp/tls v4.0.4 (signed by HashiCorp)
- Installing hashicorp/archive v2.3.0...
- Installed hashicorp/archive v2.3.0 (signed by HashiCorp)
- Installing hashicorp/random v3.4.3...
- Installed hashicorp/random v3.4.3 (signed by HashiCorp)
- Installing hashicorp/null v3.2.1...
- Installed hashicorp/null v3.2.1 (signed by HashiCorp)
- Installing hashicorp/template v2.2.0...
- Installed hashicorp/template v2.2.0 (signed by HashiCorp)
- Installing hashicorp/local v2.3.0...
- Installed hashicorp/local v2.3.0 (signed by HashiCorp)
- Installing cloudposse/template v2.2.0...
- Installed cloudposse/template v2.2.0 (self-signed, key ID 7B22D099488F3D11)
- Installing hashicorp/aws v4.52.0...
- Installed hashicorp/aws v4.52.0 (signed by HashiCorp)
- Installing hashicorp/external v2.2.3...
- Installed hashicorp/external v2.2.3 (signed by HashiCorp)

Reproduction Code [Required]

Steps to reproduce the behavior:

export TF_RECREATE_MISSING_LAMBDA_PACKAGE=false
then setup the module with similar values terraform init && terraform apply -auto-approve

Expected behavior

Lambda being able to be build (during apply time) and deployed only when necessary

Actual behavior

Lambda only gets built the first time.

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

This issue was automatically closed because of stale in 10 days