Skip to content

Commit 7bf9fb8

Browse files
committed
Clarify seed terraform
1 parent 14b74c7 commit 7bf9fb8

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

infrastructure/terraform/components/callbacks/locals.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ locals {
99
mock_client_key = replace(local.mock_client_file, ".json", "")
1010
mock_client_path = "${path.module}/../../../../tests/integration/fixtures/${local.mock_client_file}"
1111

12-
discovered_config_files = fileset(local.clients_dir_path, "*.json")
12+
config_files_from_s3 = fileset(local.clients_dir_path, "*.json")
1313
config_files = var.deploy_mock_client_subscriptions ? setunion(
14-
local.discovered_config_files,
14+
local.config_files_from_s3,
1515
toset([local.mock_client_file])
16-
) : local.discovered_config_files
16+
) : local.config_files_from_s3
1717

1818
config_clients = merge([
1919
for filename in local.config_files : {

infrastructure/terraform/components/callbacks/sync-client-config.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#!/usr/bin/env bash
22

3+
# This script seeds local client subscription JSON files from the config bucket
4+
# before Terraform evaluates locals/fileset (see local.config_clients in locals.tf).
5+
# It handles the S3 bucket not existing on first apply.
6+
# Deployment Lifecycle:
7+
# - Sync client JSON files from S3 into "modules/clients" before Terraform runs.
8+
# - Terraform then reads the local fileset from "modules/clients" as input.
9+
# - On later deployments, files are refreshed from bucket state each run.
10+
#
11+
# Deployment Lifecycle dev/test environment:
12+
# - Special handling is needed to seed test data and have it take effect on the first apply, as the bucket and files won't exist yet
13+
# - Terraform merges in the local mock fixture config into local.config_clients
14+
# - Terraform uploads mock-it-client.json to the config bucket
15+
# - On subsequent deployments, that mock config is synced from S3 and handled
16+
# through the normal fileset path.
17+
318
set -euo pipefail
419

520
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -26,6 +41,7 @@ if ! sync_output=$(aws s3 sync "s3://${bucket_name}/${s3_prefix}" "${clients_dir
2641
--include "*.json" \
2742
--only-show-errors 2>&1); then
2843
if [[ "${sync_output}" == *"NoSuchBucket"* ]]; then
44+
# Expected on first apply before Terraform creates the bucket.
2945
echo "Client config bucket not found yet; skipping sync for first run"
3046
else
3147
echo "Failed to sync client config from S3" >&2

0 commit comments

Comments
 (0)