Skip to content

Commit

Permalink
Automatic lambda creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslinnell committed Oct 11, 2023
1 parent cf04aaf commit ddfc095
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 18 deletions.
9 changes: 9 additions & 0 deletions infrastructure/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "layers_list" {
value = var.layers
}

output "layer_arns" {
value = {
for key, instance in module.layers : key => instance.layer_arn
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"filename": "builds/2bb3f59d20d8950f4a08c332ac09c0e5d3b49167b15a76a7ce500e4642596b06.zip",
"runtime": "",
"artifacts_dir": "builds",
"build_plan": [
[
"zip",
"modules/api_worker/api_layer/../../../../../../src/layers/event/dist/event.zip",
null
]
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"filename": "builds/7052fb68d98cab7aab868d0610ae3444723177fce349e3a8727003fb8b74897d.zip",
"runtime": "",
"artifacts_dir": "builds",
"build_plan": [
[
"zip",
"modules/api_worker/api_layer/../../../../../../src/layers/third_party/dist/third_party.zip",
null
]
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"filename": "builds/a1e39abba50d099b76d78d430066b9778af9131a5dfd167cd3b340d7c38c2100.zip",
"runtime": "",
"artifacts_dir": "builds",
"build_plan": [
[
"zip",
"modules/api_worker/api_layer/../../../../../../src/layers/domain/dist/domain.zip",
null
]
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"filename": "builds/c43f8c22d15b1aaf961e31c2b3923f871f617ec47a2cfa9aae3e63ea434f1d23.zip",
"runtime": "",
"artifacts_dir": "builds",
"build_plan": [
[
"zip",
"modules/api_worker/api_layer/../../../../../../src/layers/repository/dist/repository.zip",
null
]
]
}
Binary file not shown.
4 changes: 4 additions & 0 deletions infrastructure/terraform/per_workspace/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ locals {
region = "eu-west-2"
project = "nhse-cpm"
current_time = timestamp()
# layer_directories = fileset("${path.module}/..", "*")
# #layer_list = [for dir in local.layer_directories : dir]
# layer_list = split("\n", data.external.directories.result)
# layer_map = { for idx, dir in local.layer_list : idx => dir}
}
22 changes: 19 additions & 3 deletions infrastructure/terraform/per_workspace/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ module "products_table" {
kms_deletion_window_in_days = 7
}

module "layers" {
for_each = toset(var.layers)
source = "./modules/api_worker/api_layer"
name = each.key
layer_name = "${local.project}--${replace(terraform.workspace, "_", "-")}--${replace(each.key, "_", "-")}-lambda-layer"
}

module "lambdas" {
for_each = toset(var.lambdas)
source = "./modules/api_worker/api_lambda"
name = each.key
lambda_name = "${local.project}--${replace(terraform.workspace, "_", "-")}--${replace(each.key, "_", "-")}-lambda"
}


# module "api_worker_create" {
# source = "./modules/api_worker"
# name = "${local.project}--${replace(terraform.workspace, "_", "-")}--lambdaGETReadproduct"
# }

# module "api_worker_read" {
# source = "./modules/api_worker"
# name = "${local.project}--${replace(terraform.workspace, "_", "-")}--lambdaGETReadproduct"
# module "api_worker_createProduct" {
# source = "./modules/api_worker"
# name = "${local.project}--${replace(terraform.workspace, "_", "-")}--lambdacreateProduct"
# lambda_name = "createProduct"
# }

# module "api_entrypoint_owner" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "lambda_function" {
source = "terraform-aws-modules/lambda/aws"
version = "6.0.0"

function_name = var.lambda_name
description = "${replace(var.name, "_", "-")} lambda function"
handler = "src.api.${var.name}.index.handler"
runtime = var.python_version

source_path = "${path.module}/../../../../../src/api/${var.name}/dist/${var.name}.zip"

tags = {
Name = replace(var.name, "_", "-")
}

# layers = [
# module.
# ]

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
variable "name" {}

variable "handler" {}

variable "python_version" {
default = "python3.11"
}

variable "source_path" {}
variable "lambda_name" {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module "lambda_layer" {
source = "terraform-aws-modules/lambda/aws"
version = "6.0.0"

create_layer = true

layer_name = var.layer_name
description = "${replace(var.name, "_", "-")} lambda layer"
compatible_runtimes = [var.python_version]

source_path = "${path.module}/../../../../../../src/layers/${var.name}/dist/${var.name}.zip"

tags = {
Name = replace(var.name, "_", "-")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "layer_arn" {
value = module.lambda_layer.lambda_layer_arn
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "layer_name" {}

variable "python_version" {
default = "python3.11"
}

variable "name" {}

This file was deleted.

9 changes: 9 additions & 0 deletions infrastructure/terraform/per_workspace/modules/sqs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "sqs" {
source = "terraform-aws-modules/sqs/aws"

name = var.name

tags = {
Environment = "dev"
}
}
3 changes: 3 additions & 0 deletions infrastructure/terraform/per_workspace/modules/sqs/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "name" {

}
12 changes: 12 additions & 0 deletions infrastructure/terraform/per_workspace/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ variable "expiration_date" {
variable "updated_date" {
default = "NEVER"
}

variable "layers_directory" {
default = "../src/layers"
}

variable "layers" {
type = list(string)
}

variable "lambdas" {
type = list(string)
}

0 comments on commit ddfc095

Please sign in to comment.