Skip to content

Commit d59a98f

Browse files
Add dynamo table
1 parent 92b2d97 commit d59a98f

File tree

12 files changed

+1832
-9
lines changed

12 files changed

+1832
-9
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
output "function_arn" {
22
value = aws_lambda_function.main.arn
33
}
4-

infrastructure/terraform/modules/lambda-function/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ variable "log_retention_in_days" {
4040
description = "Specifies the number of days you want to retain log events in the log group for this Lambda"
4141
default = 0
4242
}
43+
44+
variable "environment_variables" {
45+
type = map(string)
46+
description = "Lambda environment variables"
47+
default = {}
48+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
resource "aws_dynamodb_table" "templates" {
2+
name = "${local.csi}-templates"
3+
billing_mode = "PAY_PER_REQUEST"
4+
5+
hash_key = "owner"
6+
range_key = "id"
7+
8+
attribute {
9+
name = "owner"
10+
type = "S"
11+
}
12+
13+
attribute {
14+
name = "id"
15+
type = "S"
16+
}
17+
18+
point_in_time_recovery {
19+
enabled = true
20+
}
21+
22+
server_side_encryption {
23+
enabled = true
24+
kms_key_arn = aws_key_key.dynamo.arn
25+
}
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "aws_kms_key" "dynamo" {
2+
description = "CMK for encrypting dynamodb data"
3+
deletion_window_in_days = 14
4+
enable_key_rotation = true
5+
}

infrastructure/terraform/modules/templates-api/module_authorizer_lambda.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ module "authorizer_build" {
1717
source_code_dir = "${local.lambdas_source_code_dir}/authorizer"
1818
entrypoint = "src/index.ts"
1919
}
20-

infrastructure/terraform/modules/templates-api/module_endpoint_lambda.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ module "endpoint_lambda" {
99
handler = "index.handler"
1010

1111
log_retention_in_days = var.log_retention_in_days
12+
13+
environment_variables = {
14+
TEMPLATES_TABLE_NAME = aws_dynamodb_table.templates.name
15+
}
1216
}
1317

1418

@@ -19,3 +23,36 @@ module "endpoint_build" {
1923
entrypoint = "src/index.ts"
2024
}
2125

26+
data "aws_iam_policy_document" "endpoint_lambda_dynamo_access" {
27+
statement {
28+
sid = "AllowDynamoAccess"
29+
effect = "Allow"
30+
31+
actions = [
32+
"dynamodb:GetItem",
33+
"dynamodb:PutItem",
34+
"dynamodb:Query"
35+
]
36+
37+
resources = [
38+
aws_dynamodb_table.templates.arn,
39+
]
40+
}
41+
42+
statement {
43+
sid = "AllowKMSAccess"
44+
effect = "Allow"
45+
46+
actions = [
47+
"kms:Decrypt",
48+
"kms:DescribeKey",
49+
"kms:Encrypt",
50+
"kms:GenerateDataKey*",
51+
"kms:ReEncrypt*",
52+
]
53+
54+
resources = [
55+
aws_kms_key.dynamo.arn
56+
]
57+
}
58+
}

infrastructure/terraform/modules/typescript-build-zip/null_resource_typescript_build.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ resource "null_resource" "typescript_build" {
88
command = "npm ci && npm run build"
99
}
1010
}
11-

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const config: Config = {
7878
'fixture',
7979
'helpers.ts',
8080
'/tests/test-team/',
81+
'.build'
8182
],
8283

8384
// Set the absolute path for imports

0 commit comments

Comments
 (0)