Skip to content

Commit ec65ea0

Browse files
committed
feat: Add Mock PDS Lambda and ECR repository configuration
- Introduced a new Mock PDS Lambda function to simulate PDS responses. - Created an ECR repository for the Mock PDS service with appropriate policies. - Updated deployment workflows to include mock_pds in build flags and image overrides. - Enhanced infrastructure configuration to support the new Mock PDS service, including image URI handling and environment variable setup.
1 parent d7692be commit ec65ea0

6 files changed

Lines changed: 59 additions & 86 deletions

File tree

.github/workflows/deploy-backend.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
lambda_build_flags:
1010
description: >
1111
JSON map of lambda_name -> force-build flag.
12-
e.g. {"recordprocessor":true,"ack-backend":false}
12+
e.g. {"recordprocessor":true,"ack-backend":false,"mock_pds":false}
1313
required: false
1414
type: string
1515
default: "{}"
@@ -73,14 +73,14 @@ on:
7373
lambda_build_flags:
7474
description: >
7575
JSON map of lambda_name -> force-build flag.
76-
e.g. {"recordprocessor":true,"ack-backend":false}
76+
e.g. {"recordprocessor":true,"ack-backend":false,"mock_pds":false}
7777
required: false
7878
type: string
7979
default: "{}"
8080
lambda_image_overrides:
8181
description: >
8282
JSON map of lambda_name -> immutable image selector for reuse mode.
83-
e.g. {"recordprocessor":"internal-dev-git-abc123","ack-backend":"123456789012.dkr.ecr.eu-west-2.amazonaws.com/imms-ackbackend-repo@sha256:..."}
83+
e.g. {"recordprocessor":"internal-dev-git-abc123","ack-backend":"123456789012.dkr.ecr.eu-west-2.amazonaws.com/imms-ackbackend-repo@sha256:...","mock_pds":"123456789012.dkr.ecr.eu-west-2.amazonaws.com/imms-mock-pds-repo@sha256:..."}
8484
required: false
8585
type: string
8686
default: "{}"
@@ -130,6 +130,12 @@ jobs:
130130
dockerfile_path: lambdas/ack_backend/Dockerfile
131131
lambda_paths: |
132132
lambdas/ack_backend/
133+
- lambda_name: mock_pds
134+
tf_var_suffix: mock_pds
135+
ecr_repository: imms-mock-pds-repo
136+
dockerfile_path: lambdas/mock_pds/Dockerfile
137+
lambda_paths: |
138+
lambdas/mock_pds/
133139
uses: ./.github/workflows/deploy-lambda-artifact.yml
134140
with:
135141
lambda_name: ${{ matrix.lambda_name }}

.github/workflows/pr-deploy-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
apigee_environment: internal-dev
2323
lambda_build_flags: >-
2424
${{ (github.event.action == 'opened' || github.event.action == 'reopened')
25-
&& '{"recordprocessor":true,"ack-backend":true}'
25+
&& '{"recordprocessor":true,"ack-backend":true,"mock_pds":true}'
2626
|| '{}' }}
2727
diff_base_sha: ${{ github.event.action == 'synchronize' && github.event.before || github.event.pull_request.base.sha }}
2828
diff_head_sha: ${{ github.event.pull_request.head.sha }}

.github/workflows/pr-teardown.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
}
5656
echo "TF_VAR_recordprocessor_image_uri=$(resolve_or_placeholder recordprocessor_image_uri imms-recordprocessor-repo)" >> $GITHUB_ENV
5757
echo "TF_VAR_ack_backend_image_uri=$(resolve_or_placeholder ack_backend_image_uri imms-ackbackend-repo)" >> $GITHUB_ENV
58+
echo "TF_VAR_mock_pds_image_uri=$(resolve_or_placeholder mock_pds_image_uri imms-mock-pds-repo)" >> $GITHUB_ENV
5859
5960
- name: Install poetry
6061
run: pip install poetry==2.1.4
@@ -129,6 +130,6 @@ jobs:
129130
--output json
130131
}
131132
132-
for repository_name in imms-recordprocessor-repo imms-ackbackend-repo; do
133+
for repository_name in imms-recordprocessor-repo imms-ackbackend-repo imms-mock-pds-repo; do
133134
cleanup_repo_by_prefix "${repository_name}"
134135
done
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
resource "aws_ecr_repository" "mock_pds_repository" {
2+
image_scanning_configuration {
3+
scan_on_push = true
4+
}
5+
image_tag_mutability = "IMMUTABLE"
6+
name = "imms-mock-pds-repo"
7+
}
8+
9+
resource "aws_ecr_repository_policy" "mock_pds_repository_lambda_image_retrieval_policy" {
10+
repository = aws_ecr_repository.mock_pds_repository.name
11+
12+
policy = jsonencode({
13+
Version = "2012-10-17"
14+
Statement = [
15+
{
16+
Sid = "LambdaECRImageRetrievalPolicy"
17+
Effect = "Allow"
18+
Principal = {
19+
Service = "lambda.amazonaws.com"
20+
}
21+
Action = [
22+
"ecr:BatchGetImage",
23+
"ecr:GetDownloadUrlForLayer"
24+
]
25+
Condition = {
26+
StringLike = {
27+
"aws:sourceArn" = "arn:aws:lambda:${var.aws_region}:${var.imms_account_id}:function:imms-*-mock-pds-lambda"
28+
}
29+
}
30+
}
31+
]
32+
})
33+
}

