Skip to content

deploy scripts: per-region TF_DATA_DIR isolation + demo-seed prompt#1287

Merged
iammukeshm merged 2 commits into
mainfrom
chore/terraform-isolate-data-dir
Jun 5, 2026
Merged

deploy scripts: per-region TF_DATA_DIR isolation + demo-seed prompt#1287
iammukeshm merged 2 commits into
mainfrom
chore/terraform-isolate-data-dir

Conversation

@iammukeshm

@iammukeshm iammukeshm commented Jun 5, 2026

Copy link
Copy Markdown
Member

Two deploy-script changes.

1. Isolate Terraform data dir per env/region (TF_DATA_DIR)

Problem

app_stack/ keeps Terraform working data in a single shared .terraform/, and each env/region is selected per-run via terraform init -reconfigure -backend-config=envs/<env>/<region>/backend.hcl. That makes concurrent runs against different backends unsafe: whichever runs init -reconfigure last repoints the shared backend pointer for both.

Observed: an ap-south-1 deploy and a us-east-1 destroy overlapped. The deploy's apply + migrator succeeded, but in the gap before its frontend step the destroy's init repointed the backend to us-east-1. The deploy's closing terraform output dashboard_site/admin_site/api_url then read the wrong state → "Output not found" → the SPA publish was silently skipped (infra was fine; only the file publish was missed).

Fix

deploy.sh, deploy.ps1, destroy.ps1 set TF_DATA_DIR to an absolute app_stack/.terraform/<env>-<region> before any terraform call. Each env/region gets its own data dir (backend pointer, providers, modules), so two runs against different backends physically cannot share — and clobber — the same pointer. .terraform/ is already gitignored.

Verification

Ran end-to-end against the live dev/ap-south-1 stack: init into a fresh .terraform/dev-ap-south-1/, applyNo changes, both SPAs built/synced (dashboard 95 objects, admin 65) + CloudFront invalidated — the previously-skipped publish now completes.

2. Prompt to seed demo tenants when not specified

deploy.sh/deploy.ps1 now ask Seed demo tenants (acme/globex)? before the apply. Skipped when already chosen (--seed-demo/-SeedDemo), not migrating (--skip-migrate), or unattended (--auto-approve / no TTY), so CI never blocks.

bash -n + PowerShell parser checks pass on all scripts.

🤖 Generated with Claude Code

iammukeshm and others added 2 commits June 5, 2026 23:36
app_stack/ kept Terraform's working data in one shared .terraform, and each
env/region was selected via `init -reconfigure -backend-config=...`. So two runs
against different backends — e.g. an ap-south-1 deploy while us-east-1 was being
destroyed — clobbered each other's backend pointer mid-run: the deploy applied
fine but its closing `terraform output` then read the wrong region's state
("Output not found") and silently skipped the SPA publish.

Fix: deploy.sh/deploy.ps1/destroy.ps1 now set TF_DATA_DIR to an absolute
app_stack/.terraform/<env>-<region> before any terraform call, giving each
env/region its own backend pointer, providers, and modules. Concurrent runs
across regions can no longer collide — no "run them one at a time" caveat.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
deploy.sh/deploy.ps1 now ask "Seed demo tenants (acme/globex)?" before the
apply. Skipped when already chosen (--seed-demo/-SeedDemo), not migrating
(--skip-migrate), or unattended (--auto-approve / no TTY) so CI never blocks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@iammukeshm iammukeshm changed the title fix(deploy): isolate Terraform data dir per env/region (TF_DATA_DIR) deploy scripts: per-region TF_DATA_DIR isolation + demo-seed prompt Jun 5, 2026
@iammukeshm iammukeshm merged commit 9cf7bcf into main Jun 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant