11# Define the directory containing the Docker image and calculate its SHA-256 hash for triggering redeployments
22locals {
3- lambdas_dir = abspath (" ${ path . root } /../lambdas" )
4- shared_dir = " ${ local . lambdas_dir } /shared"
5- id_sync_lambda_dir = " ${ local . lambdas_dir } /id_sync"
6- id_sync_dockerfile = " ${ local . lambdas_dir } /id_sync.Dockerfile"
7-
8- # Get files from both directories
9- shared_files = fileset (local. shared_dir , " **" )
3+ id_sync_lambda_dir = abspath (" ${ path . root } /../id_sync" )
104 id_sync_lambda_files = fileset (local. id_sync_lambda_dir , " **" )
11-
12- # Calculate SHA for both directories
13- shared_dir_sha = sha1 (join (" " , [for f in local . shared_files : filesha1 (" ${ local . shared_dir } /${ f } " )]))
145 id_sync_lambda_dir_sha = sha1 (join (" " , [for f in local . id_sync_lambda_files : filesha1 (" ${ local . id_sync_lambda_dir } /${ f } " )]))
15-
16- # Combined SHA to trigger rebuild when either directory changes
17- combined_sha = sha1 (" ${ local . shared_dir_sha } ${ local . id_sync_lambda_dir_sha } " )
18- repo_root = abspath (" ${ path . root } /.." )
19- is_azure_devops = can (regex (" ^/agent/_work" , path. root ))
20-
21- debug_paths = {
22- terraform_root = path.root
23- repo_root = local.repo_root
24- lambdas_dir = local.lambdas_dir
25- dockerfile_path = local.id_sync_dockerfile
26- is_azure = local.is_azure_devops
27- }
28- }
29-
30- resource "null_resource" "find_dockerfile" {
31- provisioner "local-exec" {
32- command = <<- EOT
33- echo "=== FINDING DOCKERFILE ==="
34-
35- ls -la "${ local . lambdas_dir } /" || echo "lambdas directory not found"
36- ls -la .. || echo "parent directory not found"
37- ls -la ${ path . root } /.. || echo "grandparent directory not found"
38-
39- EOT
40- }
41- }
42-
43- resource "null_resource" "debug_directory_structure" {
44- provisioner "local-exec" {
45- command = <<- EOT
46- echo "=== AZURE DEVOPS DIRECTORY DEBUG ==="
47- echo "Current working directory: $(pwd)"
48- echo "Terraform root: ${ path . root } "
49- echo ""
50- echo "=== DIRECTORY CONTENTS ==="
51- echo "Contents of current directory:"
52- ls -la
53- echo ""
54- echo "Contents of parent directory:"
55- ls -la ..
56- echo ""
57- echo "Contents of grandparent directory:"
58- ls -la ../..
59- echo ""
60- echo "Looking for lambdas directory at various levels:"
61- echo "Level 1 (../lambdas):"
62- ls -la ../lambdas 2>/dev/null || echo "Not found at ../lambdas"
63- echo "Level 2 (../../lambdas):"
64- ls -la ../../lambdas 2>/dev/null || echo "Not found at ../../lambdas"
65- echo "Level 3 (../../../lambdas):"
66- ls -la ../../../lambdas 2>/dev/null || echo "Not found at ../../../lambdas"
67- echo ""
68- echo "Looking for Dockerfiles:"
69- find .. -name "*.Dockerfile" -type f 2>/dev/null || echo "No Dockerfiles found"
70- echo "=== END DEBUG ==="
71- EOT
72- }
736}
747
758resource "aws_ecr_repository" "id_sync_lambda_repository" {
@@ -79,35 +12,14 @@ resource "aws_ecr_repository" "id_sync_lambda_repository" {
7912 name = " ${ local . short_prefix } -id-sync-repo"
8013 force_delete = local. is_temp
8114}
82- resource "null_resource" "validate_dockerfile" {
83- triggers = {
84- dockerfile_path = " ${ local . lambdas_dir } /id_sync.Dockerfile"
85- }
8615
87- provisioner "local-exec" {
88- command = <<- EOT
89- echo "Checking for Dockerfile at: ${ local . lambdas_dir } /id_sync.Dockerfile"
90- if [ ! -f "${ local . lambdas_dir } /id_sync.Dockerfile" ]; then
91- echo "ERROR: Dockerfile not found!"
92- echo "Current directory: $(pwd)"
93- echo "Looking for: ${ local . lambdas_dir } /id_sync.Dockerfile"
94- echo "Files in lambdas directory:"
95- ls -la "${ local . lambdas_dir } /" || echo "lambdas directory not found"
96- exit 1
97- else
98- echo "✅ Dockerfile found!"
99- fi
100- EOT
101- }
102- }
10316# Module for building and pushing Docker image to ECR
10417module "id_sync_docker_image" {
10518 source = " terraform-aws-modules/lambda/aws//modules/docker-build"
10619 version = " 8.0.1"
10720
10821 create_ecr_repo = false
10922 ecr_repo = aws_ecr_repository. id_sync_lambda_repository . name
110- docker_file_path = " id_sync.Dockerfile"
11123 ecr_repo_lifecycle_policy = jsonencode ({
11224 " rules" : [
11325 {
@@ -127,7 +39,7 @@ module "id_sync_docker_image" {
12739
12840 platform = " linux/amd64"
12941 use_image_tag = false
130- source_path = local. lambdas_dir
42+ source_path = local. id_sync_lambda_dir
13143 triggers = {
13244 dir_sha = local.id_sync_lambda_dir_sha
13345 }
@@ -256,8 +168,6 @@ resource "aws_iam_policy" "id_sync_lambda_exec_policy" {
256168 " arn:aws:lambda:${ var . aws_region } :${ var . immunisation_account_id } :function:imms-${ var . sub_environment } -id_sync_lambda" ,
257169 ]
258170 },
259- # NEW
260- # NB anomaly: do we want this in "id_sync_lambda_sqs_access_policy"?
261171 {
262172 Effect = " Allow" ,
263173 Action = [
@@ -267,7 +177,6 @@ resource "aws_iam_policy" "id_sync_lambda_exec_policy" {
267177 ],
268178 Resource = " arn:aws:sqs:eu-west-2:${ var . immunisation_account_id } :${ local . short_prefix } -id-sync-queue"
269179 },
270- # NB anomaly: in redis_sync this appears in "redis_sync_lambda_kms_access_policy"
271180 {
272181 Effect = " Allow" ,
273182 Action = [
@@ -364,7 +273,6 @@ resource "aws_lambda_function" "id_sync_lambda" {
364273 REDIS_HOST = data.aws_elasticache_cluster.existing_redis.cache_nodes[0 ].address
365274 REDIS_PORT = data.aws_elasticache_cluster.existing_redis.cache_nodes[0 ].port
366275 ID_SYNC_PROC_LAMBDA_NAME = " imms-${ var . sub_environment } -id_sync_lambda"
367- # NEW
368276 DELTA_TABLE_NAME = aws_dynamodb_table.delta- dynamodb- table.name
369277 IEDS_TABLE_NAME = aws_dynamodb_table.events- dynamodb- table.name
370278 PDS_ENV = var.pds_environment
@@ -384,9 +292,6 @@ resource "aws_cloudwatch_log_group" "id_sync_log_group" {
384292 retention_in_days = 30
385293}
386294
387- # delete config_lambda_notification / new_s3_invoke_permission - not required; duplicate
388-
389- # NEW
390295resource "aws_lambda_event_source_mapping" "id_sync_sqs_trigger" {
391296 event_source_arn = " arn:aws:sqs:eu-west-2:${ var . immunisation_account_id } :${ local . short_prefix } -id-sync-queue"
392297 function_name = aws_lambda_function. id_sync_lambda . arn # TODO
0 commit comments