// Set one string variable in a tfvars JSON file, preserving its other keys // (JSON allows no comments, so the file cannot mark itself as generated: // deploy-site.sh writes release_sha into infra/terraform.tfvars.json here). import { existsSync, readFileSync, writeFileSync } from 'node:fs' const [file, key, value] = process.argv.slice(2) if (!file || !key || value === undefined) { console.error('usage: patch-tfvars.mjs ') process.exit(2) } const vars = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : {} vars[key] = value writeFileSync(file, JSON.stringify(vars, null, 2) + '\n')