@intentius/chant-lexicon-terraform 0.124.76 → 0.124.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/drift-record.d.ts +24 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +52 -0
- package/dist/drift-rows.d.ts +49 -4
- package/dist/drift-rows.d.ts.map +1 -1
- package/dist/drift-rows.js +87 -19
- package/dist/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/dist/pr-env.d.ts +138 -0
- package/dist/pr-env.d.ts.map +1 -0
- package/dist/pr-env.js +248 -0
- package/dist/state/gitlab.d.ts +74 -0
- package/dist/state/gitlab.d.ts.map +1 -0
- package/dist/state/gitlab.js +275 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/index.d.ts.map +1 -1
- package/dist/state/index.js +2 -0
- package/dist/state/store.d.ts +2 -1
- package/dist/state/store.d.ts.map +1 -1
- package/dist/state/versions.d.ts +39 -0
- package/dist/state/versions.d.ts.map +1 -0
- package/dist/state/versions.js +85 -0
- package/dist/state-migration.d.ts +85 -0
- package/dist/state-migration.d.ts.map +1 -0
- package/dist/state-migration.js +296 -0
- package/dist/state-ops.d.ts +54 -87
- package/dist/state-ops.d.ts.map +1 -1
- package/dist/state-ops.js +120 -77
- package/package.json +2 -2
- package/src/__fixtures__/drift-rows/refresh-plan-module.json +48 -0
- package/src/drift-record.test.ts +62 -0
- package/src/drift-record.ts +58 -0
- package/src/drift-rows.test.ts +90 -1
- package/src/drift-rows.ts +89 -18
- package/src/pr-env.test.ts +132 -0
- package/src/pr-env.ts +312 -0
- package/src/state/gitlab.test.ts +226 -0
- package/src/state/gitlab.ts +318 -0
- package/src/state/index.ts +2 -0
- package/src/state/store.ts +2 -1
- package/src/state/versions.ts +103 -0
- package/src/state-export-unlock.test.ts +230 -0
- package/src/state-migration.test.ts +236 -0
- package/src/state-migration.ts +353 -0
- package/src/state-ops.ts +132 -130
package/dist/state-ops.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Capability } from "@intentius/chant/components/capability";
|
|
2
2
|
import type { ChangeSetPart } from "@intentius/chant/change-set";
|
|
3
|
-
import {
|
|
3
|
+
import { type GatedRequest, type GatedRequestRules } from "@intentius/chant/lifecycle/gated-request";
|
|
4
|
+
import { gatedOp } from "@intentius/chant/lifecycle/gated-op";
|
|
5
|
+
import { type StateExportInput, type StateExportOutcome } from "@intentius/chant/state-export";
|
|
6
|
+
import { type StateLockSource, type StateUnlockInput, type StateUnlockOutcome } from "@intentius/chant/state-unlock";
|
|
7
|
+
import { type StateObject } from "./state/backend.js";
|
|
4
8
|
import { type BinaryExec } from "./state/exec.js";
|
|
9
|
+
import { type GitLabState } from "./state/gitlab.js";
|
|
10
|
+
import type { StoreFetch } from "./state/object-store.js";
|
|
5
11
|
/** The ops the gated requests of this module wait at, one per kind, as terragucci named them. */
|
|
6
12
|
export declare const STATE_OPS: {
|
|
7
13
|
readonly unlock: "tf-unlock";
|
|
@@ -103,97 +109,59 @@ export declare function applyPlanFile(r: RootRun & {
|
|
|
103
109
|
planFile: string;
|
|
104
110
|
lockTimeout?: string | false;
|
|
105
111
|
}): Promise<void>;
|
|
106
|
-
|
|
107
|
-
export
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* The time a request was first asked, so asking again binds the same
|
|
115
|
-
* digest: chant's digest covers `at`, and a run that asked anew each time
|
|
116
|
-
* would never meet the approval of the last one. The newest standing,
|
|
117
|
-
* unspent request with the same kind, subject, requester and fields gives
|
|
118
|
-
* its `at`; with none, `now`.
|
|
119
|
-
*/
|
|
120
|
-
export declare function requestedAt(op: string, request: Omit<GatedRequest, "at">, options?: {
|
|
121
|
-
now?: string;
|
|
122
|
-
cwd?: string;
|
|
123
|
-
ledger?: Pick<GatedRequestLedger, "readGatedRequests">;
|
|
124
|
-
}): Promise<string>;
|
|
125
|
-
/** The digest `requestGate` puts in `fields.proof` for an attachment. */
|
|
126
|
-
export declare const attachmentDigest: (attachment: string) => string;
|
|
127
|
-
export interface GatedStateOpInput {
|
|
128
|
-
op: string;
|
|
129
|
-
/** The request, less `at`, which {@link requestedAt} fills. */
|
|
130
|
-
request: Omit<GatedRequest, "at"> & {
|
|
131
|
-
at?: string;
|
|
132
|
-
};
|
|
133
|
-
rules: GatedRequestRules;
|
|
134
|
-
description?: string;
|
|
135
|
-
expiry?: string;
|
|
136
|
-
base?: string;
|
|
137
|
-
/** A document the request carries, such as a migration's proof; its digest joins the request. */
|
|
138
|
-
attachment?: string;
|
|
139
|
-
cwd?: string;
|
|
140
|
-
now?: string;
|
|
141
|
-
runId?: string;
|
|
142
|
-
commit?: string;
|
|
143
|
-
ledger?: GatedRequestLedger;
|
|
144
|
-
gates?: RequestGateInput["gates"];
|
|
145
|
-
/**
|
|
146
|
-
* A last check just before the spend, for a fact that can change while the
|
|
147
|
-
* request waited (a run that may hold the lock came back). A string refuses
|
|
148
|
-
* the operation with that reason, and the approval is not spent.
|
|
149
|
-
*/
|
|
150
|
-
beforeSpend?: () => Promise<string | undefined>;
|
|
112
|
+
export { attachmentDigest, requestedAt, type GatedRequestLedger } from "@intentius/chant/lifecycle/gated-op";
|
|
113
|
+
export type { GatedOpInput as GatedStateOpInput, GatedOpResult as GatedStateOpResult } from "@intentius/chant/lifecycle/gated-op";
|
|
114
|
+
/** Run `act` once its request is approved: chant core's {@link gatedOp}. */
|
|
115
|
+
export declare const gatedStateOp: typeof gatedOp;
|
|
116
|
+
/** The digest a request binds, for a caller that prints it before it asks. */
|
|
117
|
+
export declare const stateOpDigest: (op: string, request: GatedRequest) => string;
|
|
118
|
+
/** A root's backend, read the way export and release read it. */
|
|
119
|
+
export interface RootBackendRun extends RootRun {
|
|
151
120
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
121
|
+
* Run `init` in a data dir of its own (a new temp dir as `TF_DATA_DIR`,
|
|
122
|
+
* removed after), so the checkout's `.terraform` is left alone. Default
|
|
123
|
+
* true. Pass false for a root another tool initialised in `dir` with `env`,
|
|
124
|
+
* such as a Terragrunt unit.
|
|
154
125
|
*/
|
|
155
|
-
|
|
126
|
+
init?: boolean;
|
|
127
|
+
/** The backend's HTTP calls, for tests. */
|
|
128
|
+
fetch?: StoreFetch;
|
|
129
|
+
}
|
|
130
|
+
/** Where a root's state is: a state object, or a GitLab-managed state (./state/gitlab.ts), which the lock verdict refuses and export and release read. */
|
|
131
|
+
type RootStateAt = StateObject | GitLabState;
|
|
132
|
+
export interface TerraformStateExportInput extends Omit<StateExportInput, "source" | "subject">, RootBackendRun {
|
|
156
133
|
}
|
|
157
|
-
/**
|
|
158
|
-
export
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
recorded: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* chant core's state export (`exportStateVersion`) of one root: its backend
|
|
136
|
+
* read by an init of its own, its versions read from the bucket or container
|
|
137
|
+
* (`./state/versions.ts`). Throws `StateExportError` for a backend that keeps
|
|
138
|
+
* no versions chant reads.
|
|
139
|
+
*/
|
|
140
|
+
export declare function terraformStateExport(input: TerraformStateExportInput): Promise<StateExportOutcome>;
|
|
141
|
+
/**
|
|
142
|
+
* A root's lock as chant core's lock release reads it: the lock its store
|
|
143
|
+
* holds (`StateStore.heldLock`: the s3 lock file, the gcs lock object, whose
|
|
144
|
+
* generation is the ID the binary takes, the azurerm lease), released with
|
|
145
|
+
* the binary's fixed `force-unlock` of that ID. A GitLab-managed state's lock
|
|
146
|
+
* is read by asking for it and released by its ID on the unlock address,
|
|
147
|
+
* which GitLab refuses for any other lock. A local state's lock goes with
|
|
148
|
+
* the process that took it, so it is refused.
|
|
149
|
+
*/
|
|
150
|
+
export declare function terraformLockSource(r: RootRun & {
|
|
151
|
+
object: RootStateAt;
|
|
152
|
+
fetch?: StoreFetch;
|
|
153
|
+
}): StateLockSource | {
|
|
154
|
+
refused: string;
|
|
179
155
|
};
|
|
156
|
+
export interface TerraformStateUnlockInput extends Omit<StateUnlockInput, "lock" | "subject">, RootBackendRun {
|
|
157
|
+
}
|
|
180
158
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* cannot be written is reported as `recorded: false`; the act already ran.
|
|
159
|
+
* chant core's lock release (`releaseStateLock`) of one root's state: its
|
|
160
|
+
* backend read by an init of its own, the lock read from the store, released
|
|
161
|
+
* by `force-unlock` in the same data dir. Throws `StateUnlockError` for a
|
|
162
|
+
* backend whose lock chant does not read.
|
|
186
163
|
*/
|
|
187
|
-
export declare function
|
|
188
|
-
digest: string;
|
|
189
|
-
request: GatedRequest;
|
|
190
|
-
approvedBy: string;
|
|
191
|
-
}) => Promise<{
|
|
192
|
-
output: T;
|
|
193
|
-
detail?: Record<string, string | number | boolean>;
|
|
194
|
-
}>): Promise<GatedStateOpResult<T>>;
|
|
195
|
-
/** The digest a request binds, for a caller that prints it before it asks. */
|
|
196
|
-
export declare const stateOpDigest: (op: string, request: GatedRequest) => string;
|
|
164
|
+
export declare function terraformStateUnlock(input: TerraformStateUnlockInput): Promise<StateUnlockOutcome>;
|
|
197
165
|
/** The step input the gated capabilities share: the root and the request's rules. */
|
|
198
166
|
interface GatedRootInput {
|
|
199
167
|
root: string;
|
|
@@ -256,5 +224,4 @@ export declare const terraformStateOpCapabilities: readonly [Capability<StateUnl
|
|
|
256
224
|
root: string;
|
|
257
225
|
planDigest: string;
|
|
258
226
|
}>];
|
|
259
|
-
export {};
|
|
260
227
|
//# sourceMappingURL=state-ops.d.ts.map
|
package/dist/state-ops.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-ops.d.ts","sourceRoot":"","sources":["../src/state-ops.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state-ops.d.ts","sourceRoot":"","sources":["../src/state-ops.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,wCAAwC,CAAC;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAsB,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AACzH,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,EAAwC,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACrI,OAAO,EAAoE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGvL,OAAO,EAA8C,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAwD,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,iGAAiG;AACjG,eAAO,MAAM,SAAS;aACpB,MAAM,EAAE,WAAW;aACnB,OAAO,EAAE,YAAY;aACrB,MAAM,EAAE,iBAAiB;CACjB,CAAC;AAEX,2CAA2C;AAC3C,eAAO,MAAM,cAAc;aACzB,MAAM,EAAE,QAAQ;aAChB,OAAO,EAAE,SAAS;aAClB,MAAM,EAAE,cAAc;CACd,CAAC;AAEX,sEAAsE;AACtE,qBAAa,YAAa,SAAQ,KAAK;IAEnC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAC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O,MAAM,4BAA4B;UAnE6C,MAAM;QAAM,MAAM;;WAkBrB,MAAM,EAAE;;UA6BnB,MAAM;gBAAc,MAAM;GAoB0C,CAAC"}
|
package/dist/state-ops.js
CHANGED
|
@@ -34,13 +34,21 @@
|
|
|
34
34
|
* The exec is injectable (`./state/exec.ts`), and so is the gated-request
|
|
35
35
|
* ledger, so a test runs no binary and writes no ledger.
|
|
36
36
|
*/
|
|
37
|
-
import {
|
|
37
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
38
|
+
import { tmpdir } from "node:os";
|
|
38
39
|
import { join } from "node:path";
|
|
39
40
|
import { CHANT_EXIT } from "@intentius/chant/exit-codes";
|
|
40
|
-
import {
|
|
41
|
+
import { gatedRequestDigest } from "@intentius/chant/lifecycle/gated-request";
|
|
42
|
+
import { gatedOp } from "@intentius/chant/lifecycle/gated-op";
|
|
43
|
+
import { exportStateVersion, StateExportError } from "@intentius/chant/state-export";
|
|
44
|
+
import { parseLockInfo, releaseStateLock, StateUnlockError } from "@intentius/chant/state-unlock";
|
|
41
45
|
import { plannerForBinary, terraformChangeSetPart } from "./change-set.js";
|
|
42
46
|
import { DEFAULT_LOCK_TIMEOUT, lockTimeoutArgs } from "./lock-timeout.js";
|
|
47
|
+
import { initialisedBackend, isRefused, stateObject } from "./state/backend.js";
|
|
43
48
|
import { lastLines, runBinary } from "./state/exec.js";
|
|
49
|
+
import { gitlabState, gitlabStore, shownUrl } from "./state/gitlab.js";
|
|
50
|
+
import { stateStore } from "./state/store.js";
|
|
51
|
+
import { gitlabVersionSource, stateVersionSource } from "./state/versions.js";
|
|
44
52
|
/** The ops the gated requests of this module wait at, one per kind, as terragucci named them. */
|
|
45
53
|
export const STATE_OPS = {
|
|
46
54
|
unlock: "tf-unlock",
|
|
@@ -150,89 +158,124 @@ export async function planCopy(r) {
|
|
|
150
158
|
export async function applyPlanFile(r) {
|
|
151
159
|
await ran(r, ["apply", "-input=false", "-no-color", ...lockTimeoutArgs("apply", r.lockTimeout ?? DEFAULT_LOCK_TIMEOUT, r.env ?? process.env), r.planFile], "apply");
|
|
152
160
|
}
|
|
153
|
-
|
|
161
|
+
// ── the gate around them ────────────────────────────────────────────────────
|
|
162
|
+
// The walk itself is chant core's since #4762 (`@intentius/chant/lifecycle/gated-op`), engine-neutral; these names stay for the products written against them.
|
|
163
|
+
export { attachmentDigest, requestedAt } from "@intentius/chant/lifecycle/gated-op";
|
|
164
|
+
/** Run `act` once its request is approved: chant core's {@link gatedOp}. */
|
|
165
|
+
export const gatedStateOp = gatedOp;
|
|
166
|
+
/** The digest a request binds, for a caller that prints it before it asks. */
|
|
167
|
+
export const stateOpDigest = (op, request) => gatedRequestDigest(op, request);
|
|
154
168
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* its `at`; with none, `now`.
|
|
169
|
+
* Where a root's state is: init (in a data dir of its own unless `init` is
|
|
170
|
+
* false), then the backend init recorded. `act` runs while the data dir is
|
|
171
|
+
* there, with the env that names it, so a binary run inside it finds the
|
|
172
|
+
* root initialised; the data dir is removed after.
|
|
160
173
|
*/
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
.
|
|
170
|
-
|
|
174
|
+
async function withBackend(r, act, readOnly = false) {
|
|
175
|
+
const env = r.env ?? process.env;
|
|
176
|
+
if (r.init === false)
|
|
177
|
+
return act(objectOf(r.dir, env, r.binary, readOnly), env);
|
|
178
|
+
const data = mkdtempSync(join(tmpdir(), "chant-state-data-"));
|
|
179
|
+
try {
|
|
180
|
+
const benv = { ...env, TF_DATA_DIR: data };
|
|
181
|
+
await initRoot({ ...r, env: benv });
|
|
182
|
+
return await act(objectOf(r.dir, benv, r.binary, readOnly), benv);
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
rmSync(data, { recursive: true, force: true });
|
|
186
|
+
}
|
|
171
187
|
}
|
|
172
|
-
|
|
173
|
-
export const attachmentDigest = (attachment) => `sha256:${createHash("sha256").update(attachment).digest("hex")}`;
|
|
188
|
+
const isGitLab = (o) => "address" in o;
|
|
174
189
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* cannot be written is reported as `recorded: false`; the act already ran.
|
|
190
|
+
* The root's state. A read needs no lock file, so an s3 backend that locks
|
|
191
|
+
* with DynamoDB is read as one that takes the lock file: the refusal is
|
|
192
|
+
* about holding its lock, which a read never does. An http backend whose
|
|
193
|
+
* address is GitLab's state API is that state.
|
|
180
194
|
*/
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
195
|
+
function objectOf(dir, env, binary, readOnly) {
|
|
196
|
+
const o = stateObject(dir, env, undefined, binary);
|
|
197
|
+
if (!isRefused(o))
|
|
198
|
+
return o;
|
|
199
|
+
const recorded = initialisedBackend(dir, env);
|
|
200
|
+
if (o.backend === "http" && recorded?.type === "http")
|
|
201
|
+
return gitlabState(recorded.config, env) ?? o;
|
|
202
|
+
if (!readOnly || o.refused !== "no-lockfile")
|
|
203
|
+
return o;
|
|
204
|
+
return stateObject(dir, env, recorded ? { ...recorded, config: { ...recorded.config, use_lockfile: true } } : undefined, binary, { backendConfig: { use_lockfile: "true" } });
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* chant core's state export (`exportStateVersion`) of one root: its backend
|
|
208
|
+
* read by an init of its own, its versions read from the bucket or container
|
|
209
|
+
* (`./state/versions.ts`). Throws `StateExportError` for a backend that keeps
|
|
210
|
+
* no versions chant reads.
|
|
211
|
+
*/
|
|
212
|
+
export async function terraformStateExport(input) {
|
|
213
|
+
const source = await withBackend(input, async (object) => (isGitLab(object) ? gitlabVersionSource(gitlabStore(object, input.fetch)) : stateVersionSource(object, input.fetch)), true);
|
|
214
|
+
if ("refused" in source)
|
|
215
|
+
throw new StateExportError(`${input.root}: ${source.refused}`);
|
|
216
|
+
return exportStateVersion({ ...input, subject: input.root, source });
|
|
217
|
+
}
|
|
218
|
+
/** What a state lock release reads and releases. */
|
|
219
|
+
const RELEASES = "a lock release reads the lock of an s3 backend's lock file, a gcs backend, an azurerm backend and a GitLab-managed state";
|
|
220
|
+
/**
|
|
221
|
+
* A root's lock as chant core's lock release reads it: the lock its store
|
|
222
|
+
* holds (`StateStore.heldLock`: the s3 lock file, the gcs lock object, whose
|
|
223
|
+
* generation is the ID the binary takes, the azurerm lease), released with
|
|
224
|
+
* the binary's fixed `force-unlock` of that ID. A GitLab-managed state's lock
|
|
225
|
+
* is read by asking for it and released by its ID on the unlock address,
|
|
226
|
+
* which GitLab refuses for any other lock. A local state's lock goes with
|
|
227
|
+
* the process that took it, so it is refused.
|
|
228
|
+
*/
|
|
229
|
+
export function terraformLockSource(r) {
|
|
230
|
+
const o = r.object;
|
|
231
|
+
const parsed = (text, where, id) => {
|
|
232
|
+
const info = parseLockInfo(text);
|
|
233
|
+
if (!info)
|
|
234
|
+
throw new StateOpError(r.root, "a lock read", 0, `${where} holds no lock ID the binary wrote; read it, and remove it by hand if it is not a lock`);
|
|
235
|
+
return id ? { ...info, ID: id } : info;
|
|
224
236
|
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
237
|
+
if (isGitLab(o)) {
|
|
238
|
+
if (!o.lockAddress || !o.unlockAddress)
|
|
239
|
+
return { refused: `its http backend names no ${o.lockAddress ? "unlock_address (TF_HTTP_UNLOCK_ADDRESS)" : "lock_address (TF_HTTP_LOCK_ADDRESS)"}, so no lock it takes can be read and released` };
|
|
240
|
+
const store = gitlabStore(o, r.fetch);
|
|
241
|
+
const location = shownUrl(o.lockAddress);
|
|
242
|
+
return {
|
|
243
|
+
location,
|
|
244
|
+
read: async () => {
|
|
245
|
+
const text = await store.probeLock();
|
|
246
|
+
return text === undefined ? undefined : parsed(text, location);
|
|
247
|
+
},
|
|
248
|
+
release: (id) => store.releaseLock(id),
|
|
249
|
+
};
|
|
232
250
|
}
|
|
251
|
+
if (isRefused(o))
|
|
252
|
+
return { refused: `${o.reason}; ${RELEASES}` };
|
|
253
|
+
if (o.backend === "local")
|
|
254
|
+
return { refused: `the state is a local file, whose lock goes with the process that took it; ${RELEASES}` };
|
|
255
|
+
const store = stateStore(o, r.dir, r.fetch);
|
|
256
|
+
return {
|
|
257
|
+
location: store.lockLocation,
|
|
258
|
+
async read() {
|
|
259
|
+
const held = await store.heldLock();
|
|
260
|
+
return held ? parsed(held.info, store.lockLocation, held.id || undefined) : undefined;
|
|
261
|
+
},
|
|
262
|
+
release: (id) => forceUnlockState({ ...r, id }),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* chant core's lock release (`releaseStateLock`) of one root's state: its
|
|
267
|
+
* backend read by an init of its own, the lock read from the store, released
|
|
268
|
+
* by `force-unlock` in the same data dir. Throws `StateUnlockError` for a
|
|
269
|
+
* backend whose lock chant does not read.
|
|
270
|
+
*/
|
|
271
|
+
export async function terraformStateUnlock(input) {
|
|
272
|
+
return withBackend(input, async (object, env) => {
|
|
273
|
+
const lock = terraformLockSource({ ...input, env, object, ...(input.fetch ? { fetch: input.fetch } : {}) });
|
|
274
|
+
if ("refused" in lock)
|
|
275
|
+
throw new StateUnlockError(`${input.root}: ${lock.refused}`);
|
|
276
|
+
return releaseStateLock({ ...input, subject: input.root, lock });
|
|
277
|
+
});
|
|
233
278
|
}
|
|
234
|
-
/** The digest a request binds, for a caller that prints it before it asks. */
|
|
235
|
-
export const stateOpDigest = (op, request) => gatedRequestDigest(op, request);
|
|
236
279
|
const actorOf = (env) => env.GITHUB_ACTOR || env.GITLAB_USER_LOGIN || env.USER || env.USERNAME || "unknown";
|
|
237
280
|
const dirOf = (cwd, input) => input.dir ?? join(cwd ?? process.cwd(), input.root);
|
|
238
281
|
async function gatedRun(op, input, kind, fields, act, attachment) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-terraform",
|
|
3
|
-
"version": "0.124.
|
|
3
|
+
"version": "0.124.78",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src/",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"access": "public"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
|
-
"@intentius/chant": "^0.124.
|
|
96
|
+
"@intentius/chant": "^0.124.78",
|
|
97
97
|
"zod": "^4.3.6"
|
|
98
98
|
},
|
|
99
99
|
"description": "terraform lexicon for chant, existing Terraform root modules as declarable entities",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format_version": "1.2",
|
|
3
|
+
"terraform_version": "1.9.8",
|
|
4
|
+
"resource_drift": [
|
|
5
|
+
{
|
|
6
|
+
"address": "module.service.aws_sqs_queue.jobs[\"orders\"]",
|
|
7
|
+
"module_address": "module.service",
|
|
8
|
+
"mode": "managed",
|
|
9
|
+
"type": "aws_sqs_queue",
|
|
10
|
+
"name": "jobs",
|
|
11
|
+
"index": "orders",
|
|
12
|
+
"provider_name": "registry.terraform.io/hashicorp/aws",
|
|
13
|
+
"change": {
|
|
14
|
+
"actions": ["update"],
|
|
15
|
+
"before": { "name": "shop-orders-jobs", "visibility_timeout_seconds": 30, "tags": { "team": "a" }, "kms_data_key": "hunter2" },
|
|
16
|
+
"after": { "name": "shop-orders-jobs", "visibility_timeout_seconds": 45, "tags": { "team": "b" }, "kms_data_key": "hunter2" },
|
|
17
|
+
"after_unknown": {},
|
|
18
|
+
"before_sensitive": { "kms_data_key": true, "tags": {} },
|
|
19
|
+
"after_sensitive": { "kms_data_key": true, "tags": {} }
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"address": "aws_instance.web",
|
|
24
|
+
"mode": "managed",
|
|
25
|
+
"type": "aws_instance",
|
|
26
|
+
"name": "web",
|
|
27
|
+
"deposed": "00000001",
|
|
28
|
+
"provider_name": "registry.terraform.io/hashicorp/aws",
|
|
29
|
+
"change": {
|
|
30
|
+
"actions": ["delete"],
|
|
31
|
+
"before": { "id": "i-0001", "instance_type": "t3.micro" },
|
|
32
|
+
"after": null,
|
|
33
|
+
"after_unknown": {},
|
|
34
|
+
"before_sensitive": {},
|
|
35
|
+
"after_sensitive": false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"resource_changes": [
|
|
40
|
+
{
|
|
41
|
+
"address": "aws_s3_bucket.code_only",
|
|
42
|
+
"mode": "managed",
|
|
43
|
+
"type": "aws_s3_bucket",
|
|
44
|
+
"name": "code_only",
|
|
45
|
+
"change": { "actions": ["create"], "before": null, "after": { "bucket": "waiting-on-main" } }
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
package/src/drift-record.test.ts
CHANGED
|
@@ -14,9 +14,11 @@ import {
|
|
|
14
14
|
choudoufuLiveLsDriftRecords,
|
|
15
15
|
choudoufuLivePlanDriftRecords,
|
|
16
16
|
choudoufuLivePlusPlanDriftRecords,
|
|
17
|
+
terraformLivePlanDriftRecords,
|
|
17
18
|
terraformPlanDriftRecords,
|
|
18
19
|
terraformStateDriftRecords,
|
|
19
20
|
} from "./drift-record";
|
|
21
|
+
import { terraformPlanDriftRows } from "./drift-rows";
|
|
20
22
|
|
|
21
23
|
const FIX = join(import.meta.dirname, "__fixtures__");
|
|
22
24
|
const read = (...path: string[]): unknown => JSON.parse(readFileSync(join(FIX, ...path), "utf-8"));
|
|
@@ -221,3 +223,63 @@ describe("choudoufu live+plan", () => {
|
|
|
221
223
|
roundTrip(records);
|
|
222
224
|
});
|
|
223
225
|
});
|
|
226
|
+
|
|
227
|
+
describe("a live root's full plan, read as drift (#4812)", () => {
|
|
228
|
+
const records = terraformLivePlanDriftRecords({ member: "estate", observedAt: AT, plan: read("live-plan-depth", "show-plan.json") });
|
|
229
|
+
|
|
230
|
+
test("a planned create is missing, an update drifted declared then live, a no-op in-sync, all read plan", () => {
|
|
231
|
+
expect(statusOf(records)).toEqual({
|
|
232
|
+
"aws_cloudwatch_log_group.adoptable": "missing",
|
|
233
|
+
"aws_cloudwatch_log_group.app": "drifted",
|
|
234
|
+
"aws_cloudwatch_log_group.held_elsewhere": "missing",
|
|
235
|
+
"aws_cloudwatch_log_group.never_applied": "missing",
|
|
236
|
+
"aws_eip.pool[0]": "in-sync",
|
|
237
|
+
"aws_eip.pool[1]": "in-sync",
|
|
238
|
+
"aws_security_group.main": "in-sync",
|
|
239
|
+
"aws_security_group_rule.https": "missing",
|
|
240
|
+
"aws_subnet.app": "in-sync",
|
|
241
|
+
"aws_vpc.adoptable": "missing",
|
|
242
|
+
"aws_vpc.main": "drifted",
|
|
243
|
+
});
|
|
244
|
+
const app = at(records, "aws_cloudwatch_log_group.app");
|
|
245
|
+
expect(app).toMatchObject({ engine: "choudoufu", read: "plan", resourceType: "aws_cloudwatch_log_group", evidence: { tool: "choudoufu", command: "choudoufu show -json" } });
|
|
246
|
+
expect(app.attributes).toContainEqual({ path: "retention_in_days", before: 1, after: 3 });
|
|
247
|
+
expect(at(records, "aws_eip.pool[0]").instanceOf).toBe(at(records, "aws_eip.pool[1]").instanceOf);
|
|
248
|
+
roundTrip(records);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("the records that are not in-sync are drift-rows' live rows", () => {
|
|
252
|
+
for (const plan of [read("live-plan-depth", "show-plan.json"), read("drift-rows", "live-root-plan.json")]) {
|
|
253
|
+
const drifted = terraformLivePlanDriftRecords({ member: "estate", observedAt: AT, plan }).filter((r) => r.status !== "in-sync");
|
|
254
|
+
expect(drifted.map((r) => r.address)).toEqual(terraformPlanDriftRows(plan, { live: true }).map((r) => r.address).sort());
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("a delete is undeclared, a replacement drifted, and a value known only after the apply is no difference", () => {
|
|
259
|
+
const live = terraformLivePlanDriftRecords({ member: "estate", observedAt: AT, engine: "tofu", plan: read("drift-rows", "live-root-plan.json") });
|
|
260
|
+
expect(statusOf(live)).toEqual({
|
|
261
|
+
"aws_iam_role.deployer": "drifted",
|
|
262
|
+
"aws_lambda_function.api": "drifted",
|
|
263
|
+
"aws_s3_bucket.assets": "missing",
|
|
264
|
+
"aws_s3_bucket.steady": "in-sync",
|
|
265
|
+
"aws_security_group.edge": "drifted",
|
|
266
|
+
"aws_sqs_queue.stray": "undeclared",
|
|
267
|
+
});
|
|
268
|
+
expect(at(live, "aws_lambda_function.api").attributes).toEqual([{ path: "memory_size", before: 512, after: 256 }]);
|
|
269
|
+
expect(at(live, "aws_lambda_function.api").evidence).toEqual({ tool: "tofu", version: "1.9.8", command: "tofu show -json" });
|
|
270
|
+
roundTrip(live);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("a sensitive value never leaves, on either side", () => {
|
|
274
|
+
const sensitive = terraformLivePlanDriftRecords({ member: "estate", observedAt: AT, plan: read("live-plan-depth", "show-plan-sensitive.json") });
|
|
275
|
+
expect(at(sensitive, "aws_vpc.main").attributes).toContainEqual({ path: "tags.token", sensitive: true });
|
|
276
|
+
const text = JSON.stringify(driftDocument(sensitive));
|
|
277
|
+
expect(text).not.toContain("hunter2");
|
|
278
|
+
expect(text).not.toContain("hunter3");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("a stock root's plan reader is unchanged: the same plan's changes read as in-sync or pending, not drift", () => {
|
|
282
|
+
const stock = terraformPlanDriftRecords({ member: "estate", observedAt: AT, plan: read("live-plan-depth", "show-plan.json") });
|
|
283
|
+
expect(stock.some((r) => r.status === "drifted" || r.status === "missing")).toBe(false);
|
|
284
|
+
});
|
|
285
|
+
});
|