Skip to content

Commit

Permalink
terraform modules test
Browse files Browse the repository at this point in the history
  • Loading branch information
zLukas committed Oct 11, 2023
1 parent 9489afa commit 8790fb5
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
22 changes: 22 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -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

}
2 changes: 2 additions & 0 deletions terraform/modules/lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions terraform/modules/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "dynamodbTable"{
value = module.certTable.arn
}

output "Lambda"{
value = module.certTable.arn
}
28 changes: 28 additions & 0 deletions terraform/test-event.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
51 changes: 51 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 8790fb5

Please sign in to comment.