Skip to content

Commit 48febb0

Browse files
CCM-10927 Adding Hello World API (#50)
* CCM-10927 Adding Hello World API * CCM-10927 Fix line endings * CCM-10927 Fix line endings * CCM-10922 Adding sample authorizer * CCM-10922 Fix TFDocs * CCM-10927 Fix dynamic env component * CCM-10927 Fix stage name * CCM-10922 Fix default stage name * CCM-10922 Fix default stage name * CCM-10922 fix header case * CCM-10922 fix header case * CCM-11007: Adding log subscription for Splunk forwarding --------- Co-authored-by: sidnhs <[email protected]>
1 parent 6f594c3 commit 48febb0

33 files changed

+739
-7567
lines changed

.github/workflows/pr_create_dynamic_env.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ jobs:
2323
DISPATCH_EVENT=$(jq -ncM \
2424
--arg infraRepoName "${this_repo_name}" \
2525
--arg releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
26+
--arg targetProject "nhs" \
2627
--arg targetEnvironment "pr${{ github.event.number }}" \
2728
--arg targetAccountGroup "nhs-notify-supplier-api-dev" \
28-
--arg targetComponent "branch" \
29+
--arg targetComponent "api" \
2930
--arg terraformAction "apply" \
3031
--arg overrides "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
3132
'{ "ref": "main",

.github/workflows/pr_destroy_dynamic_env.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ jobs:
2323
DISPATCH_EVENT=$(jq -ncM \
2424
--arg infraRepoName "${this_repo_name}" \
2525
--arg releaseVersion "main" \
26+
--arg targetProject "nhs" \
2627
--arg targetEnvironment "pr${{ github.event.number }}" \
2728
--arg targetAccountGroup "nhs-notify-supplier-api-dev" \
28-
--arg targetComponent "branch" \
29+
--arg targetComponent "api" \
2930
--arg terraformAction "destroy" \
3031
'{ "ref": "main",
3132
"inputs": {

.tool-versions

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ act 0.2.64
22
gitleaks 8.24.0
33
jq 1.6
44
nodejs 22.11.0
5-
pnpm 10.4.1
65
pre-commit 3.6.0
76
python 3.13.2
87
terraform 1.9.2

infrastructure/terraform/components/api/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,24 @@ No requirements.
1515
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
1616
| <a name="input_force_lambda_code_deploy"></a> [force\_lambda\_code\_deploy](#input\_force\_lambda\_code\_deploy) | If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development | `bool` | `false` | no |
1717
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonmous with account short-name) | `string` | n/a | yes |
18+
| <a name="input_kms_deletion_window"></a> [kms\_deletion\_window](#input\_kms\_deletion\_window) | When a kms key is deleted, how long should it wait in the pending deletion state? | `string` | `"30"` | no |
19+
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | The log level to be used in lambda functions within the component. Any log with a lower severity than the configured value will not be logged: https://docs.python.org/3/library/logging.html#levels | `string` | `"INFO"` | no |
1820
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
21+
| <a name="input_parent_acct_environment"></a> [parent\_acct\_environment](#input\_parent\_acct\_environment) | Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments | `string` | `"main"` | no |
1922
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
2023
| <a name="input_region"></a> [region](#input\_region) | The AWS Region | `string` | n/a | yes |
2124
## Modules
2225

23-
No modules.
26+
| Name | Source | Version |
27+
|------|--------|---------|
28+
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
29+
| <a name="module_hello_world"></a> [hello\_world](#module\_hello\_world) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
30+
| <a name="module_kms"></a> [kms](#module\_kms) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/kms | v2.0.10 |
2431
## Outputs
2532

26-
No outputs.
33+
| Name | Description |
34+
|------|-------------|
35+
| <a name="output_api_urll"></a> [api\_urll](#output\_api\_urll) | n/a |
2736
<!-- vale on -->
2837
<!-- markdownlint-enable -->
2938
<!-- END_TF_DOCS -->
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 = "Suppliers UI 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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "aws_api_gateway_method_settings" "main" {
2+
rest_api_id = aws_api_gateway_rest_api.main.id
3+
stage_name = aws_api_gateway_stage.main.stage_name
4+
method_path = "*/*"
5+
6+
settings {
7+
metrics_enabled = true
8+
logging_level = "INFO"
9+
data_trace_enabled = true
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "aws_api_gateway_rest_api" "main" {
2+
name = local.csi
3+
body = local.openapi_spec
4+
description = "Suppliers API"
5+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
resource "aws_api_gateway_stage" "main" {
2+
stage_name = "main" # This is the default stage name for API Gateway
3+
description = "Templates API stage ${var.environment}"
4+
rest_api_id = aws_api_gateway_rest_api.main.id
5+
deployment_id = aws_api_gateway_deployment.main.id
6+
7+
access_log_settings {
8+
destination_arn = aws_cloudwatch_log_group.api_gateway_access.arn
9+
10+
# Context variables reference - https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference
11+
format = jsonencode({
12+
"accountId" : "$context.accountId"
13+
"apiId" : "$context.apiId"
14+
"authorize" : {
15+
"error" : "$context.authorize.error"
16+
"latency" : "$context.authorize.latency"
17+
"status" : "$context.authorize.status"
18+
}
19+
"authorizer" : {
20+
"error" : "$context.authorizer.error"
21+
"integrationLatency" : "$context.authorizer.integrationLatency"
22+
"integrationStatus" : "$context.authorizer.integrationStatus"
23+
"latency" : "$context.authorizer.latency"
24+
"principalId" : "$context.authorizer.principalId"
25+
"requestId" : "$context.authorizer.requestId"
26+
"status" : "$context.authorizer.status"
27+
}
28+
"awsEndpointRequestId" : "$context.awsEndpointRequestId"
29+
"deploymentId" : "$context.deploymentId"
30+
"domainName" : "$context.domainName"
31+
"domainPrefix" : "$context.domainPrefix"
32+
"endpointType" : "$context.endpointType"
33+
"error" : {
34+
"message" : "$context.error.message"
35+
"responseType" : "$context.error.responseType"
36+
"validationErrorString" : "$context.error.validationErrorString"
37+
}
38+
"extendedRequestId" : "$context.extendedRequestId"
39+
"httpMethod" : "$context.httpMethod"
40+
"identity" : {
41+
"sourceIp" : "$context.identity.sourceIp"
42+
"userAgent" : "$context.identity.userAgent"
43+
}
44+
"integration" : {
45+
"error" : "$context.integration.error"
46+
"integrationStatus" : "$context.integration.integrationStatus"
47+
"latency" : "$context.integration.latency"
48+
"requestId" : "$context.integration.requestId"
49+
"status" : "$context.integration.status"
50+
}
51+
"path" : "$context.path"
52+
"protocol" : "$context.protocol"
53+
"requestId" : "$context.requestId"
54+
"requestTime" : "$context.requestTime"
55+
"requestTimeEpoch" : "$context.requestTimeEpoch"
56+
"responseLatency" : "$context.responseLatency"
57+
"responseLength" : "$context.responseLength"
58+
"resourceId" : "$context.resourceId"
59+
"resourcePath" : "$context.resourcePath"
60+
"stage" : "$context.stage"
61+
"status" : "$context.status"
62+
})
63+
}
64+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "aws_cloudwatch_log_group" "api_gateway_access" {
2+
name = "/aws/api-gateway/${aws_api_gateway_rest_api.main.id}/${var.environment}/access-logs"
3+
retention_in_days = var.log_retention_in_days
4+
}
5+
6+
resource "aws_cloudwatch_log_subscription_filter" "api_gateway_access" {
7+
name = replace(aws.cloudwatch_log_group.api_gateway_access.name, "/", "-")
8+
role_arn = local.acct.log_subscription_role_arn
9+
log_group_name = aws_cloudwatch_log_group.api_gateway_access.name
10+
filter_pattern = ""
11+
destination_arn = local.destination_arn
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "aws_cloudwatch_log_group" "api_gateway_execution" {
2+
name = format("API-Gateway-Execution-Logs_%s/%s",
3+
aws_api_gateway_rest_api.main.id,
4+
var.environment,
5+
)
6+
retention_in_days = var.log_retention_in_days
7+
}
8+
9+
resource "aws_cloudwatch_log_subscription_filter" "api_gateway_execution" {
10+
name = replace(aws.cloudwatch_log_group.api_gateway_access.name, "/", "-")
11+
role_arn = local.acct.log_subscription_role_arn
12+
log_group_name = aws_cloudwatch_log_group.api_gateway_access.name
13+
filter_pattern = ""
14+
destination_arn = local.destination_arn
15+
}

0 commit comments

Comments
 (0)