Skip to content

Commit bf46c62

Browse files
committed
Merge branch 'main' into NDR-97
2 parents 7188637 + ab0925a commit bf46c62

File tree

6 files changed

+43
-94
lines changed

6 files changed

+43
-94
lines changed

.github/workflows/terraform-dev-to-main-ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ jobs:
7272
run: |
7373
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan > plan_output.txt 2>&1
7474
terraform show -no-color tf.plan > tfplan.txt 2>&1
75+
76+
# Mask PEM certificates (BEGIN...END CERTIFICATE)
77+
awk 'BEGIN{cert=""}
78+
/-----BEGIN CERTIFICATE-----/{cert=$0; in_cert=1; next}
79+
/-----END CERTIFICATE-----/{cert=cert"\n"$0; print cert; cert=""; in_cert=0; next}
80+
in_cert{cert=cert"\n"$0}' tfplan.txt | while IFS= read -r cert_block; do
81+
if [ -n "$cert_block" ]; then
82+
echo "::add-mask::$cert_block"
83+
fi
84+
done || echo "No certificate blocks found to mask."
7585
7686
# Mask sensitive URLs in the Terraform Plan output
7787
grep -Eo 'https://[a-zA-Z0-9.-]+\.execute-api\.[a-zA-Z0-9.-]+\.amazonaws\.com/[a-zA-Z0-9/._-]*' tfplan.txt | while read -r api_url; do
@@ -125,6 +135,7 @@ jobs:
125135
PLAN_FULL=$(echo "$PLAN_FULL" | sed -E 's/[0-9]{12}/[REDACTED_AWS_ACCOUNT_ID]/g')
126136
PLAN_FULL=$(echo "$PLAN_FULL" | sed -E 's#https://[a-zA-Z0-9.-]+\.lambda\.amazonaws\.com/[a-zA-Z0-9/._-]+#[REDACTED_LAMBDA_URL]#g')
127137
PLAN_FULL=$(echo "$PLAN_FULL" | sed -E 's#https://[a-zA-Z0-9.-]+\.execute-api\.[a-zA-Z0-9.-]+\.amazonaws\.com/[a-zA-Z0-9/._-]*#[REDACTED_API_GATEWAY_URL]#g')
138+
PLAN_FULL=$(echo "$PLAN_FULL" | sed -E '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/s/.*/[REDACTED_PEM_CERT]/')
128139
129140
echo "PLAN<<EOF" >> $GITHUB_ENV
130141
echo "${PLAN_FULL::$LENGTH}" >> $GITHUB_ENV

infrastructure/api.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,28 @@ resource "aws_api_gateway_stage" "ndr_api" {
9393
deployment_id = aws_api_gateway_deployment.ndr_api_deploy.id
9494
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
9595
stage_name = var.environment
96-
xray_tracing_enabled = false
96+
xray_tracing_enabled = var.enable_xray_tracing
97+
98+
depends_on = [aws_cloudwatch_log_group.api_gateway_stage]
99+
}
100+
101+
resource "aws_cloudwatch_log_group" "api_gateway_stage" {
102+
# Name must follow this format to allow execution logging
103+
# https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html
104+
name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.ndr_doc_store_api.id}/${var.environment}"
105+
retention_in_days = 0
106+
}
107+
108+
resource "aws_api_gateway_method_settings" "api_gateway_stage" {
109+
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
110+
stage_name = aws_api_gateway_stage.ndr_api.stage_name
111+
method_path = "*/*"
112+
113+
settings {
114+
logging_level = "INFO"
115+
metrics_enabled = true
116+
data_trace_enabled = true
117+
}
97118
}
98119

99120
resource "aws_api_gateway_gateway_response" "unauthorised_response" {
@@ -112,6 +133,10 @@ resource "aws_api_gateway_gateway_response" "unauthorised_response" {
112133
}
113134
}
114135

136+
resource "aws_api_gateway_client_certificate" "ndr_api" {
137+
description = "Client certificate used for backend authentication in HTTP integrations with the NDR API Gateway (${var.environment})"
138+
}
139+
115140
resource "aws_api_gateway_gateway_response" "bad_gateway_response" {
116141
rest_api_id = aws_api_gateway_rest_api.ndr_doc_store_api.id
117142
response_type = "DEFAULT_5XX"

infrastructure/modules/cloudwatch/README.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

infrastructure/modules/cloudwatch/main.tf

Lines changed: 0 additions & 22 deletions
This file was deleted.

infrastructure/modules/cloudwatch/variable.tf

Lines changed: 0 additions & 34 deletions
This file was deleted.

infrastructure/variable.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,10 @@ variable "cloud_security_console_public_address" {
217217
type = string
218218
default = "0.0.0.0/0"
219219
description = "Using public address to make sure CloudStorageSecurity console is available"
220+
}
221+
222+
variable "enable_xray_tracing" {
223+
description = "Enable AWS X-Ray tracing for the API Gateway stage"
224+
type = bool
225+
default = false
220226
}

0 commit comments

Comments
 (0)