From 225265126f2b73d5cb6b0d5532078bfb4fb8b5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Weberru=C3=9F?= Date: Wed, 25 Nov 2026 14:34:36 +0000 Subject: [PATCH 1/2] fix(runner): handle absent state on first application plan --- .../app/apps/worker/src/project-iam.ts | 17 +++- .../app/tests/project-iam-native.test.ts | 78 +++++++++++++++++++ .../deploy/runner/README.de.md | 10 +++ .../deploy/runner/README.md | 9 +++ 4 files changed, 113 insertions(+), 1 deletion(-) diff --git a/landing-zone-configurator/app/apps/worker/src/project-iam.ts b/landing-zone-configurator/app/apps/worker/src/project-iam.ts index 44884137..130ee65b 100644 --- a/landing-zone-configurator/app/apps/worker/src/project-iam.ts +++ b/landing-zone-configurator/app/apps/worker/src/project-iam.ts @@ -13,6 +13,18 @@ import { } from "@lzc/contracts/recovery"; import { z } from "zod"; +// OpenTofu 1.12.6 returns this pristine snapshot for an absent HTTP State. +// Existing, partially applied or malformed States must retain normal checks. +const absentHttpState = z.strictObject({ + version: z.literal(4), + terraform_version: z.literal("1.12.6"), + serial: z.literal(0), + lineage: z.literal(""), + outputs: z.strictObject({}), + resources: z.array(z.never()).length(0), + check_results: z.null().optional(), +}); + export async function pullIamState( root: string, work: string, @@ -30,7 +42,10 @@ export async function pullIamState( maxBuffer: 16 * 1024 * 1024, }, ); - return result.stdout.trim() ? Buffer.from(result.stdout) : null; + const text = result.stdout.trim(); + if (!text || absentHttpState.safeParse(JSON.parse(text)).success) + return null; + return Buffer.from(result.stdout); } catch (error) { const e = error as { code?: unknown; stderr?: unknown; stdout?: unknown }; if ( diff --git a/landing-zone-configurator/app/tests/project-iam-native.test.ts b/landing-zone-configurator/app/tests/project-iam-native.test.ts index d31e5bff..2a9c2dca 100644 --- a/landing-zone-configurator/app/tests/project-iam-native.test.ts +++ b/landing-zone-configurator/app/tests/project-iam-native.test.ts @@ -23,6 +23,84 @@ import { recoveryFixture } from "./fixtures/application-state-recovery.js"; const binary = process.env.LZC_TEST_TOFU_BIN; const mirror = process.env.LZC_TEST_PROVIDER_MIRROR; + +it.skipIf(!binary).each(["absent", "existing"] as const)( + "real OpenTofu distinguishes an %s HTTP State before IAM discovery", + async (kind) => { + const existing = { + version: 4, + terraform_version: "1.12.6", + serial: 1, + lineage: "33333333-3333-4333-8333-333333333333", + outputs: { preserved: { value: "existing", type: "string" } }, + resources: [], + check_results: null, + }; + const methods: string[] = []; + const server = createServer((req, res) => { + methods.push(req.method!); + if (req.method !== "GET") { + res.statusCode = 405; + res.end(); + } else if (kind === "absent") { + res.statusCode = 404; + res.end(); + } else { + res.setHeader("content-type", "application/json"); + res.end(JSON.stringify(existing)); + } + }); + await new Promise((resolve) => + server.listen(0, "127.0.0.1", resolve), + ); + const folder = await mkdtemp(join(tmpdir(), "lzc-iam-first-plan-")); + try { + await mkdir(join(folder, "tools")); + await symlink(binary!, join(folder, "tools/tofu")); + const address = server.address() as { port: number }; + await writeFile( + join(folder, "main.tf"), + `terraform {\n backend "http" {\n address = "http://127.0.0.1:${address.port}/state"\n }\n}\nresource "terraform_data" "contract" { input = "first-plan" }\n`, + ); + const env = { + PATH: process.env.PATH, + TF_INPUT: "0", + CHECKPOINT_DISABLE: "1", + }; + const command = (args: string[]) => + promisify(execFile)(binary!, args, { + cwd: folder, + env, + timeout: 20_000, + }); + await command(["init", "-no-color"]); + const state = await pullIamState( + folder, + folder, + env, + Date.now() + 20_000, + ); + if (kind === "absent") { + expect(state).toBeNull(); + const plan = await command(["plan", "-no-color", "-lock=false"]); + expect(plan.stdout).toContain("1 to add, 0 to change, 0 to destroy"); + } else { + expect(state).not.toBeNull(); + expect(JSON.parse(state!.toString())).toMatchObject(existing); + expect(() => + readRecoveryState(state!, "33333333-3333-4333-8333-333333333333"), + ).toThrow("checkpoint-invalid"); + } + expect(methods.every((method) => method === "GET")).toBe(true); + } finally { + server.closeAllConnections(); + await new Promise((resolve) => server.close(() => resolve())); + await rm(folder, { recursive: true, force: true }); + } + }, + 30_000, +); + it.skipIf(!binary || !mirror)( "real OpenTofu and pinned provider adopt direct grants before a separate cleanup Apply", async () => { diff --git a/landing-zone-configurator/deploy/runner/README.de.md b/landing-zone-configurator/deploy/runner/README.de.md index 958b12b4..1390965d 100644 --- a/landing-zone-configurator/deploy/runner/README.de.md +++ b/landing-zone-configurator/deploy/runner/README.de.md @@ -123,3 +123,13 @@ Keiner der Werte wird öffentlichen tfvars, Hashes oder Befehlsargumenten hinzugefügt; beide werden auch bei fehlgeschlagenen Befehlen aus Ausgaben entfernt. Apply verwendet den exakt geprüften gespeicherten Plan ohne Neuplanung; Application-Aufträge lehnen diese Fähigkeiten ab. + +## Erster Application-Plan und fehlender State + +Bei einer neuen Bestellung kann OpenTofu 1.12.6 einen fehlenden HTTP-State als +unberührten leeren Snapshot statt als Fehler zurückgeben. Der Runner behandelt +ausschließlich diesen exakten initialen Snapshot als fehlend und setzt den ersten +Plan ohne IAM-Migrationsprüfung fort. Für bestehende oder teilweise gefüllte States +bleiben sämtliche Zuordnungs- und IAM-Prüfungen erhalten. Nach einer Runner-Korrektur +den Plan derselben Bestellung erneut starten; eine manuelle Projekt- oder +State-Anlage ist nicht erforderlich. diff --git a/landing-zone-configurator/deploy/runner/README.md b/landing-zone-configurator/deploy/runner/README.md index 763580f4..01723434 100644 --- a/landing-zone-configurator/deploy/runner/README.md +++ b/landing-zone-configurator/deploy/runner/README.md @@ -111,3 +111,12 @@ validated and delivered only through child-process Neither value is added to public tfvars, hashes or command arguments, and both are redacted from output, including failed commands. Apply consumes the exact reviewed saved plan without replanning; application jobs reject these capabilities. + +## First Application Plan and absent State + +For a new order, an absent HTTP State can be returned by OpenTofu 1.12.6 as a +pristine empty snapshot rather than an error. The Runner treats only that exact +initial snapshot as absent and proceeds with the first Plan without IAM migration +discovery. Existing or partially populated States retain all scope and IAM checks. +After a Runner correction, retry the Plan on the same order; no manual project or +State creation is required. From 5c070817172eae06d362528972c66c37f613cd5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Weberru=C3=9F?= Date: Wed, 25 Nov 2026 14:43:58 +0000 Subject: [PATCH 2/2] docs(release): describe v2.2.7 application planning hotfix --- landing-zone-configurator/infra/ci/release-notes.mjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/landing-zone-configurator/infra/ci/release-notes.mjs b/landing-zone-configurator/infra/ci/release-notes.mjs index 25cebcfe..dcf36e4b 100644 --- a/landing-zone-configurator/infra/ci/release-notes.mjs +++ b/landing-zone-configurator/infra/ci/release-notes.mjs @@ -1,6 +1,13 @@ const tag=process.env.LZC_RELEASE_TAG; if(!/^v(?:[2-9]|[1-9][0-9]+)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.test(tag??""))throw new Error("Expected a stable product release tag"); const notes={ + "v2.2.7": { + introduction:"Restore first-time Application Landing Zone planning.", + changes:[ + "Recognize OpenTofu's pristine empty State for new orders and avoid starting IAM migration checks before a project exists.", + "Keep existing State and IAM protections; retry the same order without recreating its platform binding or project.", + ], + }, "v2.2.6": { introduction:"Reliable invitation batches and quota-aware email delivery.", changes:[