Skip to content

Commit cc97bcf

Browse files
Merge pull request #191 from NHSDigital/feature/CCM-7252_new-table
CCM-7252: Terraform changes for implementing database operations in templates API
2 parents 92b2d97 + 30c1472 commit cc97bcf

File tree

14 files changed

+1839
-9
lines changed

14 files changed

+1839
-9
lines changed

infrastructure/terraform/components/acct/iam_policy_github_deploy_overload.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ data "aws_iam_policy_document" "github_deploy" {
1818
"amplify:*",
1919
"cloudformation:*",
2020
"ses:*",
21+
"appsync:*"
2122
]
2223
resources = ["*"]
2324
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ resource "aws_lambda_function" "main" {
66
source_code_hash = var.source_code_hash
77
handler = var.handler
88
runtime = var.runtime
9+
10+
environment {
11+
variables = var.environment_variables
12+
}
913
}
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_kms_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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ 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+
}
16+
17+
execution_role_policy_document = data.aws_iam_policy_document.endpoint_lambda_dynamo_access.json
1218
}
1319

1420

@@ -19,3 +25,36 @@ module "endpoint_build" {
1925
entrypoint = "src/index.ts"
2026
}
2127

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

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)