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
929 stars 689 forks source link

Could not locate source_path "null" despite create_function = false #409

Closed DuncanKwokTR closed 1 year ago

DuncanKwokTR commented 1 year ago

Description

I already have zipped my own package and do not require create_function, so it is set to false. Yet despite that, module is looking to for source_path of the deployment. It is already given local_existing_package = "file.zip"

module "r53_lambda_function_externally_managed_package" { source = "../../Resource_modules/lambda/" create_function = true # to control creation of the Lambda Function and related resources create_package = false # to control build package process create_layer = false # to control creation of the Lambda Layer and related resources create_role = true # to control creation of the IAM role and policies required for Lambda Function

function_name = local.vds_lambda_function_name description = "My lambda function code is deployed separately" handler = var.vds_lambda_handler runtime = var.vds_lambda_runtime ignore_source_code_hash = true vpc_security_group_ids = [module.r53_security_group.security_group] vpc_subnet_ids = var.vds_lambda_subnet_ids

attach_cloudwatch_logs_policy = false attach_dead_letter_policy = false attach_network_policy = false attach_tracing_policy = false attach_async_event_policy = false

local_existing_package = var.vds_lambda_filename

Depsite asking not to create package...

source_path = local.source_path

source_path = "../../../lambda_python/healthcheck.zip"

// IAM Role Create role_path = local.iam_lambda_role_path role_name = local.iam_lambda_role_name role_description = local.iam_lambda_role_description role_permissions_boundary = local.iam_lambda_role_permissions_boundary_arn role_force_detach_policies = local.iam_lambda_force_detach_policies

// IAM Policy Create policy_name = local.iam_lambda_policy_name policy_path = local.iam_lambda_policy_path policy_json = local.iam_lambda_policy

// IAM Policy Attachment attach_policy_json = true

}

Looking at the main.tf module, I see only 2 references to source_path resource "null_resource" "sam_metadata_aws_lambda_function" { count = local.create && var.create_package && var.create_function && !var.create_layer ? 1 : 0

resource "null_resource" "sam_metadata_aws_lambda_layer_version" { count = local.create && var.create_package && var.create_layer ? 1 : 0

To my understanding, if create_package = false, source_path should not even be required and will be null.

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:

no yes

call the resource module to create lambda function that has externally managed package and don;t build it from source.

Expected behavior

Skip the creation of the package.

Actual behavior

it is looking asking for source_path, despite create_function = false.

Terminal Output Screenshot(s)

β”‚ Error: External Program Execution Failed β”‚ β”‚ with module.r53_lambda_permission.data.external.archive_prepare[0], β”‚ on ../../Resource_modules/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: Could not locate source_path "null". Paths are relative to directory where terraform plan is being run β”‚ ("/home/users/gitprojects/Infrastructure_modules/cloud_container_infrastructure")

It says paths are relative, but in variables.tf, it says absolute path. variable "source_path" { description = "The absolute path to a local file or directory containing your Lambda source code" type = any # string | list(string | map(any)) default = null }

I've also tried to set create_function = true but it can never find my source through source_path even though it is correct.

Additional context

DuncanKwokTR commented 1 year ago

Apologies, in my original post, i wrote source_path = "../../../lambda_python/healthcheck.zip" It is supposed to be simply source_path = "../../../lambda_python" but still didnt work.

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.