Skip to content

Commit

Permalink
update readme + mvoe logic to locals
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengaDev committed May 29, 2024
1 parent 6cb7f4d commit fda3e7c
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions examples/basic-github-integration.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
1 change: 1 addition & 0 deletions modules/api_gateway/rest_api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
6 changes: 6 additions & 0 deletions modules/api_gateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion modules/role/role.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions modules/role/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions multiple-lambdas-integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions shared.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit fda3e7c

Please sign in to comment.