@intentius/chant-lexicon-azure 0.124.35 → 0.124.37
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/integrity.json +2 -2
- package/dist/manifest.json +1 -1
- package/dist/op/activities/az-apply.d.ts +11 -0
- package/dist/op/activities/az-apply.d.ts.map +1 -1
- package/dist/op/activities/az-apply.js +29 -4
- package/package.json +2 -2
- package/src/op/activities/az-apply.test.ts +49 -0
- package/src/op/activities/az-apply.ts +30 -4
package/dist/integrity.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"algorithm": "sha256",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"manifest.json": "
|
|
4
|
+
"manifest.json": "1748745d35ce09ef6c031c21c8e741e84d5c9427bccea1cc1a82688809543312",
|
|
5
5
|
"meta.json": "d2521221ed616d882ded4296f0071685bd74e4b645d55dabc9685733c37dc419",
|
|
6
6
|
"types/index.d.ts": "29631032bda9533849178968290e65d72250eab0b8bab424f2d9ef9b4e8546a4",
|
|
7
7
|
"rules/hardcoded-location.ts": "0b895449c8c94066e81721c46be24249231029fe13b471477456df5c4e45b8bf",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"skills/chant-azure-patterns.md": "1a3bacfac612826b77332d2692a59195638db9f1b5e8ea2eda7579621d25f603",
|
|
38
38
|
"skills/chant-azure-aks.md": "2d4e0098c1a22b54ffadd410564d9df0f3a04cb4eb7c6261f20ae33106e7aca8"
|
|
39
39
|
},
|
|
40
|
-
"composite": "
|
|
40
|
+
"composite": "21124e363076a858ce5df478a217057d05caa6e7fd6fd6517531eadd59932249"
|
|
41
41
|
}
|
package/dist/manifest.json
CHANGED
|
@@ -36,6 +36,17 @@ export interface ArmEvalCtx {
|
|
|
36
36
|
base: string;
|
|
37
37
|
signal?: AbortSignal;
|
|
38
38
|
}
|
|
39
|
+
/** The ARM resource id of a resource in the context's group. */
|
|
40
|
+
export declare function armResourceIdOf(ctx: Pick<ArmEvalCtx, "subscriptionId" | "resourceGroup">, type: string, name: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Record an applied resource's response so `reference()` resolves it by name
|
|
43
|
+
* and by resource id (#4243). Ids are case-insensitive in ARM, so they are
|
|
44
|
+
* stored lowercased, under both the id chant derives and the one the
|
|
45
|
+
* response reports.
|
|
46
|
+
*/
|
|
47
|
+
export declare function rememberDeployed(ctx: ArmEvalCtx, type: string, name: string, body: unknown): void;
|
|
48
|
+
/** An applied resource by the name or the resource id a `reference()` names. */
|
|
49
|
+
export declare function lookupDeployed(ctx: ArmEvalCtx, ref: string): unknown;
|
|
39
50
|
/** Evaluate an ARM expression string (`"[...]"`); a plain string is returned as-is. */
|
|
40
51
|
export declare function evalArmString(s: string, ctx: ArmEvalCtx): Promise<unknown>;
|
|
41
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"az-apply.d.ts","sourceRoot":"","sources":["../../../src/op/activities/az-apply.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,WAAW,EAGjB,MAAM,wBAAwB,CAAC;AAMhC,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS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AI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAChE,WAAW,EAAE,aAAa,EAAE,CAAC;CAC9B,CAAC,CA6CD;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,WAAW,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,IAAI,GAAE,MAAoB,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAqB/E"}
|
|
@@ -18,6 +18,27 @@ const defaultHttp = async (method, url, body, signal) => {
|
|
|
18
18
|
});
|
|
19
19
|
return { status: res.status, text: await res.text() };
|
|
20
20
|
};
|
|
21
|
+
/** The ARM resource id of a resource in the context's group. */
|
|
22
|
+
export function armResourceIdOf(ctx, type, name) {
|
|
23
|
+
return `/subscriptions/${ctx.subscriptionId}/resourceGroups/${ctx.resourceGroup}/providers/${armResourcePath(type, name)}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Record an applied resource's response so `reference()` resolves it by name
|
|
27
|
+
* and by resource id (#4243). Ids are case-insensitive in ARM, so they are
|
|
28
|
+
* stored lowercased, under both the id chant derives and the one the
|
|
29
|
+
* response reports.
|
|
30
|
+
*/
|
|
31
|
+
export function rememberDeployed(ctx, type, name, body) {
|
|
32
|
+
ctx.deployed.set(name, body);
|
|
33
|
+
ctx.deployed.set(armResourceIdOf(ctx, type, name).toLowerCase(), body);
|
|
34
|
+
const id = body?.id;
|
|
35
|
+
if (typeof id === "string")
|
|
36
|
+
ctx.deployed.set(id.toLowerCase(), body);
|
|
37
|
+
}
|
|
38
|
+
/** An applied resource by the name or the resource id a `reference()` names. */
|
|
39
|
+
export function lookupDeployed(ctx, ref) {
|
|
40
|
+
return ctx.deployed.get(ref) ?? (ref.startsWith("/") ? ctx.deployed.get(ref.toLowerCase()) : undefined);
|
|
41
|
+
}
|
|
21
42
|
/** Evaluate an ARM expression string (`"[...]"`); a plain string is returned as-is. */
|
|
22
43
|
export async function evalArmString(s, ctx) {
|
|
23
44
|
if (!(s.startsWith("[") && s.endsWith("]")))
|
|
@@ -113,10 +134,14 @@ class ArmExpr {
|
|
|
113
134
|
return { subscriptionId: this.ctx.subscriptionId, id: `/subscriptions/${this.ctx.subscriptionId}` };
|
|
114
135
|
case "resourceId":
|
|
115
136
|
// resourceId('Microsoft.X/y', 'name'[, 'child']) → the resource-id path.
|
|
116
|
-
return
|
|
137
|
+
return armResourceIdOf(this.ctx, String(args[0]), args.slice(1).map(String).join("/"));
|
|
117
138
|
case "reference": {
|
|
118
|
-
// reference('name'
|
|
119
|
-
|
|
139
|
+
// reference('name' | resourceId(...)[, apiVersion[, 'Full']]) → the
|
|
140
|
+
// runtime `properties` of an already-applied resource, or its whole
|
|
141
|
+
// body with 'Full' (#4243).
|
|
142
|
+
const dep = lookupDeployed(this.ctx, String(args[0]));
|
|
143
|
+
if (String(args[2] ?? "").toLowerCase() === "full")
|
|
144
|
+
return dep;
|
|
120
145
|
return dep?.properties ?? dep;
|
|
121
146
|
}
|
|
122
147
|
case "listKeys": {
|
|
@@ -284,7 +309,7 @@ export async function azApply(args, signal, http = defaultHttp) {
|
|
|
284
309
|
}
|
|
285
310
|
// Capture the applied resource so later reference()/dependents resolve.
|
|
286
311
|
try {
|
|
287
|
-
ctx.
|
|
312
|
+
rememberDeployed(ctx, resource.type, name, JSON.parse(res.text));
|
|
288
313
|
}
|
|
289
314
|
catch {
|
|
290
315
|
// non-JSON response — reference() to this resource resolves to undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/chant-lexicon-azure",
|
|
3
|
-
"version": "0.124.
|
|
3
|
+
"version": "0.124.37",
|
|
4
4
|
"description": "Azure lexicon for chant — declarative IaC in TypeScript",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://intentius.io/chant",
|
|
@@ -74,6 +74,6 @@
|
|
|
74
74
|
"typescript": "^5.9.3"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@intentius/chant": "^0.124.
|
|
77
|
+
"@intentius/chant": "^0.124.37"
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type ArmResource,
|
|
21
21
|
type AzHttp,
|
|
22
22
|
providerApiVersion,
|
|
23
|
+
rememberDeployed,
|
|
23
24
|
} from "./az-apply";
|
|
24
25
|
import { lookupApiVersion } from "../../serializer";
|
|
25
26
|
|
|
@@ -69,6 +70,54 @@ describe("evalArmString — reference() (#707)", () => {
|
|
|
69
70
|
});
|
|
70
71
|
});
|
|
71
72
|
|
|
73
|
+
describe("evalArmString — reference() by resource id (#4243)", () => {
|
|
74
|
+
test("reference(resourceId(...)).customerId resolves the resource applied by name", async () => {
|
|
75
|
+
const c = ctx();
|
|
76
|
+
rememberDeployed(c, "Microsoft.OperationalInsights/workspaces", "logs", { properties: { customerId: "cust-1" } });
|
|
77
|
+
expect(await evalArmString("[reference(resourceId('Microsoft.OperationalInsights/workspaces', 'logs')).customerId]", c)).toBe("cust-1");
|
|
78
|
+
expect(await evalArmString("[reference('logs').customerId]", c)).toBe("cust-1");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("a child type, a full id in another case, and 'Full'", async () => {
|
|
82
|
+
const c = ctx();
|
|
83
|
+
rememberDeployed(c, "Microsoft.Network/virtualNetworks/subnets", "vnet/apps", {
|
|
84
|
+
id: "/subscriptions/sub-1/resourceGroups/chant-rg/providers/Microsoft.Network/virtualNetworks/vnet/subnets/apps",
|
|
85
|
+
properties: { addressPrefix: "10.0.1.0/24" },
|
|
86
|
+
});
|
|
87
|
+
expect(await evalArmString("[reference(resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet', 'apps')).addressPrefix]", c)).toBe("10.0.1.0/24");
|
|
88
|
+
expect(
|
|
89
|
+
await evalArmString("[reference('/SUBSCRIPTIONS/sub-1/resourceGroups/chant-rg/providers/Microsoft.Network/virtualNetworks/vnet/subnets/apps').addressPrefix]", c),
|
|
90
|
+
).toBe("10.0.1.0/24");
|
|
91
|
+
expect(await evalArmString("[reference(resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet', 'apps'), '2023-04-01', 'Full').properties.addressPrefix]", c)).toBe("10.0.1.0/24");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("azApply: a later resource reads an earlier one through reference(resourceId(...))", async () => {
|
|
95
|
+
const path = `/tmp/chant-4243-${process.pid}.json`;
|
|
96
|
+
writeFileSync(path, JSON.stringify({
|
|
97
|
+
resources: [
|
|
98
|
+
{ type: "Microsoft.OperationalInsights/workspaces", apiVersion: "2022-10-01", name: "logs", location: "eastus", properties: {} },
|
|
99
|
+
{
|
|
100
|
+
type: "Microsoft.App/managedEnvironments", apiVersion: "2024-03-01", name: "env", location: "eastus",
|
|
101
|
+
dependsOn: ["[resourceId('Microsoft.OperationalInsights/workspaces', 'logs')]"],
|
|
102
|
+
properties: { appLogsConfiguration: { logAnalyticsConfiguration: { customerId: "[reference(resourceId('Microsoft.OperationalInsights/workspaces', 'logs')).customerId]" } } },
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
}));
|
|
106
|
+
const bodies: Record<string, unknown> = {};
|
|
107
|
+
const http: AzHttp = async (method, url, body) => {
|
|
108
|
+
if (method === "PUT" && url.includes("/workspaces/logs")) return { status: 200, text: JSON.stringify({ properties: { customerId: "cust-1" } }) };
|
|
109
|
+
if (method === "PUT" && url.includes("/managedEnvironments/env")) bodies.env = body;
|
|
110
|
+
return { status: 200, text: "{}" };
|
|
111
|
+
};
|
|
112
|
+
try {
|
|
113
|
+
await azApply({ templatePath: path, resourceGroup: "chant-rg", subscriptionId: "sub-1", endpoint: "http://x" }, undefined, http);
|
|
114
|
+
} finally {
|
|
115
|
+
unlinkSync(path);
|
|
116
|
+
}
|
|
117
|
+
expect((bodies.env as { properties: { appLogsConfiguration: { logAnalyticsConfiguration: { customerId: string } } } }).properties.appLogsConfiguration.logAnalyticsConfiguration.customerId).toBe("cust-1");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
72
121
|
describe("evalArmString — listKeys() (#707)", () => {
|
|
73
122
|
test("listKeys(resourceId(...), v).keys[0].value → POSTs the key action and indexes", async () => {
|
|
74
123
|
const calls: string[] = [];
|
|
@@ -70,6 +70,29 @@ export interface ArmEvalCtx {
|
|
|
70
70
|
signal?: AbortSignal;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/** The ARM resource id of a resource in the context's group. */
|
|
74
|
+
export function armResourceIdOf(ctx: Pick<ArmEvalCtx, "subscriptionId" | "resourceGroup">, type: string, name: string): string {
|
|
75
|
+
return `/subscriptions/${ctx.subscriptionId}/resourceGroups/${ctx.resourceGroup}/providers/${armResourcePath(type, name)}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Record an applied resource's response so `reference()` resolves it by name
|
|
80
|
+
* and by resource id (#4243). Ids are case-insensitive in ARM, so they are
|
|
81
|
+
* stored lowercased, under both the id chant derives and the one the
|
|
82
|
+
* response reports.
|
|
83
|
+
*/
|
|
84
|
+
export function rememberDeployed(ctx: ArmEvalCtx, type: string, name: string, body: unknown): void {
|
|
85
|
+
ctx.deployed.set(name, body);
|
|
86
|
+
ctx.deployed.set(armResourceIdOf(ctx, type, name).toLowerCase(), body);
|
|
87
|
+
const id = (body as { id?: unknown } | null)?.id;
|
|
88
|
+
if (typeof id === "string") ctx.deployed.set(id.toLowerCase(), body);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** An applied resource by the name or the resource id a `reference()` names. */
|
|
92
|
+
export function lookupDeployed(ctx: ArmEvalCtx, ref: string): unknown {
|
|
93
|
+
return ctx.deployed.get(ref) ?? (ref.startsWith("/") ? ctx.deployed.get(ref.toLowerCase()) : undefined);
|
|
94
|
+
}
|
|
95
|
+
|
|
73
96
|
/** Evaluate an ARM expression string (`"[...]"`); a plain string is returned as-is. */
|
|
74
97
|
export async function evalArmString(s: string, ctx: ArmEvalCtx): Promise<unknown> {
|
|
75
98
|
if (!(s.startsWith("[") && s.endsWith("]"))) return s;
|
|
@@ -161,10 +184,13 @@ class ArmExpr {
|
|
|
161
184
|
return { subscriptionId: this.ctx.subscriptionId, id: `/subscriptions/${this.ctx.subscriptionId}` };
|
|
162
185
|
case "resourceId":
|
|
163
186
|
// resourceId('Microsoft.X/y', 'name'[, 'child']) → the resource-id path.
|
|
164
|
-
return
|
|
187
|
+
return armResourceIdOf(this.ctx, String(args[0]), args.slice(1).map(String).join("/"));
|
|
165
188
|
case "reference": {
|
|
166
|
-
// reference('name'
|
|
167
|
-
|
|
189
|
+
// reference('name' | resourceId(...)[, apiVersion[, 'Full']]) → the
|
|
190
|
+
// runtime `properties` of an already-applied resource, or its whole
|
|
191
|
+
// body with 'Full' (#4243).
|
|
192
|
+
const dep = lookupDeployed(this.ctx, String(args[0]));
|
|
193
|
+
if (String(args[2] ?? "").toLowerCase() === "full") return dep;
|
|
168
194
|
return (dep as { properties?: unknown } | undefined)?.properties ?? dep;
|
|
169
195
|
}
|
|
170
196
|
case "listKeys": {
|
|
@@ -362,7 +388,7 @@ export async function azApply(
|
|
|
362
388
|
}
|
|
363
389
|
// Capture the applied resource so later reference()/dependents resolve.
|
|
364
390
|
try {
|
|
365
|
-
ctx.
|
|
391
|
+
rememberDeployed(ctx, resource.type, name, JSON.parse(res.text));
|
|
366
392
|
} catch {
|
|
367
393
|
// non-JSON response — reference() to this resource resolves to undefined
|
|
368
394
|
}
|