From fda3e7ce8b08d40ff8b8d7c755caa0b8a21d61ec Mon Sep 17 00:00:00 2001 From: chenga Date: Wed, 29 May 2024 15:10:00 +0300 Subject: [PATCH] update readme + mvoe logic to locals --- README.md | 6 +++++- examples/basic-github-integration.tf | 4 ++-- locals.tf | 2 ++ modules/api_gateway/rest_api.tf | 1 + modules/api_gateway/variables.tf | 6 ++++++ modules/role/role.tf | 2 +- modules/role/variables.tf | 4 ++-- multiple-lambdas-integration.tf | 2 ++ shared.tf | 4 ++-- variables.tf | 6 ++++++ 10 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 397dbfa..0e91573 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Terraform configuration used to create the required AWS resources for integratin | Name | Version | | ----------- | ----------- | -| [aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) | >= 4.37.0 | +| [aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) | >= 5.26.0 | ## Inputs @@ -152,3 +152,7 @@ module "spectral_lambda_integration" { 8. `lambda_iam_role_arn` - Amazon Resource Name (ARN) specifying the role. 9. `lambda_iam_role_name` - Name of the role. 10. `secrets_arns` - Arns of created secrets in secrets manager. + +## Support + +For GitHub deployment - only bot version 2.x is supported \ No newline at end of file diff --git a/examples/basic-github-integration.tf b/examples/basic-github-integration.tf index b5a945e..d6978a8 100644 --- a/examples/basic-github-integration.tf +++ b/examples/basic-github-integration.tf @@ -1,8 +1,8 @@ module "spectral_lambda_integration" { source = "github.com/SpectralOps/spectral-terraform-lambda-integration" - integration_type = "github" - lambda_enable_logs = true + integration_type = "github" + lambda_enable_logs = true # Use this attributes to deploy specific version of the bot frontend_lambda_source_code_path = "./source-code/github/github-frontend.zip" diff --git a/locals.tf b/locals.tf index 5479c8a..424502b 100644 --- a/locals.tf +++ b/locals.tf @@ -9,4 +9,6 @@ locals { "github" = coalesce(var.secrets_names, ["Spectral_GithubBot_GithubToken", "Spectral_GithubBot_WebhookSecret"]), "gitlab" = coalesce(var.secrets_names, ["Spectral_GitlabBot_GitlabToken", "Spectral_GitlabBot_WebhookSecret"]) } + # Please do not change or replace the 'frontend' suffix since there a logic in the bot based in it + function_name = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend" } \ No newline at end of file diff --git a/modules/api_gateway/rest_api.tf b/modules/api_gateway/rest_api.tf index a2629cc..cc32b6a 100644 --- a/modules/api_gateway/rest_api.tf +++ b/modules/api_gateway/rest_api.tf @@ -31,6 +31,7 @@ resource "aws_api_gateway_integration" "api_proxy_integration" { integration_http_method = "POST" type = "AWS_PROXY" uri = var.lambda_function_arn + timeout_milliseconds = var.gateway_api_integration_timeout_milliseconds } resource "aws_api_gateway_method_response" "response_200" { diff --git a/modules/api_gateway/variables.tf b/modules/api_gateway/variables.tf index 88c29d4..57b766d 100644 --- a/modules/api_gateway/variables.tf +++ b/modules/api_gateway/variables.tf @@ -39,4 +39,10 @@ variable "integration_type" { variable "function_name" { type = string description = "The name of the function the API would trigger upon request" +} + +variable "gateway_api_integration_timeout_milliseconds" { + description = "Timeout for the API Gateway to wait for lambda response" + type = number + default = 29000 } \ No newline at end of file diff --git a/modules/role/role.tf b/modules/role/role.tf index f2622fc..2dc1a88 100644 --- a/modules/role/role.tf +++ b/modules/role/role.tf @@ -13,7 +13,7 @@ data "aws_iam_policy_document" "assume_role_policy" { } resource "aws_iam_role" "lambda_execution_role" { - name = var.resource_name_pattern + name = var.role_name assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json tags = merge( diff --git a/modules/role/variables.tf b/modules/role/variables.tf index 645c53f..3f0e86e 100644 --- a/modules/role/variables.tf +++ b/modules/role/variables.tf @@ -27,9 +27,9 @@ variable "tags" { } } -variable "resource_name_pattern" { +variable "role_name" { type = string - description = "A common resource name created by pattern." + description = "The name of the role" } variable "multiple_lambda_integration" { diff --git a/multiple-lambdas-integration.tf b/multiple-lambdas-integration.tf index 9292f00..953f89d 100644 --- a/multiple-lambdas-integration.tf +++ b/multiple-lambdas-integration.tf @@ -5,6 +5,7 @@ module "frontend_lambda_function" { tags = var.tags environment = var.environment integration_type = var.integration_type + # Please do not change or replace the 'frontend' suffix since there a logic in the bot based in it resource_name_pattern = "${local.resource_name_pattern}-frontend" env_vars = var.env_vars logs_retention_in_days = var.lambda_logs_retention_in_days @@ -26,6 +27,7 @@ module "backend_lambda_function" { tags = var.tags environment = var.environment integration_type = var.integration_type + # Please do not change or replace the 'backend' suffix since there a logic in the bot based in it resource_name_pattern = "${local.resource_name_pattern}-backend" env_vars = var.env_vars logs_retention_in_days = var.lambda_logs_retention_in_days diff --git a/shared.tf b/shared.tf index e39efb8..6b6dbab 100644 --- a/shared.tf +++ b/shared.tf @@ -11,7 +11,7 @@ module "api_gateway" { environment = var.environment integration_type = var.integration_type resource_name_pattern = local.resource_name_pattern - function_name = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend" + function_name = local.function_name lambda_function_arn = local.api_triggered_function_arn } @@ -24,7 +24,7 @@ module "secrets_manager" { module "lambda_role" { source = "./modules/role" - resource_name_pattern = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend" + role_name = local.function_name store_secret_in_secrets_manager = var.store_secret_in_secrets_manager secrets_arns = var.store_secret_in_secrets_manager ? module.secrets_manager[0].secrets_arns : [] tags = var.tags diff --git a/variables.tf b/variables.tf index 8d57172..1c51d72 100644 --- a/variables.tf +++ b/variables.tf @@ -109,4 +109,10 @@ variable "secrets_names" { description = "Names of secrets to create" type = list(string) default = null +} + +variable "gateway_api_integration_timeout_milliseconds" { + description = "Timeout for the API Gateway to wait for lambda response" + type = number + default = 29000 } \ No newline at end of file