Stop deploy from reconfiguring central backend

This commit is contained in:
Timothy J. Aveni
2026-06-28 21:36:58 -07:00
parent 50603b4cc8
commit b6ffc25755
+5 -30
View File
@@ -13,7 +13,6 @@ const repoRoot = process.env.QUIXOS_REPO_ROOT ?? path.resolve(sourceScriptDir, "
const scriptDir = process.env.QUIXOS_RUNTIME_DIR ?? path.resolve(repoRoot, "tofu/runtime"); const scriptDir = process.env.QUIXOS_RUNTIME_DIR ?? path.resolve(repoRoot, "tofu/runtime");
const amiBuilderDir = path.resolve(scriptDir, "../ami-builder"); const amiBuilderDir = path.resolve(scriptDir, "../ami-builder");
const centralDir = path.resolve(scriptDir, "../central"); const centralDir = path.resolve(scriptDir, "../central");
const centralInitBackendScript = path.join(centralDir, "init-backend.sh");
const legacyResolvedAmiVarsFile = "resolved-ami.auto.tfvars.json"; const legacyResolvedAmiVarsFile = "resolved-ami.auto.tfvars.json";
const resolvedDeployVarsFile = "zz-qx-deploy.auto.tfvars.json"; const resolvedDeployVarsFile = "zz-qx-deploy.auto.tfvars.json";
@@ -171,27 +170,6 @@ const capture = (command, args, options = {}) =>
const captureMaybe = (command, args, options = {}) => const captureMaybe = (command, args, options = {}) =>
run(command, args, { ...options, capture: true, allowFailure: true }); run(command, args, { ...options, capture: true, allowFailure: true });
let centralBackendReconfigured = false;
const reconfigureCentralBackend = (env) => {
if (centralBackendReconfigured || !fs.existsSync(centralDir)) {
return;
}
if (fs.existsSync(centralInitBackendScript)) {
run(centralInitBackendScript, ["-reconfigure"], {
cwd: centralDir,
env,
});
} else {
run("tofu", ["init", "-reconfigure"], {
cwd: centralDir,
env,
});
}
centralBackendReconfigured = true;
};
const centralOutput = (name, { env, required = false } = {}) => { const centralOutput = (name, { env, required = false } = {}) => {
if (!fs.existsSync(centralDir)) { if (!fs.existsSync(centralDir)) {
if (required) { if (required) {
@@ -200,25 +178,22 @@ const centralOutput = (name, { env, required = false } = {}) => {
return null; return null;
} }
let result = captureMaybe("tofu", ["-chdir=" + centralDir, "output", "-raw", name], { env }); const result = captureMaybe("tofu", ["-chdir=" + centralDir, "output", "-raw", name], { env });
if (
result.status !== 0
&& /Backend initialization required|please run "tofu init"|run\s+"tofu init"/i.test(result.stderr)
) {
reconfigureCentralBackend(env);
result = captureMaybe("tofu", ["-chdir=" + centralDir, "output", "-raw", name], { env });
}
const value = result.stdout.trim(); const value = result.stdout.trim();
if (result.status === 0 && value) { if (result.status === 0 && value) {
return value; return value;
} }
if (required) { if (required) {
const initHint = /Backend initialization required|please run "tofu init"|run\s+"tofu init"/i.test(result.stderr)
? "Initialize central explicitly with: (cd tofu/central && ./init-backend.sh -reconfigure)"
: "";
const details = [ const details = [
`Unable to read tofu/central output '${name}'.`, `Unable to read tofu/central output '${name}'.`,
`Command: tofu -chdir=${centralDir} output -raw ${name}`, `Command: tofu -chdir=${centralDir} output -raw ${name}`,
result.stderr.trimEnd(), result.stderr.trimEnd(),
result.stdout.trimEnd(), result.stdout.trimEnd(),
initHint,
].filter(Boolean).join("\n"); ].filter(Boolean).join("\n");
throw new Error(details); throw new Error(details);
} }