Skip to content

Share Terraform settings through Key Vault with just pull / just push - #46

Merged
NinjaLikesCheez merged 1 commit into
mainfrom
claude/tfvars-pull
Nov 18, 2026
Merged

NinjaLikesCheez merged 1 commit into
mainfrom
claude/tfvars-pull

Conversation

@NinjaLikesCheez

Copy link
Copy Markdown
Contributor

Brings Pixel's just pull / just push to pixel-phone. Each environment's Terraform settings move out of the committed example and into a gitignored infra/envs/<env>/terraform.tfvars, shared through the Key Vault secret terraform-tfvars (ADR 0012).

What changes

  • just pull <env> brings down terraform.tfvars and .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 type prod. It refuses a tfvars that sets a sensitive variable or one the stack doesn't declare, so prod's custom_domains in 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-push are unchanged: app secrets only.
  • just tf-plan / tf-apply read terraform.tfvars and stop with a hint if it's missing. CI still plans dev with terraform.example.tfvars.
  • infra/secrets.manifest.yaml gets Pixel's groups. The existing secrets are app, and terraform-tfvars is tooling. The module's locals.tf filters to app, so the plan shouldn't change.
  • Docs: a "Terraform settings" section in the runbook. Setup, Home Assistant, infra, the env READMEs and AGENTS.md point at 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 exists

Trade-offs (also in the ADR)

  • A settings change is no longer a pull request, so it has no review and no git history. Key Vault keeps every version.
  • The committed examples still hold dev's and prod's real values, so CI's plan of dev means something. They can drift from the real settings.
  • tf-plan doesn't check that the local tfvars matches Key Vault. Run just pull first.

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.
  • Not run against Azure: no pull or push to a real vault yet.

🤖 Generated with Claude Code

- 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 thread scripts/secrets-sync.ts
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@NinjaLikesCheez
NinjaLikesCheez merged commit d1e54f3 into main Nov 18, 2026
10 checks passed

This branch was successfully deployed

1 active deployment
dev — ef10f68a Deployed Nov 18, 2026 by NinjaLikesCheez via Plan envs/dev #43
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