infrastructure/instance/mock_pds.tf

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,6 @@
11
locals {
2-
mock_pds_lambda_dir = abspath("${path.root}/../../lambdas/mock_pds")
3-
mock_pds_lambda_files = fileset(local.mock_pds_lambda_dir, "**")
4-
mock_pds_lambda_dir_sha = sha1(join("", [for f in local.mock_pds_lambda_files : filesha1("${local.mock_pds_lambda_dir}/${f}")]))
5-
mock_pds_lambda_name = "${local.short_prefix}-mock-pds-lambda"
6-
mock_pds_base_url = var.mock_pds_enabled ? "${aws_lambda_function_url.mock_pds_lambda_url[0].function_url}Patient" : ""
7-
}
8-
9-
resource "aws_ecr_repository" "mock_pds_lambda_repository" {
10-
count = var.mock_pds_enabled ? 1 : 0
11-
12-
image_scanning_configuration {
13-
scan_on_push = true
14-
}
15-
16-
name = "${local.short_prefix}-mock-pds-repo"
17-
force_delete = local.is_temp
18-
}
19-
20-
module "mock_pds_docker_image" {
21-
count = var.mock_pds_enabled ? 1 : 0
22-
23-
source = "terraform-aws-modules/lambda/aws//modules/docker-build"
24-
version = "8.7.0"
25-
docker_file_path = "./mock_pds/Dockerfile"
26-
create_ecr_repo = false
27-
ecr_repo = aws_ecr_repository.mock_pds_lambda_repository[0].name
28-
ecr_repo_lifecycle_policy = jsonencode({
29-
"rules" : [
30-
{
31-
"rulePriority" : 1,
32-
"description" : "Keep only the last 2 images",
33-
"selection" : {
34-
"tagStatus" : "any",
35-
"countType" : "imageCountMoreThan",
36-
"countNumber" : 2
37-
},
38-
"action" : {
39-
"type" : "expire"
40-
}
41-
}
42-
]
43-
})
44-
45-
platform = "linux/amd64"
46-
use_image_tag = false
47-
source_path = abspath("${path.root}/../../lambdas")
48-
triggers = {
49-
dir_sha = local.mock_pds_lambda_dir_sha
50-
}
51-
}
52-
53-
resource "aws_ecr_repository_policy" "mock_pds_lambda_ecr_image_retrieval_policy" {
54-
count = var.mock_pds_enabled ? 1 : 0
55-
56-
repository = aws_ecr_repository.mock_pds_lambda_repository[0].name
57-
58-
policy = jsonencode({
59-
Version = "2012-10-17"
60-
Statement = [
61-
{
62-
"Sid" : "LambdaECRImageRetrievalPolicy",
63-
"Effect" : "Allow",
64-
"Principal" : {
65-
"Service" : "lambda.amazonaws.com"
66-
},
67-
"Action" : [
68-
"ecr:BatchGetImage",
69-
"ecr:DeleteRepositoryPolicy",
70-
"ecr:GetDownloadUrlForLayer",
71-
"ecr:GetRepositoryPolicy",
72-
"ecr:SetRepositoryPolicy"
73-
],
74-
"Condition" : {
75-
"StringLike" : {
76-
"aws:sourceArn" : "arn:aws:lambda:${var.aws_region}:${var.immunisation_account_id}:function:${local.mock_pds_lambda_name}"
77-
}
78-
}
79-
}
80-
]
81-
})
2+
mock_pds_lambda_name = "${local.short_prefix}-mock-pds-lambda"
3+
mock_pds_base_url = var.mock_pds_enabled ? "${aws_lambda_function_url.mock_pds_lambda_url[0].function_url}Patient" : ""
824
}
835

846
resource "aws_iam_role" "mock_pds_lambda_exec_role" {
@@ -174,7 +96,7 @@ resource "aws_lambda_function" "mock_pds_lambda" {
17496
function_name = local.mock_pds_lambda_name
17597
role = aws_iam_role.mock_pds_lambda_exec_role[0].arn
17698
package_type = "Image"
177-
image_uri = module.mock_pds_docker_image[0].image_uri
99+
image_uri = var.mock_pds_image_uri
178100
architectures = ["x86_64"]
179101
timeout = 30
180102

infrastructure/instance/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ variable "ack_backend_image_uri" {
161161
}
162162
}
163163

164+
variable "mock_pds_image_uri" {
165+
description = "Immutable URI of the mock PDS Lambda container image in ECR. Required when mock_pds_enabled is true; supplied by CI/CD."
166+
type = string
167+
default = ""
168+
169+
validation {
170+
condition = !var.mock_pds_enabled || trimspace(var.mock_pds_image_uri) != ""
171+
error_message = "mock_pds_image_uri must be provided when mock_pds_enabled is true."
172+
}
173+
}
174+
164175
locals {
165176
prefix = "${var.project_name}-${var.service}-${var.sub_environment}"
166177
short_prefix = "${var.project_short_name}-${var.sub_environment}"

0 commit comments

Comments
 (0)