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

unable to find zip build after the 1st run #407

Closed yerbaszen closed 1 year ago

yerbaszen commented 1 year ago

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

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" {
β”‚ 

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

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.

github-actions[bot] commented 1 year ago

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

github-actions[bot] commented 1 year ago

This issue was automatically closed because of stale in 10 days

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.