Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion landing-zone-configurator/app/apps/worker/src/project-iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
Expand Down
78 changes: 78 additions & 0 deletions landing-zone-configurator/app/tests/project-iam-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((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<void>((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 () => {
Expand Down
10 changes: 10 additions & 0 deletions landing-zone-configurator/deploy/runner/README.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 9 additions & 0 deletions landing-zone-configurator/deploy/runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
7 changes: 7 additions & 0 deletions landing-zone-configurator/infra/ci/release-notes.mjs
Original file line number Diff line number Diff line change
@@ -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:[
Expand Down
Loading