From 4f62c8e422da68e2ccaeb6e24ece3641ea41ccbb Mon Sep 17 00:00:00 2001 From: chenga Date: Mon, 27 May 2024 14:28:34 +0300 Subject: [PATCH] enhance function name variable to api gateway --- modules/api_gateway/rest_api.tf | 2 +- modules/api_gateway/variables.tf | 5 +++++ modules/lambda/lambda.tf | 2 +- shared.tf | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/api_gateway/rest_api.tf b/modules/api_gateway/rest_api.tf index 01426b0..a2629cc 100644 --- a/modules/api_gateway/rest_api.tf +++ b/modules/api_gateway/rest_api.tf @@ -43,7 +43,7 @@ resource "aws_api_gateway_method_response" "response_200" { resource "aws_lambda_permission" "lambda_permission" { statement_id = "AllowExecutionFromAPIGateway" action = "lambda:InvokeFunction" - function_name = var.resource_name_pattern + function_name = var.function_name principal = "apigateway.amazonaws.com" source_arn = local.rest_api_execution_arn } diff --git a/modules/api_gateway/variables.tf b/modules/api_gateway/variables.tf index af9f612..88c29d4 100644 --- a/modules/api_gateway/variables.tf +++ b/modules/api_gateway/variables.tf @@ -34,4 +34,9 @@ variable "tags" { variable "integration_type" { type = string description = "Spectral integration type (A unique phrase describing the integration) - Available values: `terraform`." +} + +variable "function_name" { + type = string + description = "The name of the function the API would trigger upon request" } \ No newline at end of file diff --git a/modules/lambda/lambda.tf b/modules/lambda/lambda.tf index 9d06039..7e29feb 100644 --- a/modules/lambda/lambda.tf +++ b/modules/lambda/lambda.tf @@ -1,6 +1,6 @@ locals { runtime = "nodejs20.x" - lambda_source_code_zip_path = "${coalesce(var.lambda_source_code_path, "${path.module}/source_code/${var.integration_type}")}/${var.lambda_source_code_filename}" + lambda_source_code_zip_path = coalesce(var.lambda_source_code_path, "${path.module}/source_code/${var.integration_type}/${var.lambda_source_code_filename}") } resource "aws_lambda_function" "spectral_scanner_lambda" { diff --git a/shared.tf b/shared.tf index 6661005..124b840 100644 --- a/shared.tf +++ b/shared.tf @@ -10,7 +10,8 @@ module "api_gateway" { tags = var.tags environment = var.environment integration_type = var.integration_type - resource_name_pattern = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend" + resource_name_pattern = local.resource_name_pattern + function_name = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend" lambda_function_arn = local.api_triggered_function_arn }