Skip to content

Commit e16d0fd

Browse files
authored
Merge pull request #183 from NHSDigital/feature/CCM-7249_template-api-skeleton-squash
CCM-7249: empty templates API backend
2 parents 0c58a89 + c0e3291 commit e16d0fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9454
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# dependencies
1818
node_modules
19+
.node-version
1920
*/node_modules
2021
/.pnp
2122
.pnp.js
@@ -47,6 +48,7 @@ npm-debug.log*
4748
# typescript
4849
*.tsbuildinfo
4950
next-env.d.ts
51+
.swc
5052

5153
# reports
5254
reports

infrastructure/terraform/components/app/amplify_app.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ resource "aws_amplify_app" "main" {
2727
]
2828

2929
environment_variables = {
30-
NOTIFY_GROUP = var.group
31-
NOTIFY_ENVIRONMENT = var.environment
32-
NOTIFY_DOMAIN_NAME = local.root_domain_name
33-
ACCOUNT_ID = var.aws_account_id
34-
NEXT_PUBLIC_DISABLE_CONTENT = var.disable_content
30+
NOTIFY_GROUP = var.group
31+
NOTIFY_ENVIRONMENT = var.environment
32+
NOTIFY_DOMAIN_NAME = local.root_domain_name
33+
ACCOUNT_ID = var.aws_account_id
34+
NEXT_PUBLIC_DISABLE_CONTENT = var.disable_content
3535
}
3636
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module "templates_api" {
2+
source = "../../modules/templates-api"
3+
4+
project = var.project
5+
environment = var.environment
6+
aws_account_id = var.aws_account_id
7+
region = var.region
8+
group = var.group
9+
csi = local.csi
10+
log_retention_in_days = var.log_retention_in_days
11+
}

infrastructure/terraform/components/app/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ output "amplify" {
44
domain_name = local.root_domain_name
55
}
66
}
7+
8+
output "api_invoke_url" {
9+
value = module.templates_api.api_invoke_url
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "aws_cloudwatch_log_group" "lambda" {
2+
name = "/aws/lambda/${var.function_name}"
3+
retention_in_days = var.log_retention_in_days
4+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
resource "aws_iam_role" "lambda_execution_role" {
2+
name = "${var.function_name}-execution-role"
3+
description = "IAM Role for Lambda function ${var.function_name}"
4+
assume_role_policy = data.aws_iam_policy_document.lambda_service_trust_policy.json
5+
}
6+
7+
resource "aws_iam_role_policy" "lambda_execution_policy" {
8+
role = aws_iam_role.lambda_execution_role.name
9+
name = "${var.function_name}-execution-policy"
10+
policy = data.aws_iam_policy_document.lambda_execution_policy.json
11+
}
12+
13+
data "aws_iam_policy_document" "lambda_service_trust_policy" {
14+
statement {
15+
sid = "LambdaAssumeRole"
16+
effect = "Allow"
17+
18+
actions = [
19+
"sts:AssumeRole",
20+
]
21+
22+
principals {
23+
type = "Service"
24+
25+
identifiers = [
26+
"lambda.amazonaws.com"
27+
]
28+
}
29+
}
30+
}
31+
32+
data "aws_iam_policy_document" "lambda_execution_policy" {
33+
source_policy_documents = [
34+
var.execution_role_policy_document
35+
]
36+
37+
statement {
38+
sid = "AllowLogs"
39+
effect = "Allow"
40+
41+
actions = [
42+
"logs:CreateLogStream",
43+
"logs:PutLogEvents"
44+
]
45+
46+
resources = [
47+
"${aws_cloudwatch_log_group.lambda.arn}:log-stream:*",
48+
]
49+
}
50+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_lambda_function" "main" {
2+
description = var.description
3+
function_name = var.function_name
4+
role = aws_iam_role.lambda_execution_role.arn
5+
filename = var.filename
6+
source_code_hash = var.source_code_hash
7+
handler = var.handler
8+
runtime = var.runtime
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "function_arn" {
2+
value = aws_lambda_function.main.arn
3+
}
4+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
variable "description" {
2+
type = string
3+
description = "Description of what your Lambda Function does"
4+
}
5+
6+
variable "execution_role_policy_document" {
7+
type = string
8+
description = "IAM Policy Document containing additional runtime permissions for the Lambda function beyond the basic execution policy"
9+
default = ""
10+
}
11+
12+
variable "filename" {
13+
type = string
14+
description = "Path to the function's deployment package within the local filesystem"
15+
}
16+
17+
variable "function_name" {
18+
type = string
19+
description = "Unique name of the Lambda function"
20+
}
21+
22+
variable "source_code_hash" {
23+
type = string
24+
description = "Base64-encoded SHA256 hash of the package file specified by `filename`"
25+
}
26+
27+
variable "handler" {
28+
type = string
29+
description = "Function entrypoint in your code"
30+
}
31+
32+
variable "runtime" {
33+
type = string
34+
description = "Identifier of the function's runtime"
35+
default = "nodejs20.x"
36+
}
37+
38+
variable "log_retention_in_days" {
39+
type = number
40+
description = "Specifies the number of days you want to retain log events in the log group for this Lambda"
41+
default = 0
42+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "aws_api_gateway_deployment" "main" {
2+
rest_api_id = aws_api_gateway_rest_api.main.id
3+
description = "Templates API deployment"
4+
5+
triggers = {
6+
openapi_hash = sha1(jsonencode(local.openapi_spec)),
7+
}
8+
9+
variables = {
10+
deployed_at = timestamp()
11+
}
12+
13+
lifecycle {
14+
create_before_destroy = true
15+
}
16+
}

0 commit comments

Comments
 (0)