Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengaDev committed May 1, 2024
1 parent b1f91e0 commit 2e72689
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
6 changes: 4 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
locals {
resource_name_pattern = "spectral-${var.integration_type}-integration-${var.environment}"
resource_name_pattern = "${coalesce(var.resource_name_common_part, "spectral-${var.integration_type}-integration-${var.environment}")}-${random_string.random_resource_name_suffix.id}"
single_lambda_integration = contains(["jira", "terraform"], var.integration_type) ? true : false
multiple_lambda_integration = contains(["gitlab"], var.integration_type) ? true : false
multiple_lambda_integration = contains(["gitlab", "github"], var.integration_type) ? true : false
api_triggered_function_arn = local.single_lambda_integration ? module.lambda_function[0].lambda_function_arn : module.frontend_lambda_function[0].lambda_function_arn
frontend_lambda_handler = contains(["github"], var.integration_type) ? "index.handler" : "frontend.app"
backend_lambda_handler = contains(["github"], var.integration_type) ? "index.handler" : "backend.app"
}
4 changes: 2 additions & 2 deletions modules/lambda/lambda.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
runtime = "nodejs14.x"
lambda_source_code_zip_path = "${path.module}/source_code/${var.integration_type}/${var.lambda_source_code_filename}"
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}"
}

resource "aws_lambda_function" "spectral_scanner_lambda" {
Expand Down
5 changes: 5 additions & 0 deletions modules/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ variable "lambda_source_code_filename" {
description = "The lambda source code filename"
}

variable "lambda_source_code_path" {
type = string
description = "The lambda source code path"
}

variable "role_arn" {
type = string
description = "The lambda source code filename"
Expand Down
6 changes: 4 additions & 2 deletions multiple-lambdas-integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ module "frontend_lambda_function" {
env_vars = var.env_vars
logs_retention_in_days = var.lambda_logs_retention_in_days
should_write_logs = var.lambda_enable_logs
lambda_handler = "frontend.app"
lambda_handler = local.frontend_lambda_handler
timeout = var.lambda_function_timeout
memory_size = var.lambda_function_memory_size
publish = var.lambda_publish
secrets_arns = var.store_secret_in_secrets_manager ? module.secrets_manager[0].secrets_arns : []
store_secret_in_secrets_manager = var.store_secret_in_secrets_manager
lambda_source_code_filename = "frontend.zip"
lambda_source_code_path = var.frontend_lambda_source_code_path
role_arn = module.lambda_role.lambda_role_arn
}

Expand All @@ -30,13 +31,14 @@ module "backend_lambda_function" {
env_vars = var.env_vars
logs_retention_in_days = var.lambda_logs_retention_in_days
should_write_logs = var.lambda_enable_logs
lambda_handler = "backend.app"
lambda_handler = local.backend_lambda_handler
timeout = var.lambda_function_timeout
memory_size = var.lambda_function_memory_size
publish = var.lambda_publish
secrets_arns = var.store_secret_in_secrets_manager ? module.secrets_manager[0].secrets_arns : []
store_secret_in_secrets_manager = var.store_secret_in_secrets_manager
lambda_source_code_filename = "backend.zip"
lambda_source_code_path = var.backend_lambda_source_code_path
role_arn = module.lambda_role.lambda_role_arn
}

Expand Down
10 changes: 8 additions & 2 deletions shared.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
resource "random_string" "random_resource_name_suffix" {
length = 10
special = false
upper = false
}

module "api_gateway" {
source = "./modules/api_gateway"
global_tags = var.global_tags
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.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend-${random_string.random_resource_name_suffix.id}"
lambda_function_arn = local.api_triggered_function_arn
}

Expand All @@ -16,7 +22,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"
resource_name_pattern = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend-${random_string.random_resource_name_suffix.id}"
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
1 change: 1 addition & 0 deletions single-lambda-integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module "lambda_function" {
secrets_arns = var.store_secret_in_secrets_manager ? module.secrets_manager[0].secrets_arns : []
store_secret_in_secrets_manager = var.store_secret_in_secrets_manager
lambda_source_code_filename = "app.zip"
lambda_source_code_path = var.lambda_source_code_path
role_arn = module.lambda_role.lambda_role_arn
}
20 changes: 20 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ variable "integration_type" {
}
}

variable "lambda_source_code_path" {
type = string
description = "Path to the lambda source code zip file"
}

variable "frontend_lambda_source_code_path" {
type = string
description = "Path to the lambda source code zip file of the frontend lambda"
}

variable "backend_lambda_source_code_path" {
type = string
description = "Path to the lambda source code zip file of the backend lambda"
}

variable "environment" {
type = string
description = "The target environment name for deployment."
Expand Down Expand Up @@ -79,4 +94,9 @@ variable "store_secret_in_secrets_manager" {
type = bool
description = "Whether to store your secrets in secrets manager, default is false"
default = false
}

variable "resource_name_common_part" {
type = string
description = "A common part for all resources created under the stack"
}

0 comments on commit 2e72689

Please sign in to comment.