|
1 | 1 | # Define the directory containing the Docker image and calculate its SHA-256 hash for triggering redeployments |
2 | 2 | locals { |
| 3 | + lambdas_dir = abspath("${path.root}/../lambdas") |
| 4 | + shared_dir = abspath("${path.root}/../lambdas/shared") |
3 | 5 | id_sync_lambda_dir = abspath("${path.root}/../lambdas/id_sync") |
| 6 | + |
| 7 | + # Get files from both directories |
| 8 | + shared_files = fileset(local.shared_dir, "**") |
4 | 9 | id_sync_lambda_files = fileset(local.id_sync_lambda_dir, "**") |
| 10 | + |
| 11 | + # Calculate SHA for both directories |
| 12 | + shared_dir_sha = sha1(join("", [for f in local.shared_files : filesha1("${local.shared_dir}/${f}")])) |
5 | 13 | id_sync_lambda_dir_sha = sha1(join("", [for f in local.id_sync_lambda_files : filesha1("${local.id_sync_lambda_dir}/${f}")])) |
| 14 | + |
| 15 | + # Combined SHA to trigger rebuild when either directory changes |
| 16 | + combined_sha = sha1("${local.shared_dir_sha}${local.id_sync_lambda_dir_sha}") |
| 17 | +} |
| 18 | + |
| 19 | +output "debug_build_paths" { |
| 20 | + value = { |
| 21 | + lambdas_dir = local.lambdas_dir |
| 22 | + shared_dir = local.shared_dir |
| 23 | + id_sync_lambda_dir = local.id_sync_lambda_dir |
| 24 | + shared_files_count = length(local.shared_files) |
| 25 | + id_sync_files_count = length(local.id_sync_lambda_files) |
| 26 | + combined_sha = local.combined_sha |
| 27 | + dockerfile_exists = fileexists("${local.id_sync_lambda_dir}/Dockerfile") |
| 28 | + shared_common_exists = fileexists("${local.shared_dir}/src/common/__init__.py") |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +# Debug: List some files from each directory |
| 33 | +output "debug_file_listing" { |
| 34 | + value = { |
| 35 | + shared_files_sample = slice(local.shared_files, 0, min(5, length(local.shared_files))) |
| 36 | + id_sync_files_sample = slice(local.id_sync_lambda_files, 0, min(5, length(local.id_sync_lambda_files))) |
| 37 | + } |
6 | 38 | } |
7 | 39 |
|
8 | 40 | # Reference the existing SQS queue |
@@ -44,9 +76,39 @@ module "id_sync_docker_image" { |
44 | 76 |
|
45 | 77 | platform = "linux/amd64" |
46 | 78 | use_image_tag = false |
47 | | - source_path = local.id_sync_lambda_dir |
| 79 | + source_path = local.lambdas_dir # parent lambdas directory |
48 | 80 | triggers = { |
49 | | - dir_sha = local.id_sync_lambda_dir_sha |
| 81 | + dir_sha = local.combined_sha # Changed to combined SHA |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +# Add a local provisioner to debug build context |
| 86 | +resource "null_resource" "debug_build_context" { |
| 87 | + triggers = { |
| 88 | + dir_sha = local.combined_sha |
| 89 | + } |
| 90 | + |
| 91 | + provisioner "local-exec" { |
| 92 | + command = <<-EOT |
| 93 | + echo "=== BUILD CONTEXT DEBUG ===" |
| 94 | + echo "Build context: ${local.lambdas_dir}" |
| 95 | + echo "Dockerfile location: ${local.id_sync_lambda_dir}/Dockerfile" |
| 96 | + echo "" |
| 97 | + echo "Checking Dockerfile exists:" |
| 98 | + ls -la "${local.id_sync_lambda_dir}/Dockerfile" || echo "Dockerfile NOT FOUND!" |
| 99 | + echo "" |
| 100 | + echo "Checking shared directory structure:" |
| 101 | + ls -la "${local.shared_dir}/src/common/" || echo "Shared common directory NOT FOUND!" |
| 102 | + echo "" |
| 103 | + echo "Files in build context (lambdas dir):" |
| 104 | + ls -la "${local.lambdas_dir}/" |
| 105 | + echo "" |
| 106 | + echo "Shared files structure:" |
| 107 | + find "${local.shared_dir}" -type f -name "*.py" | head -10 |
| 108 | + echo "" |
| 109 | + echo "ID Sync files structure:" |
| 110 | + find "${local.id_sync_lambda_dir}" -type f -name "*.py" | head -10 |
| 111 | + EOT |
50 | 112 | } |
51 | 113 | } |
52 | 114 |
|
|
0 commit comments