@intentius/chant-lexicon-azure 0.124.38 → 0.124.40

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.
Files changed (44) hide show
  1. package/dist/components/arm-deploy.d.ts +80 -0
  2. package/dist/components/arm-deploy.d.ts.map +1 -0
  3. package/dist/components/arm-deploy.js +398 -0
  4. package/dist/components/capability-plugin.d.ts +6 -0
  5. package/dist/components/capability-plugin.d.ts.map +1 -0
  6. package/dist/components/capability-plugin.js +17 -0
  7. package/dist/components/index.d.ts +3 -0
  8. package/dist/components/index.d.ts.map +1 -0
  9. package/dist/components/index.js +2 -0
  10. package/dist/composites/catalog.d.ts.map +1 -1
  11. package/dist/composites/catalog.js +120 -0
  12. package/dist/composites/container-app.d.ts +102 -0
  13. package/dist/composites/container-app.d.ts.map +1 -0
  14. package/dist/composites/container-app.js +130 -0
  15. package/dist/composites/index.d.ts +2 -0
  16. package/dist/composites/index.d.ts.map +1 -1
  17. package/dist/composites/index.js +1 -0
  18. package/dist/deep-observe.d.ts +30 -0
  19. package/dist/deep-observe.d.ts.map +1 -1
  20. package/dist/deep-observe.js +1 -1
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +4 -1
  24. package/dist/integrity.json +5 -5
  25. package/dist/manifest.json +1 -1
  26. package/dist/skills/chant-azure-patterns.md +16 -0
  27. package/dist/skills/chant-azure-security.md +1 -0
  28. package/dist/skills/chant-azure.md +2 -0
  29. package/package.json +7 -2
  30. package/src/components/arm-deploy-floci.e2e.test.ts +80 -0
  31. package/src/components/arm-deploy.test.ts +256 -0
  32. package/src/components/arm-deploy.ts +491 -0
  33. package/src/components/capability-plugin.ts +26 -0
  34. package/src/components/index.ts +9 -0
  35. package/src/composites/catalog.ts +120 -0
  36. package/src/composites/composites.test.ts +128 -0
  37. package/src/composites/container-app.ts +230 -0
  38. package/src/composites/index.ts +5 -0
  39. package/src/deep-observe.ts +2 -2
  40. package/src/index.ts +5 -0
  41. package/src/plugin.test.ts +10 -0
  42. package/src/skills/chant-azure-patterns.md +16 -0
  43. package/src/skills/chant-azure-security.md +1 -0
  44. package/src/skills/chant-azure.md +2 -0
