From 8790fb555b418eb932135a95a4b70511a31a8e1a Mon Sep 17 00:00:00 2001 From: zLukas Date: Wed, 11 Oct 2023 20:00:38 +0200 Subject: [PATCH] terraform modules test --- terraform/main.tf | 22 ++++++++++++ terraform/modules/lambda/main.tf | 2 ++ terraform/modules/lambda/variables.tf | 10 ++++++ terraform/outputs.tf | 7 ++++ terraform/test-event.json | 28 +++++++++++++++ terraform/variables.tf | 51 +++++++++++++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 terraform/main.tf create mode 100644 terraform/test-event.json diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..9cdc4d5 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,22 @@ +module certTable { + source ="./modules/dynamodb" + access_key = var.access_key + secret_key = var.secret_key + region = var.region + table_name = var.table_name + table_main_key = var.table_main_key + +} + +module certLambda { + source = "./modules/lambda" + access_key = var.access_key + secret_key = var.secret_key + region = var.region + lambda_name = var.lambda_name + zip_file = var.zip_file + lambda_iam_resources = [module.certTable.arn] + env_vars = var.env_vars + lambda_iam_actions = var.lambda_iam_actions + +} \ No newline at end of file diff --git a/terraform/modules/lambda/main.tf b/terraform/modules/lambda/main.tf index 1c7cdce..8b01d18 100644 --- a/terraform/modules/lambda/main.tf +++ b/terraform/modules/lambda/main.tf @@ -7,6 +7,8 @@ resource "aws_lambda_function" "lambda" { role = aws_iam_role.iam_for_lambda.arn handler = "bootstrap" runtime = "go1.x" + timeout = var.timeout + memory_size = var.memory_size environment { diff --git a/terraform/modules/lambda/variables.tf b/terraform/modules/lambda/variables.tf index 14583b8..31f1958 100644 --- a/terraform/modules/lambda/variables.tf +++ b/terraform/modules/lambda/variables.tf @@ -10,6 +10,16 @@ variable region { type = string } +variable timeout { + type = number + default = 30 +} + +variable memory_size { + type = number + default = 512 +} + variable lambda_name { type = string } diff --git a/terraform/outputs.tf b/terraform/outputs.tf index e69de29..7ee4699 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -0,0 +1,7 @@ +output "dynamodbTable"{ + value = module.certTable.arn +} + +output "Lambda"{ + value = module.certTable.arn +} \ No newline at end of file diff --git a/terraform/test-event.json b/terraform/test-event.json new file mode 100644 index 0000000..01c9868 --- /dev/null +++ b/terraform/test-event.json @@ -0,0 +1,28 @@ +{ + "requester": "me", + "caCert": { + "serial": 1, + "validForYears": 10, + "subject": { + "country": "PL", + "organization": "ChmurPol", + "organizationalUnit": "dzial certow", + "locality": "WD", + "commonName": "certhost jp2" + } + }, + "cert": { + "serial": 1, + "validForYears": 1, + "dnsNames": [ + "yellowhost.jp2" + ], + "subject": { + "country": "PL", + "organization": "ChmurPol", + "organizationalUnit": "dzial certow", + "locality": "WD", + "commonName": "creampie.jp2" + } + } + } \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index 18a9648..5e3404a 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,7 +1,58 @@ variable access_key { type = string + sensitive = true } variable secret_key { type = string + sensitive = true +} + +variable region { + type = string + default = "eu-central-1" +} + +variable table_name { + type = string + default = "certificates" +} + +variable table_main_key { + type = object({ + name = string + type = string + }) + default = { + name = "Name" + type = "S" +} +} + +variable lambda_name { + type = string + default = "CertLambda" +} + +variable env_vars { + type = map(string) + default = { + ENVIROMENT = "LAMBDA" + TABLE_NAME = "certificates" + DB_REGION = "eu-central-1" + } +} + +variable lambda_iam_actions { + type = list(string) + default = ["dynamodb:TagResource", + "dynamodb:PutItem", + "dynamodb:DescribeTable", + "dynamodb:DeleteItem", + "dynamodb:UpdateItem"] +} + +variable zip_file { + type = string + default = "bootstrap.zip" }