feat: dev/prod segregation so unstable branches cannot break production agents - #51
Open
daniel-sarosi-gwc wants to merge 1 commit into
Open
feat: dev/prod segregation so unstable branches cannot break production agents#51daniel-sarosi-gwc wants to merge 1 commit into
daniel-sarosi-gwc wants to merge 1 commit into
Conversation
…on agents (closes #50) Refactor the shared Blitzlog infrastructure into env-scoped modules and two thin per-env wrappers. Applying Terraform from an unstable branch now lands in a fully isolated dev environment instead of replacing production. Layout: infra/modules/core/ # all blitzlog resources, parameterized by var.environment infra/prod/ # wrapper: environment = "prod" infra/dev/ # wrapper: environment = "dev" infra/modules/core/user-pool/ # per-user bot pool, also env-scoped What changes for prod and dev: - resource names: blitzlog-handler -> blitzlog-{env}-handler blitzlog-lambda-role -> blitzlog-{env}-lambda-role blitzlog-stt-models -> blitzlog-{env}-stt-models ... (every resource) - state file: s3://<bucket>/blitzlog.tfstate -> s3://<bucket>/{env}/blitzlog.tfstate - SSM namespace: /blitzlog/* -> /blitzlog/{env}/* - IAM policies: scoped to /blitzlog/{env}/* — the prod Lambda role cannot read /blitzlog/dev/* and vice versa - ec2:TerminateInstances: gated on ec2:ResourceTag/Environment so a prod agent cannot terminate a dev instance - per-user bot pool: takes required environment variable, lands in /blitzlog/{env}/users/<login>/... - Lambda reads BLITZLOG_ENV from its Terraform-injected env vars and templates all SSM paths under /blitzlog/<env>/ Migration: cd infra/prod terraform init -migrate-state -backend-config=prod-backend.hcl terraform apply Brief API Gateway outage expected on first apply (every resource is replaced because names are now prefixed); SQS DLQ absorbs in-flight requests. Tests: - 207 existing pytest tests pass (handler refactor for env namespacing) - 7 new tests in tests/test_terraform_env_isolation.py catch cross-env SSM read leaks, hardcoded /blitzlog/{env}/ paths, missing Environment tags on TerminateInstances, and missing env validation - terraform fmt -check -recursive clean across all modules - terraform validate passes for prod, dev, modules/core, and modules/core/user-pool - ruff check . and black --check . clean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #50
Problem
Blitzlog had a single shared infrastructure deployment: one Lambda, one API
Gateway, one IAM role pair, one SSM namespace, one S3 backend state file.
Applying Terraform from an unstable branch replaced every resource in place,
and every user's GitHub webhook still pointed at the same URL — so all live
agent runs started going through unstable code.
Solution
Refactor
infra/into env-scoped modules and two thin per-environmentwrappers. Applying Terraform from an unstable branch now lands in a fully
isolated dev environment instead of replacing prod.
Layout
What changes for prod and dev
blitzlog-handler→blitzlog-{env}-handler, etc. (every resource)s3://<bucket>/blitzlog.tfstate→s3://<bucket>/{env}/blitzlog.tfstate/blitzlog/*→/blitzlog/{env}/*/blitzlog/{env}/*— the prod Lambda role cannot read/blitzlog/dev/*and vice versaec2:ResourceTag/Environmentso a prod agent can't terminate a dev instanceenvironmentvariable, lands in/blitzlog/{env}/users/<login>/...BLITZLOG_ENVfrom Terraform-injected env vars and templates all SSM paths under/blitzlog/<env>/Migration
Brief API Gateway outage expected on first apply; SQS DLQ absorbs in-flight requests.
Deploying dev
Real production users' webhooks still point at the prod App's URL — they cannot be affected by anything in dev.
Tests
tests/test_terraform_env_isolation.pycatch:/blitzlog/{env}/pathsEnvironmenttags onTerminateInstancespoliciesenvironmentvariable validation in moduleterraform fmt -check -recursiveclean across all modulesterraform validatepasses forprod/,dev/,modules/core/, andmodules/core/user-pool/ruff check .andblack --check .cleanAcceptance criteria
cd infra/prod && terraform validatepassescd infra/dev && terraform validatepasses/blitzlog/{env}/literals)ec2:TerminateInstancespolicy requiresec2:ResourceTag/Environment = var.environmentenvironmentand prefixes its SSM pathscd infra/prod && terraform init -migrate-statefrom the maintainer (one-time prod recreation)terraform applyagainstinfra/dev/with dev App credentialsFollow-ups (not in this PR)
terraform applyagainstinfra/dev/on every push to a non-mainbranch.stagingenv (cp -r dev staging, changeenvironment = "staging").