@@ -0,0 +1,491 @@
1
+ /**
2
+ * `arm-deploy`: the azure lexicon's apply step for components (#4273). It
3
+ * applies a built ARM template into one resource group through `azApply`
4
+ * (../op/activities/az-apply.ts), the same per-resource applier `ApplyOp`'s
5
+ * `arm` target and the floci-az lane use, so a component step, an Op and the
6
+ * emulator run share one code path.
7
+ *
8
+ * `plan` reads each template resource live with the read client
9
+ * (../api/read-client.ts) and compares it with the body `azApply` would PUT,
10
+ * normalized with the noise rules deep observation uses
11
+ * (../deep-observe.ts). A resource that is not there is a create, one whose
12
+ * claimed properties all match is a no-op, and one that differs is an update
13
+ * with each changed path before and after. With `prune: true`, each
14
+ * chant-owned resource in the group the template no longer declares is a
15
+ * delete, the set `pruneArmOrphans` would delete.
16
+ *
17
+ * ARM's PUT is a create-or-update with no preview, so the plan cannot ask
18
+ * Azure what would change the way `cfn-deploy` asks for a change set. What
19
+ * holds the apply to the approved plan is the digest: `run` plans again and
20
+ * applies only when it gets the approved one.
21
+ */
22
+
23
+ import { createHash } from "node:crypto";
24
+ import { readFileSync } from "node:fs";
25
+ import type { Capability, CapabilityPlan, DeployContext, PlannedOutputs } from "@intentius/chant/components/capability";
26
+ import type { ChangeSetAttribute, ChangeSetEntry, ChangeSetHole, ChangeSetPart } from "@intentius/chant/change-set";
27
+ import { MASKED, UNRESOLVED, deepPathSet, flattenDeepProperties, normalizeDeepProperties } from "@intentius/chant/deep-observation";
28
+ import { diffDeep } from "@intentius/chant/lifecycle/deep-diff";
29
+ import { computePlanDigest } from "@intentius/chant/lifecycle/plan-digest";
30
+ import { AzureReadError, getResource, isNotFound, listResources, type AzureReadClientOptions } from "../api/read-client";
31
+ import { azureDeepNormalizationHooks, buildLiveProperties, type ArmResourceShowResponse } from "../deep-observe";
32
+ import { classifyArmFailure } from "../describe-resources";
33
+ import {
34
+ armDependencies,
35
+ azApply,
36
+ evalArm,
37
+ evalArmString,
38
+ isChantOwned,
39
+ orderArmResources,
40
+ rememberDeployed,
41
+ type ArmEvalCtx,
42
+ type ArmResource,
43
+ type AzHttp,
44
+ type AzNotPrunable,
45
+ } from "../op/activities/az-apply";
46
+
47
+ /** floci-az's local subscription, the applier's default too. */
48
+ const DEFAULT_SUBSCRIPTION = "00000000-0000-0000-0000-000000000001";
49
+ const DEFAULT_ENDPOINT = "https://management.azure.com";
50
+ const DEFAULT_LOCATION = "eastus";
51
+
52
+ export interface ArmDeployInput {
53
+ /** Path to the built ARM template (`deploymentTemplate.json`). */
54
+ template: string;
55
+ /** The resource group the template applies into. Default: the component's name. */
56
+ resourceGroup?: string;
57
+ /** Region for the group and for `resourceGroup().location`. Default: `eastus`. */
58
+ location?: string;
59
+ /** ARM endpoint. Default: `AZURE_ENDPOINT_URL`, else real Azure. */
60
+ endpoint?: string;
61
+ /** Subscription id. Default: `AZURE_SUBSCRIPTION_ID`, else floci-az's local subscription. */
62
+ subscriptionId?: string;
63
+ /** Delete chant-owned resources of the group the template no longer declares. Default: false. */
64
+ prune?: boolean;
65
+ }
66
+
67
+ export interface ArmDeployOutput {
68
+ applied: Array<{ type: string; name: string }>;
69
+ pruned: Array<{ type: string; name: string; deleted: boolean }>;
70
+ notPrunable: AzNotPrunable[];
71
+ /** The template's `outputs`, evaluated against the group once it applied. */
72
+ outputs: Record<string, unknown>;
73
+ }
74
+
75
+ /** What an `arm-deploy` plan hands `run` through `DeployContext.plans[resourceGroup]`. */
76
+ export interface ArmDeployPlanArtifact {
77
+ kind: "arm-deploy-plan";
78
+ resourceGroup: string;
79
+ planDigest: string;
80
+ }
81
+
82
+ function isArmDeployPlanArtifact(value: unknown): value is ArmDeployPlanArtifact {
83
+ const v = value as Partial<ArmDeployPlanArtifact> | undefined;
84
+ return v?.kind === "arm-deploy-plan" && typeof v.resourceGroup === "string" && typeof v.planDigest === "string";
85
+ }
86
+
87
+ /**
88
+ * Thrown by `run` when planning again gives another digest than the approved
89
+ * plan: the group, the template or the endpoint moved since. Nothing is
90
+ * applied. `planMoved` is core's mark for a moved plan, so the command exits 3.
91
+ */
92
+ export class ArmDeployPlanMovedError extends Error {
93
+ readonly planMoved = true;
94
+ constructor(
95
+ public readonly resourceGroup: string,
96
+ public readonly planned: string,
97
+ public readonly now: string,
98
+ ) {
99
+ super(
100
+ `arm-deploy "${resourceGroup}": refusing to apply. Planning again gives ${now}, the approved plan was ${planned}; ` +
101
+ `the resource group or its template changed since. Plan it again.`,
102
+ );
103
+ this.name = "ArmDeployPlanMovedError";
104
+ }
105
+ }
106
+
107
+ /** The settings a step resolves to, environment included. Read at call time so a test or an emulator lane can set them. */
108
+ interface Target {
109
+ resourceGroup: string;
110
+ location: string;
111
+ endpoint: string;
112
+ subscriptionId: string;
113
+ }
114
+
115
+ function targetOf(ctx: DeployContext, input: ArmDeployInput): Target {
116
+ return {
117
+ resourceGroup: input.resourceGroup ?? ctx.component,
118
+ location: input.location ?? DEFAULT_LOCATION,
119
+ endpoint: (input.endpoint ?? process.env.AZURE_ENDPOINT_URL ?? DEFAULT_ENDPOINT).replace(/\/$/, ""),
120
+ subscriptionId: input.subscriptionId ?? process.env.AZURE_SUBSCRIPTION_ID ?? DEFAULT_SUBSCRIPTION,
121
+ };
122
+ }
123
+
124
+ function evalCtxOf(target: Target, http: AzHttp): ArmEvalCtx {
125
+ return {
126
+ subscriptionId: target.subscriptionId,
127
+ resourceGroup: target.resourceGroup,
128
+ location: target.location,
129
+ deployed: new Map(),
130
+ http,
131
+ base: target.endpoint,
132
+ };
133
+ }
134
+
135
+ function clientOf(target: Target, http: AzHttp): AzureReadClientOptions {
136
+ return { endpoint: target.endpoint, subscriptionId: target.subscriptionId, resourceGroup: target.resourceGroup, http };
137
+ }
138
+
139
+ interface ArmTemplate {
140
+ resources?: ArmResource[];
141
+ outputs?: Record<string, { type?: string; value?: unknown }>;
142
+ }
143
+
144
+ function readTemplate(path: string): ArmTemplate {
145
+ return JSON.parse(readFileSync(path, "utf8")) as ArmTemplate;
146
+ }
147
+
148
+ function templateDigest(path: string): string | null {
149
+ try {
150
+ return `sha256:${createHash("sha256").update(readFileSync(path)).digest("hex")}`;
151
+ } catch {
152
+ return null;
153
+ }
154
+ }
155
+
156
+ /**
157
+ * A 404 that means the resource is not there, as opposed to one that means the
158
+ * subscription is not: ARM answers `SubscriptionNotFound` with a 404 too, and
159
+ * planning every resource as a create on that answer would be wrong. A missing
160
+ * resource group is absence, since `azApply` creates the group first.
161
+ */
162
+ function isAbsent(err: unknown): boolean {
163
+ return isNotFound(err) && !(err instanceof AzureReadError && /^SubscriptionNotFound$/i.test(err.code ?? ""));
164
+ }
165
+
166
+ // ── The declared side ────────────────────────────────────────────────────────
167
+
168
+ /** An expression that reads a resource's runtime state, which only an apply knows. */
169
+ const RUNTIME_READ = /\b(reference|list[A-Za-z]*)\s*\(/;
170
+
171
+ /**
172
+ * Evaluate one string the way `azApply` would, leaving an expression that
173
+ * reads runtime state (`reference()`, `listKeys()`) or uses a function the
174
+ * evaluator lacks as written. The noise rules read a bracket expression on
175
+ * the declared side as unresolved, so it is never compared, and the plan
176
+ * makes no `listKeys` call.
177
+ */
178
+ async function evalStaticString(s: string, ctx: ArmEvalCtx): Promise<unknown> {
179
+ if (!(s.startsWith("[") && s.endsWith("]")) || s.startsWith("[[")) return evalArmString(s, ctx);
180
+ if (RUNTIME_READ.test(s)) return s;
181
+ try {
182
+ return await evalArmString(s, ctx);
183
+ } catch {
184
+ return s;
185
+ }
186
+ }
187
+
188
+ async function evalStatic(value: unknown, ctx: ArmEvalCtx): Promise<unknown> {
189
+ if (typeof value === "string") return evalStaticString(value, ctx);
190
+ if (Array.isArray(value)) return Promise.all(value.map((v) => evalStatic(v, ctx)));
191
+ if (value && typeof value === "object") {
192
+ const out: Record<string, unknown> = {};
193
+ for (const [k, v] of Object.entries(value)) out[String(await evalStaticString(k, ctx))] = await evalStatic(v, ctx);
194
+ return out;
195
+ }
196
+ return value;
197
+ }
198
+
199
+ /**
200
+ * The fields `azApply` PUTs for a resource, in the flat shape deep
201
+ * observation reads a live resource into. The ownership tags `azApply` adds
202
+ * are left out: the noise rules drop them from the live side too.
203
+ */
204
+ async function declaredTree(resource: ArmResource, name: string, ctx: ArmEvalCtx): Promise<Record<string, unknown>> {
205
+ const body: ArmResourceShowResponse = { name };
206
+ if (resource.location !== undefined) body.location = (await evalStatic(resource.location, ctx)) as string;
207
+ for (const field of ["sku", "kind", "identity", "tags", "zones", "plan", "properties"] as const) {
208
+ if (resource[field] !== undefined) (body as Record<string, unknown>)[field] = await evalStatic(resource[field], ctx);
209
+ }
210
+ return buildLiveProperties(body, name);
211
+ }
212
+
213
+ // ── The plan ─────────────────────────────────────────────────────────────────
214
+
215
+ /** One template resource as the plan read it. */
216
+ interface PlannedResource {
217
+ resource: ArmResource;
218
+ name: string;
219
+ action: "create" | "update" | "no-op" | "unread";
220
+ }
221
+
222
+ interface ArmPlanResult {
223
+ entries: ChangeSetEntry[];
224
+ holes: ChangeSetHole[];
225
+ resources: PlannedResource[];
226
+ /** The live bodies read, remembered for `reference()`. */
227
+ live: ArmEvalCtx;
228
+ template: ArmTemplate;
229
+ }
230
+
231
+ function attributeOf(path: string, before: unknown, after: unknown, hasBefore: boolean, hasAfter: boolean): ChangeSetAttribute {
232
+ if (before === MASKED || after === MASKED) return { path, sensitive: true };
233
+ if (after === UNRESOLVED) return { path, ...(hasBefore ? { before } : {}), unknown: true };
234
+ return { path, ...(hasBefore ? { before } : {}), ...(hasAfter ? { after } : {}) };
235
+ }
236
+
237
+ /** Read the group and compare it with the template. Pure apart from GETs. */
238
+ async function readPlan(member: string, target: Target, input: ArmDeployInput, http: AzHttp): Promise<ArmPlanResult> {
239
+ const template = readTemplate(input.template);
240
+ const resources = template.resources ?? [];
241
+ const ctx = evalCtxOf(target, http);
242
+ const client = clientOf(target, http);
243
+ const entries: ChangeSetEntry[] = [];
244
+ const holes: ChangeSetHole[] = [];
245
+ const planned: PlannedResource[] = [];
246
+ const base = (type: string, name: string) => ({
247
+ member,
248
+ lexicon: "azure",
249
+ planner: "chant" as const,
250
+ address: `${type}/${name}`,
251
+ type,
252
+ name,
253
+ });
254
+
255
+ for (const resource of orderArmResources(resources)) {
256
+ const name = String(await evalStaticString(resource.name, ctx));
257
+ const address = `${resource.type}/${name}`;
258
+ if (name.startsWith("[")) {
259
+ holes.push({ address, type: resource.type, reason: "the resource's name reads runtime state; known only at apply" });
260
+ planned.push({ resource, name, action: "unread" });
261
+ continue;
262
+ }
263
+ const declaredRaw = await declaredTree(resource, name, ctx);
264
+ let live: ArmResourceShowResponse | undefined;
265
+ try {
266
+ live = (await getResource(client, resource.type, name, resource.apiVersion)) as ArmResourceShowResponse;
267
+ } catch (err) {
268
+ if (!isAbsent(err)) {
269
+ const failure = classifyArmFailure(err);
270
+ holes.push({ address, type: resource.type, reason: `${failure.reason}: ${failure.detail}` });
271
+ planned.push({ resource, name, action: "unread" });
272
+ continue;
273
+ }
274
+ }
275
+ const opts = { entityType: resource.type, hooks: azureDeepNormalizationHooks };
276
+
277
+ if (!live) {
278
+ const declared = normalizeDeepProperties(declaredRaw, { ...opts, side: "declared" });
279
+ const attributes = [...flattenDeepProperties(declared, { ...opts, side: "declared" })]
280
+ .map(([path, value]) => attributeOf(path, undefined, value, false, true))
281
+ .sort((a, b) => a.path.localeCompare(b.path));
282
+ entries.push({ ...base(resource.type, name), action: "create", attributes });
283
+ planned.push({ resource, name, action: "create" });
284
+ continue;
285
+ }
286
+
287
+ rememberDeployed(ctx, resource.type, name, live);
288
+ const liveRaw = buildLiveProperties(live, name);
289
+ const declared = normalizeDeepProperties(declaredRaw, { ...opts, side: "declared", counterpartPaths: deepPathSet(liveRaw) });
290
+ const liveTree = normalizeDeepProperties(liveRaw, { ...opts, side: "live", counterpartPaths: deepPathSet(declaredRaw) });
291
+ const diff = diffDeep({
292
+ declared: { [address]: { type: resource.type, properties: declared } },
293
+ live: { resources: { [address]: { type: resource.type, properties: liveTree } }, unobserved: {} },
294
+ hooks: azureDeepNormalizationHooks,
295
+ });
296
+ // A masked value ARM does not return (a password) is write-only, not a change.
297
+ const changes = (diff.drifted[0]?.changes ?? []).filter((c) => !(c.kind === "absent" && c.declared === MASKED));
298
+ const id = typeof live.id === "string" ? { id: live.id } : {};
299
+ if (changes.length === 0) {
300
+ entries.push({ ...base(resource.type, name), ...id, action: "no-op", attributes: [] });
301
+ planned.push({ resource, name, action: "no-op" });
302
+ continue;
303
+ }
304
+ const attributes = changes
305
+ .map((c) => attributeOf(c.path, c.live, c.declared, c.kind === "changed", true))
306
+ .sort((a, b) => a.path.localeCompare(b.path));
307
+ entries.push({ ...base(resource.type, name), ...id, action: "update", disruption: "in-place", attributes });
308
+ planned.push({ resource, name, action: "update" });
309
+ }
310
+
311
+ if (input.prune) {
312
+ // The set `pruneArmOrphans` deletes: chant-owned, of any type, and not declared by (type, name).
313
+ const keep = new Set(planned.map((p) => `${p.resource.type}\0${p.name}`));
314
+ try {
315
+ for (const item of await listResources(client)) {
316
+ if (typeof item.type !== "string" || typeof item.name !== "string") continue;
317
+ if (!isChantOwned(item.tags)) continue;
318
+ if (keep.has(`${item.type}\0${item.name}`)) continue;
319
+ entries.push({
320
+ ...base(item.type, item.name),
321
+ ...(typeof item.id === "string" ? { id: item.id } : {}),
322
+ action: "delete",
323
+ disruption: "destroy",
324
+ attributes: [],
325
+ });
326
+ }
327
+ } catch (err) {
328
+ if (!isAbsent(err)) {
329
+ const failure = classifyArmFailure(err);
330
+ holes.push({ address: target.resourceGroup, type: "Microsoft.Resources/resourceGroups", reason: `prune not read: ${failure.reason}: ${failure.detail}` });
331
+ }
332
+ }
333
+ }
334
+
335
+ entries.sort((a, b) => a.address.localeCompare(b.address));
336
+ holes.sort((a, b) => a.address.localeCompare(b.address));
337
+ return { entries, holes, resources: planned, live: ctx, template };
338
+ }
339
+
340
+ function armPlanDigest(ctx: DeployContext, target: Target, input: ArmDeployInput, unresolved: string[], plan?: Pick<ArmPlanResult, "entries" | "holes">): string {
341
+ return computePlanDigest("arm-deploy-plan", {
342
+ env: ctx.env,
343
+ ...target,
344
+ template: input.template,
345
+ templateDigest: templateDigest(input.template),
346
+ prune: input.prune ?? false,
347
+ unresolved,
348
+ ...(plan ? { entries: plan.entries, holes: plan.holes } : {}),
349
+ });
350
+ }
351
+
352
+ /** The template's outputs evaluated against `ctx`, leaving out each one that evaluates to nothing. */
353
+ async function evaluateOutputs(
354
+ outputs: ArmTemplate["outputs"],
355
+ ctx: ArmEvalCtx,
356
+ only?: (name: string) => boolean,
357
+ ): Promise<{ known: Record<string, unknown>; unknown: string[] }> {
358
+ const known: Record<string, unknown> = {};
359
+ const unknown: string[] = [];
360
+ for (const [name, output] of Object.entries(outputs ?? {})) {
361
+ if (only && !only(name)) {
362
+ unknown.push(name);
363
+ continue;
364
+ }
365
+ let value: unknown;
366
+ try {
367
+ value = await evalArm(output?.value, ctx);
368
+ } catch {
369
+ value = undefined;
370
+ }
371
+ if (value === undefined) unknown.push(name);
372
+ else known[name] = value;
373
+ }
374
+ return { known, unknown: unknown.sort() };
375
+ }
376
+
377
+ /**
378
+ * What the plan says of the template's outputs: an output whose value reads
379
+ * only resources the plan leaves as they are is known from the live read.
380
+ * Every other one is known only after apply.
381
+ */
382
+ async function plannedOutputs(plan: ArmPlanResult): Promise<PlannedOutputs> {
383
+ const names = new Set(plan.resources.map((r) => r.resource.name));
384
+ const changing = new Set(plan.resources.filter((r) => r.action !== "no-op").map((r) => r.resource.name));
385
+ return evaluateOutputs(plan.template.outputs, plan.live, (name) => {
386
+ const value = plan.template.outputs?.[name]?.value;
387
+ const reads = armDependencies({ type: "", apiVersion: "", name: "", properties: value }, names);
388
+ return reads.every((r) => !changing.has(r));
389
+ });
390
+ }
391
+
392
+ /** Read every template resource live and evaluate the template's outputs against them. */
393
+ async function liveOutputs(target: Target, input: ArmDeployInput, http: AzHttp): Promise<Record<string, unknown>> {
394
+ const template = readTemplate(input.template);
395
+ if (Object.keys(template.outputs ?? {}).length === 0) return {};
396
+ const ctx = evalCtxOf(target, http);
397
+ const client = clientOf(target, http);
398
+ for (const resource of orderArmResources(template.resources ?? [])) {
399
+ const name = String(await evalStaticString(resource.name, ctx));
400
+ if (name.startsWith("[")) continue;
401
+ try {
402
+ rememberDeployed(ctx, resource.type, name, await getResource(client, resource.type, name, resource.apiVersion));
403
+ } catch (err) {
404
+ if (!isAbsent(err)) throw err;
405
+ }
406
+ }
407
+ return (await evaluateOutputs(template.outputs, ctx)).known;
408
+ }
409
+
410
+ async function planArmDeploy(http: AzHttp, ctx: DeployContext, input: ArmDeployInput): Promise<CapabilityPlan> {
411
+ const target = targetOf(ctx, input);
412
+ const member = target.resourceGroup;
413
+ const unresolved = [...(ctx.unresolvedInputs ?? [])].sort();
414
+ const memberOf = (planDigest: string, holes: ChangeSetHole[]): ChangeSetPart["member"] => ({
415
+ member,
416
+ lexicon: "azure",
417
+ planner: "chant",
418
+ status: "planned",
419
+ planDigest,
420
+ holes,
421
+ });
422
+
423
+ if (unresolved.length > 0) {
424
+ const planDigest = armPlanDigest(ctx, target, input, unresolved);
425
+ const hole = { address: member, type: "Microsoft.Resources/resourceGroups", reason: `inputs from ${unresolved.join(", ")}; re-checked on apply` };
426
+ return { member, planDigest, changeSet: { member: memberOf(planDigest, [hole]), entries: [] } };
427
+ }
428
+
429
+ const plan = await readPlan(member, target, input, http);
430
+ const planDigest = armPlanDigest(ctx, target, input, unresolved, plan);
431
+ const outputs = await plannedOutputs(plan);
432
+ // A plan with a hole hands `run` nothing to hold it to, as `cfn-deploy`'s does not.
433
+ const artifact: ArmDeployPlanArtifact | undefined = plan.holes.length === 0 ? { kind: "arm-deploy-plan", resourceGroup: member, planDigest } : undefined;
434
+ return {
435
+ member,
436
+ planDigest,
437
+ ...(artifact ? { artifact } : {}),
438
+ changeSet: { member: memberOf(planDigest, plan.holes), entries: plan.entries },
439
+ outputs,
440
+ };
441
+ }
442
+
443
+ /**
444
+ * The `arm-deploy` capability over an injectable HTTP transport (the
445
+ * `AzHttp` seam `azApply` and the read client share). Tests pass a fake;
446
+ * the default is `fetch`.
447
+ */
448
+ export function createArmDeployCapability(options: { http?: AzHttp } = {}): Capability<ArmDeployInput, ArmDeployOutput> {
449
+ const http: AzHttp = options.http ?? (async (method, url, body, signal) => {
450
+ const res = await fetch(url, {
451
+ method,
452
+ headers: body === undefined ? undefined : { "content-type": "application/json" },
453
+ body: body === undefined ? undefined : JSON.stringify(body),
454
+ signal,
455
+ });
456
+ return { status: res.status, text: await res.text() };
457
+ });
458
+ return {
459
+ kind: "arm-deploy",
460
+ plan(ctx, input) {
461
+ return planArmDeploy(http, ctx, input);
462
+ },
463
+ outputs(ctx, input) {
464
+ return liveOutputs(targetOf(ctx, input), input, http);
465
+ },
466
+ async run(ctx, input) {
467
+ const target = targetOf(ctx, input);
468
+ const approved = ctx.plans?.[target.resourceGroup];
469
+ if (isArmDeployPlanArtifact(approved)) {
470
+ const now = await planArmDeploy(http, { env: ctx.env, component: ctx.component }, input);
471
+ if (now.planDigest !== approved.planDigest) throw new ArmDeployPlanMovedError(target.resourceGroup, approved.planDigest, now.planDigest);
472
+ }
473
+ const result = await azApply(
474
+ {
475
+ templatePath: input.template,
476
+ resourceGroup: target.resourceGroup,
477
+ location: target.location,
478
+ endpoint: target.endpoint,
479
+ subscriptionId: target.subscriptionId,
480
+ prune: input.prune ?? false,
481
+ },
482
+ undefined,
483
+ http,
484
+ );
485
+ return { ...result, outputs: await liveOutputs(target, input, http) };
486
+ },
487
+ };
488
+ }
489
+
490
+ /** The default `arm-deploy` capability, over `fetch`. */
491
+ export const armDeployCapability: Capability<ArmDeployInput, ArmDeployOutput> = createArmDeployCapability();
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `azureCapabilityPlugin`: the azure lexicon's capability plugin (#4273). It
3
+ * contributes `arm-deploy` through core's `CapabilityPlugin` contract, so a
4
+ * project declaring `lexicons: ["azure"]` gets the verb registered when it
5
+ * runs components, the way the aws lexicon contributes `cfn-deploy`.
6
+ */
7
+ import type { Capability } from "@intentius/chant/components/capability";
8
+ import { ownPackageVersion, type CapabilityPlugin } from "@intentius/chant/components/capability-plugin";
9
+ import { armDeployCapability } from "./arm-deploy";
10
+
11
+ export const AZURE_VERB_FAMILIES = {
12
+ apply: ["arm-deploy"],
13
+ } as const;
14
+
15
+ export const azureCapabilityPlugin: CapabilityPlugin = {
16
+ name: "azure",
17
+ get version(): string {
18
+ return ownPackageVersion(import.meta.url);
19
+ },
20
+ capabilities(): Array<Capability<never, unknown>> {
21
+ return [armDeployCapability as Capability<never, unknown>];
22
+ },
23
+ families(): Record<string, readonly string[]> {
24
+ return AZURE_VERB_FAMILIES;
25
+ },
26
+ };
@@ -0,0 +1,9 @@
1
+ export { azureCapabilityPlugin, AZURE_VERB_FAMILIES } from "./capability-plugin";
2
+ export {
3
+ armDeployCapability,
4
+ createArmDeployCapability,
5
+ ArmDeployPlanMovedError,
6
+ type ArmDeployInput,
7
+ type ArmDeployOutput,
8
+ type ArmDeployPlanArtifact,
9
+ } from "./arm-deploy";
@@ -172,6 +172,126 @@ export const compositeCatalog: CompositeEntry[] = [
172
172
  }
173
173
  ]
