Repository navigation
Share Terraform settings through Key Vault with just pull / just push - #46
Merged
Merged
Conversation
- Each env is planned and applied with a gitignored infra/envs/<env>/terraform.tfvars, shared through the Key Vault secret terraform-tfvars, as Pixel does (ADR 0012). - just pull <env> / just push <env> sync it together with the app secrets. The tfvars is shown as a diff; push refuses sensitive or undeclared variables, re-reads the vault before writing and reads the values back. It never applies. - secrets.manifest.yaml gets Pixel's groups: app (Terraform references these) and tooling (terraform-tfvars, laptop tools only). - tf-plan / tf-apply read terraform.tfvars and stop if it's missing. CI still plans dev with terraform.example.tfvars. - Runbook "Terraform settings", setup, infra and env READMEs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines
+214
to
+221
| const envText = readText(envFile); | ||
| if (envText === undefined) { | ||
| throw new Stop( | ||
| `${envFile} doesn't exist. Run just ${scope === "all" ? "pull" : "secrets-pull"} ${target} first.`, | ||
| ); | ||
| } | ||
| const wrong = wrongEnvFile(target, envText); | ||
| if (wrong) throw new Error(wrong); | ||
| if (wrong) throw new Stop(wrong); |
There was a problem hiding this comment.
Bug: push() throws an error when .env.<env> does not exist, blocking initial secret bootstrapping because pull() will not create the file when the vault is empty.
Severity: MEDIUM
Suggested Fix
Allow push() to handle a missing .env.<env> file when pushing tfvars or when running in a bootstrapping context, or update the error message and flow to create the initial env file from .env.example if it does not exist.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: scripts/secrets-sync.ts#L214-L221
Potential issue: In `push()`, an error is unconditionally thrown when
`readText(envFile)` returns undefined, instructing the user to run `just pull <env>
first`. However, in a fresh environment or empty vault, `pull()` only creates and writes
the environment file if `env.size > 0`. Because pulling an empty vault produces no file,
bootstrapping via `just push <env>` fails and the instructed fix cannot resolve it.
Also affects:
scripts/secrets-sync.ts:188~202
Did we get this right? 👍 / 👎 to inform future reviews.
This branch was successfully deployed
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.
Brings Pixel's
just pull/just pushto pixel-phone. Each environment's Terraform settings move out of the committed example and into a gitignoredinfra/envs/<env>/terraform.tfvars, shared through the Key Vault secretterraform-tfvars(ADR 0012).What changes
just pull <env>brings downterraform.tfvarsand.env.<env>. The tfvars is shown as a diff and secrets by length only. It asks before writing.just push <env>shows the diff and asks; prod makes you typeprod. It refuses a tfvars that sets a sensitive variable or one the stack doesn't declare, so prod'scustom_domainsin dev's file is caught. Before writing it re-reads the vault, and it reads the values back afterwards. It never deletes and never applies.just secrets-pull/secrets-pushare unchanged: app secrets only.just tf-plan/tf-applyreadterraform.tfvarsand stop with a hint if it's missing. CI still plans dev withterraform.example.tfvars.infra/secrets.manifest.yamlgets Pixel's groups. The existing secrets areapp, andterraform-tfvarsistooling. The module'slocals.tffilters toapp, so the plan shouldn't change.terraform.tfvars. CHANGELOG entry under Changed.After merging
Each vault needs its first copy before anyone can pull:
cp infra/envs/dev/terraform.example.tfvars infra/envs/dev/terraform.tfvars just push dev # likewise prod, once its vault existsTrade-offs (also in the ADR)
tf-plandoesn't check that the local tfvars matches Key Vault. Runjust pullfirst.Testing
just check: lint, types, 296 tests with coverage thresholds.just tf-validate,just docs-build.locals.tf's filter evaluated against the new manifest in a throwaway Terraform: it gives the same secret map as before.🤖 Generated with Claude Code