174
174
  },
175
+ {
176
+ "name": "ContainerAppNetwork",
177
+ "lexicon": "azure",
178
+ "description": "A VNet with a subnet delegated to `Microsoft.App/environments`, for ContainerAppSite environments to sit in.",
179
+ "bundles": [
180
+ "Subnet",
181
+ "VirtualNetwork"
182
+ ],
183
+ "params": [
184
+ {
185
+ "name": "name",
186
+ "type": "string",
187
+ "required": true,
188
+ "description": "Network name prefix: the VNet is `<name>-vnet`, its subnet `apps`."
189
+ },
190
+ {
191
+ "name": "location",
192
+ "type": "string",
193
+ "required": false,
194
+ "description": "Azure region (default: resource group location)."
195
+ },
196
+ {
197
+ "name": "addressSpace",
198
+ "type": "string",
199
+ "required": false,
200
+ "description": "VNet address space (default: \"10.0.0.0/16\")."
201
+ },
202
+ {
203
+ "name": "subnetPrefix",
204
+ "type": "string",
205
+ "required": false,
206
+ "description": "The environment subnet's prefix, a /23 or larger (default: \"10.0.0.0/23\")."
207
+ },
208
+ {
209
+ "name": "tags",
210
+ "type": "Record<string, string>",
211
+ "required": false,
212
+ "description": "Resource tags."
213
+ },
214
+ {
215
+ "name": "defaults",
216
+ "type": "{ virtualNetwork?: Partial<ConstructorParameters<typeof VirtualNetwork>[0]>; subnet?: Partial<ConstructorParameters<t...",
217
+ "required": false,
218
+ "description": "Per-member defaults."
219
+ }
220
+ ]
221
+ },
222
+ {
223
+ "name": "ContainerAppSite",
224
+ "lexicon": "azure",
225
+ "description": "A Container Apps environment in a subnet, shipping logs to its own Log Analytics workspace, with one app running as a user-assigned identity.",
226
+ "bundles": [
227
+ "LogAnalyticsWorkspace",
228
+ "ManagedIdentity",
229
+ "containerApps",
230
+ "managedEnvironments"
231
+ ],
232
+ "params": [
233
+ {
234
+ "name": "name",
235
+ "type": "string",
236
+ "required": true,
237
+ "description": "Environment name; the workspace is `<name>-logs` and the identity `<name>-<app>`."
238
+ },
239
+ {
240
+ "name": "app",
241
+ "type": "string",
242
+ "required": true,
243
+ "description": "Container app name."
244
+ },
245
+ {
246
+ "name": "subnetId",
247
+ "type": "string",
248
+ "required": true,
249
+ "description": "Subnet resource ID for the environment, such as a ContainerAppNetwork's `subnet.id`."
250
+ },
251
+ {
252
+ "name": "location",
253
+ "type": "string",
254
+ "required": false,
255
+ "description": "Azure region (default: resource group location)."
256
+ },
257
+ {
258
+ "name": "image",
259
+ "type": "string",
260
+ "required": false,
261
+ "description": "Container image (default: \"mcr.microsoft.com/k8se/quickstart:latest\")."
262
+ },
263
+ {
264
+ "name": "port",
265
+ "type": "number",
266
+ "required": false,
267
+ "description": "Port the container listens on; ingress forwards to it (default: 80)."
268
+ },
269
+ {
270
+ "name": "replicas",
271
+ "type": "number",
272
+ "required": false,
273
+ "description": "Fixed replica count (default: 1)."
274
+ },
275
+ {
276
+ "name": "internal",
277
+ "type": "boolean",
278
+ "required": false,
279
+ "description": "Make the environment reachable only from its VNet (default: false)."
280
+ },
281
+ {
282
+ "name": "tags",
283
+ "type": "Record<string, string>",
284
+ "required": false,
285
+ "description": "Resource tags."
286
+ },
287
+ {
288
+ "name": "defaults",
289
+ "type": "{ workspace?: Partial<ConstructorParameters<typeof LogAnalyticsWorkspace>[0]>; identity?: Partial<ConstructorParamete...",
290
+ "required": false,
291
+ "description": "Per-member defaults."
292
+ }
293
+ ]
294
+ },
175
295
  {
176
296
  "name": "ContainerInstance",
177
297
  "lexicon": "azure",