@mark1russell7/stack-tofu 0.1.4 → 0.2.1
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/README.md +72 -5
- package/build/add-on.d.ts +2 -2
- package/build/add-on.js +2 -2
- package/build/{check-COlnfceW.d.ts → check-B-gwXACy.d.ts} +9 -3
- package/build/{check-COlnfceW.d.ts.map → check-B-gwXACy.d.ts.map} +1 -1
- package/build/index.d.ts +49 -13
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -3
- package/build/{join-C_LP43nN.js → join-Bzyt9lhB.js} +256 -20
- package/build/join-Bzyt9lhB.js.map +1 -0
- package/build/{layer-C9IpaDIx.js → layer-CS1ZZFFP.js} +11 -4
- package/build/layer-CS1ZZFFP.js.map +1 -0
- package/build/{layer-MFHgwWfO.d.ts → layer-Cz0jBEel.d.ts} +60 -2
- package/build/layer-Cz0jBEel.d.ts.map +1 -0
- package/build/{plan-B4mHDZjK.d.ts → plan-D04Q_k6n.d.ts} +2 -2
- package/build/{plan-B4mHDZjK.d.ts.map → plan-D04Q_k6n.d.ts.map} +1 -1
- package/build/schema.d.ts +2 -2
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +37 -2
- package/build/schema.js.map +1 -1
- package/package.json +2 -2
- package/build/join-C_LP43nN.js.map +0 -1
- package/build/layer-C9IpaDIx.js.map +0 -1
- package/build/layer-MFHgwWfO.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as isBuiltin, c as resourceAddress, d as typeProvider, i as copyName, l as resourceName, n as TOFU_SCHEMA, s as providerAddress, t as BUILTIN_PROVIDER, u as resourceProvider } from "./layer-CS1ZZFFP.js";
|
|
2
2
|
import { stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
3
|
-
import { joinRecords, joinSetting, partNeeds, partsById } from "@mark1russell7/system-stack";
|
|
3
|
+
import { joinRecords, joinSetting, neededParts, neededParts as neededParts$1, partNeeds, partsById } from "@mark1russell7/system-stack";
|
|
4
4
|
import { app, axes, each, evaluate, lit, ref, space } from "@mark1russell7/vex";
|
|
5
5
|
import { BoolDomain, NumDomain, TextDomain } from "@mark1russell7/vex-domains";
|
|
6
6
|
// src/values.ts
|
|
@@ -61,6 +61,11 @@ function varOf(value) {
|
|
|
61
61
|
const text = formText(value, "$var");
|
|
62
62
|
return text !== void 0 && NAME_FORM.test(text) ? text : void 0;
|
|
63
63
|
}
|
|
64
|
+
/** This function gives the name of a correct parameter form, `{ "$param": "name" }`. Only a resource of a group can have one. */
|
|
65
|
+
function paramOf(value) {
|
|
66
|
+
const text = formText(value, "$param");
|
|
67
|
+
return text !== void 0 && NAME_FORM.test(text) ? text : void 0;
|
|
68
|
+
}
|
|
64
69
|
/**
|
|
65
70
|
* This function escapes the template sequences of a text. OpenTofu then reads the text as it is in the record.
|
|
66
71
|
* `$${` is the escape of `${`, and `%%{` is the escape of `%{`.
|
|
@@ -136,11 +141,227 @@ function valueUses(value) {
|
|
|
136
141
|
function pathText(path) {
|
|
137
142
|
return path.length === 0 ? "(the value)" : path.join(".");
|
|
138
143
|
}
|
|
144
|
+
// src/groups.ts
|
|
145
|
+
/** This function gives the local address of a resource of a group: its type, a point and its local name. */
|
|
146
|
+
function localAddress(resource) {
|
|
147
|
+
return `${resource.type}.${resource.name}`;
|
|
148
|
+
}
|
|
149
|
+
/** This function gives the name in the files of a resource of a copy: the name of the copy, `_` and the local name. */
|
|
150
|
+
function copyResourceName(copy, resource) {
|
|
151
|
+
return `${copyName(copy)}_${resource.name}`;
|
|
152
|
+
}
|
|
153
|
+
/** This function gives the provider name of the address of a provider configuration: the word before the point. */
|
|
154
|
+
function providerName(address) {
|
|
155
|
+
const end = address.indexOf(".");
|
|
156
|
+
return end === -1 ? address : address.slice(0, end);
|
|
157
|
+
}
|
|
158
|
+
/** This function tells if a resource of a group is a part of OpenTofu, with no provider configuration. */
|
|
159
|
+
function isBuiltinMember(resource) {
|
|
160
|
+
return resource.provider === void 0 && typeProvider(resource.type) === "terraform";
|
|
161
|
+
}
|
|
162
|
+
/** This function gives the value of each parameter of a group for a copy. It gives `undefined` when a parameter has no value. */
|
|
163
|
+
function paramValues(group, copy) {
|
|
164
|
+
const values = /* @__PURE__ */ new Map();
|
|
165
|
+
for (const param of group.params ?? []) {
|
|
166
|
+
const value = copy.values !== void 0 && Object.hasOwn(copy.values, param.name) ? copy.values[param.name] : param.default;
|
|
167
|
+
if (value === void 0) return void 0;
|
|
168
|
+
values.set(param.name, value);
|
|
169
|
+
}
|
|
170
|
+
return values;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* This function fills a value of a resource of a group for one copy. A parameter form becomes the value of the parameter.
|
|
174
|
+
* A reference to a local address of the group becomes a reference to the resource of the copy. The value of a parameter does not change.
|
|
175
|
+
*/
|
|
176
|
+
function fill(value, params, addresses) {
|
|
177
|
+
if (isList(value)) return value.map((item) => fill(item, params, addresses));
|
|
178
|
+
if (!isObject(value)) return value;
|
|
179
|
+
if (isForm(value)) {
|
|
180
|
+
const param = paramOf(value);
|
|
181
|
+
const given = param === void 0 ? void 0 : params.get(param);
|
|
182
|
+
if (given !== void 0) return given;
|
|
183
|
+
const ref = refOf(value);
|
|
184
|
+
const parts = ref === void 0 ? void 0 : refParts(ref);
|
|
185
|
+
const address = parts === void 0 ? void 0 : addresses.get(parts.address);
|
|
186
|
+
return parts !== void 0 && address !== void 0 ? { $ref: `${address}.${parts.attribute}` } : value;
|
|
187
|
+
}
|
|
188
|
+
return fillObject(value, params, addresses);
|
|
189
|
+
}
|
|
190
|
+
/** This function fills each argument of an object. The object itself is not a form, also when it has a key that starts with `$`. */
|
|
191
|
+
function fillObject(values, params, addresses) {
|
|
192
|
+
return Object.fromEntries(Object.entries(values).map(([key, item]) => [key, fill(item, params, addresses)]));
|
|
193
|
+
}
|
|
194
|
+
/** This function gives the provider configuration of a resource of a copy. A configuration of the copy with the same provider name replaces that of the group. */
|
|
195
|
+
function copyProvider(copy, resource) {
|
|
196
|
+
if (isBuiltinMember(resource)) return void 0;
|
|
197
|
+
const name = providerName(resource.provider ?? typeProvider(resource.type));
|
|
198
|
+
return copy.providers?.find((address) => providerName(address) === name) ?? resource.provider;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* This function gives the resources of the copies of a layer, in the sequence of the copies and of the resources of each group.
|
|
202
|
+
*
|
|
203
|
+
* - A resource of a copy makes the part of the copy. Its name is the name of the copy, `_` and its local name.
|
|
204
|
+
* - A parameter form becomes the value of the copy, or the default of the parameter.
|
|
205
|
+
* - A reference to a local address of the group reads the resource of the same copy.
|
|
206
|
+
* - A configuration of the copy replaces the configuration of the same provider name.
|
|
207
|
+
*
|
|
208
|
+
* A copy whose group the layer does not have, or that gives no value for a parameter with no default, makes no resource.
|
|
209
|
+
* For two groups with one name, the copies use the first one. The gate `checkTofu` gives a fault for each such record.
|
|
210
|
+
*/
|
|
211
|
+
function copyResources(layer) {
|
|
212
|
+
const groups = /* @__PURE__ */ new Map();
|
|
213
|
+
for (const group of layer.groups ?? []) if (!groups.has(group.name)) groups.set(group.name, group);
|
|
214
|
+
return (layer.copies ?? []).flatMap((copy) => {
|
|
215
|
+
const group = groups.get(copy.group);
|
|
216
|
+
const params = group === void 0 ? void 0 : paramValues(group, copy);
|
|
217
|
+
if (group === void 0 || params === void 0) return [];
|
|
218
|
+
const addresses = new Map(group.resources.map((resource) => [localAddress(resource), `${resource.type}.${copyResourceName(copy, resource)}`]));
|
|
219
|
+
return group.resources.map((resource) => {
|
|
220
|
+
const provider = copyProvider(copy, resource);
|
|
221
|
+
return {
|
|
222
|
+
part: copy.part,
|
|
223
|
+
type: resource.type,
|
|
224
|
+
name: copyResourceName(copy, resource),
|
|
225
|
+
...provider === void 0 ? {} : { provider },
|
|
226
|
+
...resource.values === void 0 ? {} : { values: fillObject(resource.values, params, addresses) },
|
|
227
|
+
...resource.cost === void 0 ? {} : { cost: resource.cost },
|
|
228
|
+
...resource.keep === void 0 ? {} : { keep: resource.keep },
|
|
229
|
+
...resource.ignore === void 0 ? {} : { ignore: resource.ignore }
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/** This function gives each resource of a layer: the resources of the field `resources`, and then the resources of the copies. */
|
|
235
|
+
function layerResources(layer) {
|
|
236
|
+
return (layer.copies ?? []).length === 0 ? layer.resources : [...layer.resources, ...copyResources(layer)];
|
|
237
|
+
}
|
|
238
|
+
/** This function gives each correct parameter form of the arguments of a record, in the sequence of the arguments. */
|
|
239
|
+
function paramUses(values) {
|
|
240
|
+
const uses = [];
|
|
241
|
+
const walk = (item, path) => {
|
|
242
|
+
if (isList(item)) {
|
|
243
|
+
item.forEach((child, index) => {
|
|
244
|
+
walk(child, [...path, index]);
|
|
245
|
+
});
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (!isObject(item)) return;
|
|
249
|
+
const name = isForm(item) ? paramOf(item) : void 0;
|
|
250
|
+
if (name !== void 0) uses.push({
|
|
251
|
+
name,
|
|
252
|
+
path
|
|
253
|
+
});
|
|
254
|
+
else if (!isForm(item)) for (const [key, child] of Object.entries(item)) walk(child, [...path, key]);
|
|
255
|
+
};
|
|
256
|
+
for (const [key, child] of Object.entries(values)) walk(child, [key]);
|
|
257
|
+
return uses;
|
|
258
|
+
}
|
|
259
|
+
/** This function gives a list of names for a message, for example `"a", "b"`. */
|
|
260
|
+
function quoted(items) {
|
|
261
|
+
return items.map((item) => `"${item}"`).join(", ");
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* This function gives the faults of the groups and of the copies of a layer. `checkTofu` gives them with its other faults.
|
|
265
|
+
* The resources of the copies get the faults of each resource there: the gate examines them as resources.
|
|
266
|
+
*
|
|
267
|
+
* The errors:
|
|
268
|
+
* - `group-form`: the name of a group, of a parameter or of a copy does not have the form of a name. Or a group has no resource.
|
|
269
|
+
* - `group-duplicate`: two groups, two parameters of a group, two resources of a group with one local address, or two copies have one name.
|
|
270
|
+
* - `group-shadow`: a local address of a group is the address of a resource of the layer. A reference in the group then reads the copy.
|
|
271
|
+
* - `group-none`: a copy names a group that the layer does not have.
|
|
272
|
+
* - `param-none`: a parameter form of a group names a parameter that the group does not have.
|
|
273
|
+
* - `param-missing`: a copy gives no value for a parameter with no default.
|
|
274
|
+
* - `param-unknown`: a copy gives a value for a parameter that the group does not have.
|
|
275
|
+
* - `copy-provider`: a configuration of a copy replaces no configuration of the group, or two of them have one provider name.
|
|
276
|
+
* A configuration that the layer does not have gives `provider-none` at each resource of the copy.
|
|
277
|
+
*
|
|
278
|
+
* The warnings:
|
|
279
|
+
* - `group-unused`: no copy names a group.
|
|
280
|
+
* - `param-unused`: no resource of a group reads a parameter.
|
|
281
|
+
*/
|
|
282
|
+
function groupFaults(layer) {
|
|
283
|
+
const faults = [];
|
|
284
|
+
const add = (level, code, at, message, more = {}) => {
|
|
285
|
+
faults.push({
|
|
286
|
+
level,
|
|
287
|
+
code,
|
|
288
|
+
at,
|
|
289
|
+
message,
|
|
290
|
+
...more
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
const top = new Set(layer.resources.map(resourceAddress));
|
|
294
|
+
const groups = /* @__PURE__ */ new Map();
|
|
295
|
+
for (const group of layer.groups ?? []) {
|
|
296
|
+
const at = `group.${group.name}`;
|
|
297
|
+
if (groups.has(group.name)) {
|
|
298
|
+
add("error", "group-duplicate", at, `Two groups have the name "${group.name}".`);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
groups.set(group.name, group);
|
|
302
|
+
if (!NAME_FORM.test(group.name)) add("error", "group-form", at, `The name "${group.name}" of a group does not have the form of a name.`);
|
|
303
|
+
if (group.resources.length === 0) add("error", "group-form", at, `The group "${group.name}" has no resource.`);
|
|
304
|
+
const params = /* @__PURE__ */ new Set();
|
|
305
|
+
for (const param of group.params ?? []) {
|
|
306
|
+
if (params.has(param.name)) add("error", "group-duplicate", at, `Two parameters of the group "${group.name}" have the name "${param.name}".`);
|
|
307
|
+
else if (!NAME_FORM.test(param.name)) add("error", "group-form", at, `The name "${param.name}" of a parameter of the group "${group.name}" does not have the form of a name.`);
|
|
308
|
+
params.add(param.name);
|
|
309
|
+
}
|
|
310
|
+
const locals = /* @__PURE__ */ new Set();
|
|
311
|
+
const read = /* @__PURE__ */ new Set();
|
|
312
|
+
for (const resource of group.resources) {
|
|
313
|
+
const local = localAddress(resource);
|
|
314
|
+
if (locals.has(local)) add("error", "group-duplicate", at, `Two resources of the group "${group.name}" have the local address "${local}".`);
|
|
315
|
+
locals.add(local);
|
|
316
|
+
if (top.has(local)) add("error", "group-shadow", at, `The group "${group.name}" has the local address "${local}", and the layer has a resource with that address. A reference in the group reads the resource of the copy.`, { other: local });
|
|
317
|
+
for (const use of paramUses(resource.values ?? {})) if (params.has(use.name)) read.add(use.name);
|
|
318
|
+
else add("error", "param-none", at, `The value at "${pathText(use.path)}" of the resource "${local}" of the group "${group.name}" names the parameter "${use.name}", which the group does not have.`);
|
|
319
|
+
}
|
|
320
|
+
for (const name of params) if (!read.has(name)) add("warning", "param-unused", at, `No resource of the group "${group.name}" reads the parameter "${name}".`);
|
|
321
|
+
}
|
|
322
|
+
const copies = /* @__PURE__ */ new Set();
|
|
323
|
+
const copied = /* @__PURE__ */ new Set();
|
|
324
|
+
for (const copy of layer.copies ?? []) {
|
|
325
|
+
const name = copyName(copy);
|
|
326
|
+
const at = `copy.${name}`;
|
|
327
|
+
const more = { part: copy.part };
|
|
328
|
+
if (copies.has(name)) {
|
|
329
|
+
add("error", "group-duplicate", at, `Two copies have the name "${name}".`, more);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
copies.add(name);
|
|
333
|
+
if (!NAME_FORM.test(name)) add("error", "group-form", at, `The name "${name}" of a copy does not have the form of a name.`, more);
|
|
334
|
+
const group = groups.get(copy.group);
|
|
335
|
+
if (group === void 0) {
|
|
336
|
+
add("error", "group-none", at, `The copy "${name}" names the group "${copy.group}", which the layer does not have. It makes no resource.`, {
|
|
337
|
+
...more,
|
|
338
|
+
other: `group.${copy.group}`
|
|
339
|
+
});
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
copied.add(group.name);
|
|
343
|
+
const params = group.params ?? [];
|
|
344
|
+
const given = Object.keys(copy.values ?? {});
|
|
345
|
+
for (const key of given) if (!params.some((param) => param.name === key)) add("error", "param-unknown", at, `The copy "${name}" gives the parameter "${key}", which the group "${group.name}" does not have.`, more);
|
|
346
|
+
const missing = params.filter((param) => param.default === void 0 && !given.includes(param.name)).map((param) => param.name);
|
|
347
|
+
if (missing.length > 0) add("error", "param-missing", at, `The copy "${name}" gives no value for the parameters ${quoted(missing)} of the group "${group.name}". It makes no resource.`, more);
|
|
348
|
+
const used = new Set(group.resources.filter((resource) => !isBuiltinMember(resource)).map((resource) => providerName(resource.provider ?? typeProvider(resource.type))));
|
|
349
|
+
const replaced = /* @__PURE__ */ new Set();
|
|
350
|
+
for (const address of copy.providers ?? []) {
|
|
351
|
+
const provider = providerName(address);
|
|
352
|
+
if (replaced.has(provider)) add("error", "copy-provider", at, `The copy "${name}" has two configurations of the provider "${provider}". Each one replaces the configuration of its provider name.`, more);
|
|
353
|
+
else if (!used.has(provider)) add("error", "copy-provider", at, `The configuration "${address}" of the copy "${name}" replaces no configuration: no resource of the group "${group.name}" uses the provider "${provider}".`, more);
|
|
354
|
+
replaced.add(provider);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
for (const group of groups.values()) if (!copied.has(group.name)) add("warning", "group-unused", `group.${group.name}`, `No copy names the group "${group.name}". It makes no resource.`);
|
|
358
|
+
return faults;
|
|
359
|
+
}
|
|
139
360
|
// src/queries.ts
|
|
140
|
-
/** This function gives the first resource of each address of a layer, in the sequence of the records. */
|
|
361
|
+
/** This function gives the first resource of each address of a layer, in the sequence of the records. The resources of the copies come last. */
|
|
141
362
|
function firstResources(layer) {
|
|
142
363
|
const seen = /* @__PURE__ */ new Set();
|
|
143
|
-
return layer.
|
|
364
|
+
return layerResources(layer).filter((resource) => {
|
|
144
365
|
const address = resourceAddress(resource);
|
|
145
366
|
if (seen.has(address)) return false;
|
|
146
367
|
seen.add(address);
|
|
@@ -198,13 +419,6 @@ function walkNeeds(parts, from, stop) {
|
|
|
198
419
|
return found;
|
|
199
420
|
}
|
|
200
421
|
/**
|
|
201
|
-
* This function gives the `id` of each part that a part needs, directly or through other parts.
|
|
202
|
-
* The part itself is not in the result. A need that names no part of the stack is in the result.
|
|
203
|
-
*/
|
|
204
|
-
function neededParts(stack, part) {
|
|
205
|
-
return new Set(walkNeeds(partsById(stack), part, () => false));
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
422
|
* This function gives the dependencies of each resource that come from the needs of the stack, by the address of the resource.
|
|
209
423
|
*
|
|
210
424
|
* - A resource depends on the resources of each part that its part needs.
|
|
@@ -396,7 +610,17 @@ const TOFU_CODES = [
|
|
|
396
610
|
"limit-none",
|
|
397
611
|
"cost-over",
|
|
398
612
|
"provider-need",
|
|
399
|
-
"variable-unused"
|
|
613
|
+
"variable-unused",
|
|
614
|
+
"group-form",
|
|
615
|
+
"group-duplicate",
|
|
616
|
+
"group-shadow",
|
|
617
|
+
"group-none",
|
|
618
|
+
"param-none",
|
|
619
|
+
"param-missing",
|
|
620
|
+
"param-unknown",
|
|
621
|
+
"copy-provider",
|
|
622
|
+
"group-unused",
|
|
623
|
+
"param-unused"
|
|
400
624
|
];
|
|
401
625
|
/** These arguments of a resource are meta-arguments. The generator writes them from the records, so the arguments of a record cannot have them. */
|
|
402
626
|
const RESOURCE_META = [
|
|
@@ -461,9 +685,15 @@ function names(items) {
|
|
|
461
685
|
* - `limit-none`: the resources of an account have a planned cost above 0, and the account has no hard limit.
|
|
462
686
|
* - `cost-over`: the planned cost of an account is more than its hard limit.
|
|
463
687
|
*
|
|
688
|
+
* The groups and the copies, as errors: `group-form`, `group-duplicate`, `group-shadow`, `group-none`, `param-none`,
|
|
689
|
+
* `param-missing`, `param-unknown` and `copy-provider`. `groupFaults` tells each one. The gate also examines each resource of
|
|
690
|
+
* each copy as a resource, so a fault of a resource of a group comes at each copy.
|
|
691
|
+
*
|
|
464
692
|
* The warnings:
|
|
465
693
|
* - `provider-need`: the part of a resource does not need the part of its provider configuration. The stack does not show that dependence.
|
|
466
694
|
* - `variable-unused`: no value reads a variable.
|
|
695
|
+
* - `group-unused`: no copy names a group.
|
|
696
|
+
* - `param-unused`: no resource of a group reads a parameter.
|
|
467
697
|
*
|
|
468
698
|
* The gate does not examine the stack: `checkStack` of the core does. The function is pure.
|
|
469
699
|
*/
|
|
@@ -558,7 +788,7 @@ function checkTofu(layer, stack, options = {}) {
|
|
|
558
788
|
checkValues(provider.values, at, `the provider configuration "${address}"`, "provider", PROVIDER_META, provider.part);
|
|
559
789
|
}
|
|
560
790
|
const seen = /* @__PURE__ */ new Set();
|
|
561
|
-
for (const resource of layer
|
|
791
|
+
for (const resource of layerResources(layer)) {
|
|
562
792
|
const at = resourceAddress(resource);
|
|
563
793
|
const more = { part: resource.part };
|
|
564
794
|
if (seen.has(at)) {
|
|
@@ -582,11 +812,12 @@ function checkTofu(layer, stack, options = {}) {
|
|
|
582
812
|
else if (builtin) {
|
|
583
813
|
if (resource.cost !== void 0 && resource.cost > 0) error("cost-builtin", at, `The resource "${at}" is a part of OpenTofu, and its record has a planned cost of ${money(resource.cost)}. It counts against no account.`, more);
|
|
584
814
|
} else if (resource.cost === void 0) error("cost-none", at, `The resource "${at}" has no planned cost. A cost that is not known is not 0: give the cost of a month, or 0 for a resource with no price.`, more);
|
|
585
|
-
if (provider !== void 0 && provider.part !== resource.part && parts.has(resource.part) && parts.has(provider.part) && !neededParts(stack, resource.part).has(provider.part)) add("warning", "provider-need", at, `The resource "${at}" makes the part "${resource.part}" with the provider configuration of "${provider.part}", and "${resource.part}" does not need "${provider.part}" in the stack.`, {
|
|
815
|
+
if (provider !== void 0 && provider.part !== resource.part && parts.has(resource.part) && parts.has(provider.part) && !neededParts$1(stack, resource.part).has(provider.part)) add("warning", "provider-need", at, `The resource "${at}" makes the part "${resource.part}" with the provider configuration of "${provider.part}", and "${resource.part}" does not need "${provider.part}" in the stack.`, {
|
|
586
816
|
...more,
|
|
587
817
|
other: provider.part
|
|
588
818
|
});
|
|
589
819
|
}
|
|
820
|
+
faults.push(...groupFaults(layer));
|
|
590
821
|
for (const cycle of resourceCycles(layer, stack)) {
|
|
591
822
|
const [first = "", second] = cycle;
|
|
592
823
|
error("cycle", first, cycle.length === 1 ? `The resource "${first}" reads its own attribute, so OpenTofu cannot make it.` : `The resources ${names(cycle)} wait for each other, so OpenTofu can make none of them.`, second === void 0 ? {} : { other: second });
|
|
@@ -622,12 +853,13 @@ function checkTofu(layer, stack, options = {}) {
|
|
|
622
853
|
*
|
|
623
854
|
* - The resources, the provider configurations and the variables are in the order of the fragments.
|
|
624
855
|
* - A resource address in two or more fragments is a fault, also when the resources are equal.
|
|
625
|
-
* - The same rule holds for the address of a provider configuration
|
|
856
|
+
* - The same rule holds for the address of a provider configuration, the name of a variable, of a group and of a copy.
|
|
626
857
|
* - The layer has one version of OpenTofu. A fragment with a different value is a fault.
|
|
627
858
|
* - The state has one place. Thus a backend in two or more fragments is a fault, also when the backends are equal.
|
|
628
859
|
*
|
|
629
860
|
* A resource of one fragment can use a provider configuration or a variable of a different fragment.
|
|
630
|
-
*
|
|
861
|
+
* A copy of one fragment can name a group of a different fragment.
|
|
862
|
+
* The joined layer has the field `providers`, `variables`, `groups` or `copies` when a fragment has it. The function is pure, and it
|
|
631
863
|
* changes no layer. The gate `checkTofu` examines the joined layer afterward.
|
|
632
864
|
*
|
|
633
865
|
* @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.
|
|
@@ -639,9 +871,11 @@ function joinTofu(pieces) {
|
|
|
639
871
|
const providers = joinRecords(pieces, (layer) => layer.providers, providerAddress, "provider configuration");
|
|
640
872
|
const variables = joinRecords(pieces, (layer) => layer.variables, (variable) => variable.name, "variable");
|
|
641
873
|
const resources = joinRecords(pieces, (layer) => layer.resources, resourceAddress, "resource");
|
|
874
|
+
const groups = joinRecords(pieces, (layer) => layer.groups, (group) => group.name, "group");
|
|
875
|
+
const copies = joinRecords(pieces, (layer) => layer.copies, copyName, "copy");
|
|
642
876
|
const errors = [...version.errors];
|
|
643
877
|
if (backends.length > 1) errors.push(`The fragments ${backends.map((piece) => `"${piece.from}"`).join(", ")} each have a backend. The state has one place.`);
|
|
644
|
-
errors.push(...providers.errors, ...variables.errors, ...resources.errors);
|
|
878
|
+
errors.push(...providers.errors, ...variables.errors, ...resources.errors, ...groups.errors, ...copies.errors);
|
|
645
879
|
if (errors.length > 0) return {
|
|
646
880
|
ok: false,
|
|
647
881
|
errors
|
|
@@ -655,10 +889,12 @@ function joinTofu(pieces) {
|
|
|
655
889
|
...backend === void 0 ? {} : { backend },
|
|
656
890
|
...pieces.some((piece) => piece.layer.providers !== void 0) ? { providers: providers.items } : {},
|
|
657
891
|
...pieces.some((piece) => piece.layer.variables !== void 0) ? { variables: variables.items } : {},
|
|
658
|
-
resources: resources.items
|
|
892
|
+
resources: resources.items,
|
|
893
|
+
...pieces.some((piece) => piece.layer.groups !== void 0) ? { groups: groups.items } : {},
|
|
894
|
+
...pieces.some((piece) => piece.layer.copies !== void 0) ? { copies: copies.items } : {}
|
|
659
895
|
}
|
|
660
896
|
};
|
|
661
897
|
}
|
|
662
|
-
export {
|
|
898
|
+
export { localAddress as A, isObject as B, resourceCycles as C, copyResources as D, copyResourceName as E, TYPE_FORM as F, renderValue as G, pathText as H, VERSION_FORM as I, valueUses as K, escapeTemplate as L, PATH_FORM as M, PROVIDER_FORM as N, groupFaults as O, SOURCE_FORM as P, isForm as R, neededParts as S, resourcesByPart as T, refOf as U, paramOf as V, refParts as W, isZeroOrMore as _, checkTofu as a, dependsOn as b, PLANNED_OVER as c, UNKNOWN_COSTS as d, accountKey as f, evaluateCost as g, costSpace as h, TOFU_CODES as i, NAME_FORM as j, layerResources as k, PLANNED_ROOM as l, budgetsByPart as m, PROVIDER_META as n, COST_LAYER_KEY as o, accountStates as p, varOf as q, RESOURCE_META as r, PLANNED as s, joinTofu as t, PLANNED_TOTAL as u, plannedTotal as v, resourceRefs as w, firstResources as x, resourceKey as y, isList as z };
|
|
663
899
|
|
|
664
|
-
//# sourceMappingURL=join-
|
|
900
|
+
//# sourceMappingURL=join-Bzyt9lhB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-Bzyt9lhB.js","names":["neededParts"],"sources":["../src/values.ts","../src/groups.ts","../src/queries.ts","../src/cost.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import type { TofuObject, TofuValue } from \"./layer.ts\";\n\n// The forms of a value, and the text of each value in the files.\n// In the JSON syntax of OpenTofu, each text is a template. Thus the generator escapes each text of a record.\n\n/** The form of the type of a resource and of the type of a backend. */\nexport const TYPE_FORM: RegExp = /^[a-z][a-z0-9_]*$/;\n\n/** The form of the local name of a provider, for example `example` or `example-beta`. */\nexport const PROVIDER_FORM: RegExp = /^[a-z][a-z0-9_-]*$/;\n\n/** The form of a name in the files: the name of a resource, of a variable, of an alias and of an argument. */\nexport const NAME_FORM: RegExp = /^[A-Za-z_][A-Za-z0-9_-]*$/;\n\n/**\n * The form of a path of attributes, for example `network[0].address` or `metadata[\"ssh-keys\"]`. A key of a map in quotes has\n * letters, digits and the characters `_ . : / -` only. Thus a path holds no template sequence and no quote of its own.\n */\nexport const PATH_FORM: RegExp = /^[A-Za-z_][A-Za-z0-9_-]*(\\.[A-Za-z_][A-Za-z0-9_-]*|\\[[0-9]+\\]|\\[\"[A-Za-z0-9_.:/-]+\"\\])*$/;\n\n/** The form of the address of a provider in a registry: two or three words with `/` between them. */\nexport const SOURCE_FORM: RegExp = /^[a-z0-9][a-z0-9.-]*(\\/[a-z0-9][a-z0-9_-]*){1,2}$/;\n\n/** The form of a list of versions, for example `>= 1.8, < 2.0`. */\nexport const VERSION_FORM: RegExp = /^[0-9A-Za-z .,<>=~!+-]+$/;\n\n/** The parts of a reference: the address of a resource, and a path of attributes of it. */\nexport interface RefParts {\n readonly address: string;\n readonly attribute: string;\n}\n\n/**\n * This function gives the parts of the text of a reference, for example `example_server.web.address`.\n * It gives `undefined` for a text with a different form.\n */\nexport function refParts(ref: string): RefParts | undefined {\n const [type, name, ...rest] = ref.split(\".\");\n if (type === undefined || name === undefined || rest.length === 0) return undefined;\n // An index stays with the word before it, so the name of the resource can not have one.\n const attribute = rest.join(\".\");\n if (!TYPE_FORM.test(type) || !NAME_FORM.test(name) || !PATH_FORM.test(attribute)) return undefined;\n return { address: `${type}.${name}`, attribute };\n}\n\n/** This function tells if a value is a list. */\nexport function isList(value: TofuValue): value is readonly TofuValue[] {\n return Array.isArray(value);\n}\n\n/** This function tells if a value is an object of values. A list and `null` are not objects. */\nexport function isObject(value: TofuValue): value is TofuObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** This function tells if an object has a key that starts with `$`: the object is a form, not a map of arguments. */\nexport function isForm(value: TofuObject): boolean {\n return Object.keys(value).some((key) => key.startsWith(\"$\"));\n}\n\n/** This function gives the one value of a form with the one key `key`, when that value is a text. */\nfunction formText(value: TofuObject, key: string): string | undefined {\n const keys = Object.keys(value);\n const text = value[key];\n return keys.length === 1 && keys[0] === key && typeof text === \"string\" ? text : undefined;\n}\n\n/** This function gives the text of a correct reference form, `{ \"$ref\": \"type.name.attribute\" }`. */\nexport function refOf(value: TofuObject): string | undefined {\n const text = formText(value, \"$ref\");\n return text !== undefined && refParts(text) !== undefined ? text : undefined;\n}\n\n/** This function gives the name of a correct variable form, `{ \"$var\": \"name\" }`. */\nexport function varOf(value: TofuObject): string | undefined {\n const text = formText(value, \"$var\");\n return text !== undefined && NAME_FORM.test(text) ? text : undefined;\n}\n\n/** This function gives the name of a correct parameter form, `{ \"$param\": \"name\" }`. Only a resource of a group can have one. */\nexport function paramOf(value: TofuObject): string | undefined {\n const text = formText(value, \"$param\");\n return text !== undefined && NAME_FORM.test(text) ? text : undefined;\n}\n\n/**\n * This function escapes the template sequences of a text. OpenTofu then reads the text as it is in the record.\n * `$${` is the escape of `${`, and `%%{` is the escape of `%{`.\n */\nexport function escapeTemplate(text: string): string {\n // A function gives each replacement: in a replacement text, `$$` is the escape of one `$`.\n return text.replaceAll(\"${\", () => \"$${\").replaceAll(\"%{\", () => \"%%{\");\n}\n\n/**\n * This function gives a value as OpenTofu reads it in a JSON file.\n *\n * - A text and each key of an object are escaped.\n * - A reference form becomes the expression of the attribute, and a variable form the expression of the variable.\n *\n * A form that is not correct stays an object with an escaped key. The gate `checkTofu` refuses such a layer.\n */\nexport function renderValue(value: TofuValue): TofuValue {\n if (typeof value === \"string\") return escapeTemplate(value);\n if (isList(value)) return value.map(renderValue);\n if (!isObject(value)) return value;\n const ref = refOf(value);\n if (ref !== undefined) return `\\${${ref}}`;\n const variable = varOf(value);\n if (variable !== undefined) return `\\${var.${variable}}`;\n return Object.fromEntries(Object.entries(value).map(([key, item]) => [escapeTemplate(key), renderValue(item)]));\n}\n\n/** A place in a value: the keys and the positions from the value to the place. */\nexport type ValuePath = readonly (string | number)[];\n\n/** A form of a value, with its place. `text` is absent when the form is not correct. */\nexport interface FormUse {\n readonly kind: \"ref\" | \"var\" | \"bad\";\n readonly path: ValuePath;\n readonly text?: string | undefined;\n}\n\n/** One number of a value that is not finite, with its place. */\nexport interface NumberUse {\n readonly path: ValuePath;\n readonly value: number;\n}\n\n/** The forms and the numbers that are not finite of a value. */\nexport interface ValueUses {\n readonly forms: readonly FormUse[];\n readonly numbers: readonly NumberUse[];\n}\n\n/** This function gives each form of a value and each number that is not finite, in the sequence of the value. */\nexport function valueUses(value: TofuValue): ValueUses {\n const forms: FormUse[] = [];\n const numbers: NumberUse[] = [];\n const walk = (item: TofuValue, path: ValuePath): void => {\n if (typeof item === \"number\") {\n if (!Number.isFinite(item)) numbers.push({ path, value: item });\n return;\n }\n if (isList(item)) {\n item.forEach((child, index) => {\n walk(child, [...path, index]);\n });\n return;\n }\n if (!isObject(item)) return;\n if (isForm(item)) {\n const ref = refOf(item);\n const variable = varOf(item);\n if (ref !== undefined) forms.push({ kind: \"ref\", path, text: ref });\n else if (variable !== undefined) forms.push({ kind: \"var\", path, text: variable });\n else forms.push({ kind: \"bad\", path });\n return;\n }\n for (const [key, child] of Object.entries(item)) walk(child, [...path, key]);\n };\n walk(value, []);\n return { forms, numbers };\n}\n\n/** This function gives a place in a value as a text, for example `disk.0.size`. The place of the value is `(the value)`. */\nexport function pathText(path: ValuePath): string {\n return path.length === 0 ? \"(the value)\" : path.join(\".\");\n}\n","import type { TofuFault } from \"./check.ts\";\nimport {\n BUILTIN_PROVIDER,\n copyName,\n resourceAddress,\n typeProvider,\n type Copy,\n type Group,\n type GroupResource,\n type Resource,\n type TofuLayer,\n type TofuObject,\n type TofuValue,\n} from \"./layer.ts\";\nimport { isForm, isList, isObject, NAME_FORM, paramOf, pathText, refOf, refParts, type ValuePath } from \"./values.ts\";\n\n// The groups of resources and their copies. The resources of a copy are a view of its group. Each function of the package\n// reads the resources of a layer through `layerResources`, so each gate, each query and the files cover the copies.\n\n/** This function gives the local address of a resource of a group: its type, a point and its local name. */\nexport function localAddress(resource: GroupResource): string {\n return `${resource.type}.${resource.name}`;\n}\n\n/** This function gives the name in the files of a resource of a copy: the name of the copy, `_` and the local name. */\nexport function copyResourceName(copy: Copy, resource: GroupResource): string {\n return `${copyName(copy)}_${resource.name}`;\n}\n\n/** This function gives the provider name of the address of a provider configuration: the word before the point. */\nfunction providerName(address: string): string {\n const end = address.indexOf(\".\");\n return end === -1 ? address : address.slice(0, end);\n}\n\n/** This function tells if a resource of a group is a part of OpenTofu, with no provider configuration. */\nfunction isBuiltinMember(resource: GroupResource): boolean {\n return resource.provider === undefined && typeProvider(resource.type) === BUILTIN_PROVIDER;\n}\n\n/** This function gives the value of each parameter of a group for a copy. It gives `undefined` when a parameter has no value. */\nfunction paramValues(group: Group, copy: Copy): Map<string, TofuValue> | undefined {\n const values = new Map<string, TofuValue>();\n for (const param of group.params ?? []) {\n const value = copy.values !== undefined && Object.hasOwn(copy.values, param.name) ? copy.values[param.name] : param.default;\n if (value === undefined) return undefined;\n values.set(param.name, value);\n }\n return values;\n}\n\n/**\n * This function fills a value of a resource of a group for one copy. A parameter form becomes the value of the parameter.\n * A reference to a local address of the group becomes a reference to the resource of the copy. The value of a parameter does not change.\n */\nfunction fill(value: TofuValue, params: ReadonlyMap<string, TofuValue>, addresses: ReadonlyMap<string, string>): TofuValue {\n if (isList(value)) return value.map((item) => fill(item, params, addresses));\n if (!isObject(value)) return value;\n if (isForm(value)) {\n const param = paramOf(value);\n const given = param === undefined ? undefined : params.get(param);\n if (given !== undefined) return given;\n const ref = refOf(value);\n const parts = ref === undefined ? undefined : refParts(ref);\n const address = parts === undefined ? undefined : addresses.get(parts.address);\n return parts !== undefined && address !== undefined ? { $ref: `${address}.${parts.attribute}` } : value;\n }\n return fillObject(value, params, addresses);\n}\n\n/** This function fills each argument of an object. The object itself is not a form, also when it has a key that starts with `$`. */\nfunction fillObject(values: TofuObject, params: ReadonlyMap<string, TofuValue>, addresses: ReadonlyMap<string, string>): TofuObject {\n return Object.fromEntries(Object.entries(values).map(([key, item]) => [key, fill(item, params, addresses)]));\n}\n\n/** This function gives the provider configuration of a resource of a copy. A configuration of the copy with the same provider name replaces that of the group. */\nfunction copyProvider(copy: Copy, resource: GroupResource): string | undefined {\n if (isBuiltinMember(resource)) return undefined;\n const name = providerName(resource.provider ?? typeProvider(resource.type));\n return copy.providers?.find((address) => providerName(address) === name) ?? resource.provider;\n}\n\n/**\n * This function gives the resources of the copies of a layer, in the sequence of the copies and of the resources of each group.\n *\n * - A resource of a copy makes the part of the copy. Its name is the name of the copy, `_` and its local name.\n * - A parameter form becomes the value of the copy, or the default of the parameter.\n * - A reference to a local address of the group reads the resource of the same copy.\n * - A configuration of the copy replaces the configuration of the same provider name.\n *\n * A copy whose group the layer does not have, or that gives no value for a parameter with no default, makes no resource.\n * For two groups with one name, the copies use the first one. The gate `checkTofu` gives a fault for each such record.\n */\nexport function copyResources(layer: TofuLayer): Resource[] {\n const groups = new Map<string, Group>();\n for (const group of layer.groups ?? []) if (!groups.has(group.name)) groups.set(group.name, group);\n return (layer.copies ?? []).flatMap((copy) => {\n const group = groups.get(copy.group);\n const params = group === undefined ? undefined : paramValues(group, copy);\n if (group === undefined || params === undefined) return [];\n const addresses = new Map(group.resources.map((resource) => [localAddress(resource), `${resource.type}.${copyResourceName(copy, resource)}`]));\n return group.resources.map((resource): Resource => {\n const provider = copyProvider(copy, resource);\n return {\n part: copy.part,\n type: resource.type,\n name: copyResourceName(copy, resource),\n ...(provider === undefined ? {} : { provider }),\n ...(resource.values === undefined ? {} : { values: fillObject(resource.values, params, addresses) }),\n ...(resource.cost === undefined ? {} : { cost: resource.cost }),\n ...(resource.keep === undefined ? {} : { keep: resource.keep }),\n ...(resource.ignore === undefined ? {} : { ignore: resource.ignore }),\n };\n });\n });\n}\n\n/** This function gives each resource of a layer: the resources of the field `resources`, and then the resources of the copies. */\nexport function layerResources(layer: TofuLayer): readonly Resource[] {\n return (layer.copies ?? []).length === 0 ? layer.resources : [...layer.resources, ...copyResources(layer)];\n}\n\n/** One parameter form of a value, with its place. */\ninterface ParamUse {\n readonly name: string;\n readonly path: ValuePath;\n}\n\n/** This function gives each correct parameter form of the arguments of a record, in the sequence of the arguments. */\nfunction paramUses(values: TofuObject): ParamUse[] {\n const uses: ParamUse[] = [];\n const walk = (item: TofuValue, path: ValuePath): void => {\n if (isList(item)) {\n item.forEach((child, index) => {\n walk(child, [...path, index]);\n });\n return;\n }\n if (!isObject(item)) return;\n const name = isForm(item) ? paramOf(item) : undefined;\n if (name !== undefined) uses.push({ name, path });\n else if (!isForm(item)) for (const [key, child] of Object.entries(item)) walk(child, [...path, key]);\n };\n for (const [key, child] of Object.entries(values)) walk(child, [key]);\n return uses;\n}\n\n/** This function gives a list of names for a message, for example `\"a\", \"b\"`. */\nfunction quoted(items: readonly string[]): string {\n return items.map((item) => `\"${item}\"`).join(\", \");\n}\n\n/**\n * This function gives the faults of the groups and of the copies of a layer. `checkTofu` gives them with its other faults.\n * The resources of the copies get the faults of each resource there: the gate examines them as resources.\n *\n * The errors:\n * - `group-form`: the name of a group, of a parameter or of a copy does not have the form of a name. Or a group has no resource.\n * - `group-duplicate`: two groups, two parameters of a group, two resources of a group with one local address, or two copies have one name.\n * - `group-shadow`: a local address of a group is the address of a resource of the layer. A reference in the group then reads the copy.\n * - `group-none`: a copy names a group that the layer does not have.\n * - `param-none`: a parameter form of a group names a parameter that the group does not have.\n * - `param-missing`: a copy gives no value for a parameter with no default.\n * - `param-unknown`: a copy gives a value for a parameter that the group does not have.\n * - `copy-provider`: a configuration of a copy replaces no configuration of the group, or two of them have one provider name.\n * A configuration that the layer does not have gives `provider-none` at each resource of the copy.\n *\n * The warnings:\n * - `group-unused`: no copy names a group.\n * - `param-unused`: no resource of a group reads a parameter.\n */\nexport function groupFaults(layer: TofuLayer): TofuFault[] {\n const faults: TofuFault[] = [];\n const add = (level: TofuFault[\"level\"], code: TofuFault[\"code\"], at: string, message: string, more: { readonly other?: string; readonly part?: string } = {}): void => {\n faults.push({ level, code, at, message, ...more });\n };\n const top = new Set(layer.resources.map(resourceAddress));\n const groups = new Map<string, Group>();\n for (const group of layer.groups ?? []) {\n const at = `group.${group.name}`;\n if (groups.has(group.name)) {\n add(\"error\", \"group-duplicate\", at, `Two groups have the name \"${group.name}\".`);\n continue;\n }\n groups.set(group.name, group);\n if (!NAME_FORM.test(group.name)) add(\"error\", \"group-form\", at, `The name \"${group.name}\" of a group does not have the form of a name.`);\n if (group.resources.length === 0) add(\"error\", \"group-form\", at, `The group \"${group.name}\" has no resource.`);\n const params = new Set<string>();\n for (const param of group.params ?? []) {\n if (params.has(param.name)) add(\"error\", \"group-duplicate\", at, `Two parameters of the group \"${group.name}\" have the name \"${param.name}\".`);\n else if (!NAME_FORM.test(param.name)) add(\"error\", \"group-form\", at, `The name \"${param.name}\" of a parameter of the group \"${group.name}\" does not have the form of a name.`);\n params.add(param.name);\n }\n const locals = new Set<string>();\n const read = new Set<string>();\n for (const resource of group.resources) {\n const local = localAddress(resource);\n if (locals.has(local)) add(\"error\", \"group-duplicate\", at, `Two resources of the group \"${group.name}\" have the local address \"${local}\".`);\n locals.add(local);\n if (top.has(local)) {\n add(\"error\", \"group-shadow\", at, `The group \"${group.name}\" has the local address \"${local}\", and the layer has a resource with that address. A reference in the group reads the resource of the copy.`, {\n other: local,\n });\n }\n for (const use of paramUses(resource.values ?? {})) {\n if (params.has(use.name)) read.add(use.name);\n else add(\"error\", \"param-none\", at, `The value at \"${pathText(use.path)}\" of the resource \"${local}\" of the group \"${group.name}\" names the parameter \"${use.name}\", which the group does not have.`);\n }\n }\n for (const name of params) {\n if (!read.has(name)) add(\"warning\", \"param-unused\", at, `No resource of the group \"${group.name}\" reads the parameter \"${name}\".`);\n }\n }\n\n const copies = new Set<string>();\n const copied = new Set<string>();\n for (const copy of layer.copies ?? []) {\n const name = copyName(copy);\n const at = `copy.${name}`;\n const more = { part: copy.part };\n if (copies.has(name)) {\n add(\"error\", \"group-duplicate\", at, `Two copies have the name \"${name}\".`, more);\n continue;\n }\n copies.add(name);\n if (!NAME_FORM.test(name)) add(\"error\", \"group-form\", at, `The name \"${name}\" of a copy does not have the form of a name.`, more);\n const group = groups.get(copy.group);\n if (group === undefined) {\n add(\"error\", \"group-none\", at, `The copy \"${name}\" names the group \"${copy.group}\", which the layer does not have. It makes no resource.`, { ...more, other: `group.${copy.group}` });\n continue;\n }\n copied.add(group.name);\n const params = group.params ?? [];\n const given = Object.keys(copy.values ?? {});\n for (const key of given) {\n if (!params.some((param) => param.name === key)) add(\"error\", \"param-unknown\", at, `The copy \"${name}\" gives the parameter \"${key}\", which the group \"${group.name}\" does not have.`, more);\n }\n const missing = params.filter((param) => param.default === undefined && !given.includes(param.name)).map((param) => param.name);\n if (missing.length > 0) add(\"error\", \"param-missing\", at, `The copy \"${name}\" gives no value for the parameters ${quoted(missing)} of the group \"${group.name}\". It makes no resource.`, more);\n const used = new Set(group.resources.filter((resource) => !isBuiltinMember(resource)).map((resource) => providerName(resource.provider ?? typeProvider(resource.type))));\n const replaced = new Set<string>();\n for (const address of copy.providers ?? []) {\n const provider = providerName(address);\n if (replaced.has(provider)) {\n add(\"error\", \"copy-provider\", at, `The copy \"${name}\" has two configurations of the provider \"${provider}\". Each one replaces the configuration of its provider name.`, more);\n } else if (!used.has(provider)) {\n add(\"error\", \"copy-provider\", at, `The configuration \"${address}\" of the copy \"${name}\" replaces no configuration: no resource of the group \"${group.name}\" uses the provider \"${provider}\".`, more);\n }\n replaced.add(provider);\n }\n }\n for (const group of groups.values()) {\n if (!copied.has(group.name)) add(\"warning\", \"group-unused\", `group.${group.name}`, `No copy names the group \"${group.name}\". It makes no resource.`);\n }\n return faults;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { partNeeds, partsById, type Part, type Stack } from \"@mark1russell7/system-stack\";\nimport { layerResources } from \"./groups.ts\";\nimport { resourceAddress, type Resource, type TofuLayer } from \"./layer.ts\";\nimport { refParts, valueUses } from \"./values.ts\";\n\n// The queries over the records. The sequence of the resources in the files comes from the needs of the stack,\n// so a person writes each dependence one time: in the stack.\n\n/** This function gives the first resource of each address of a layer, in the sequence of the records. The resources of the copies come last. */\nexport function firstResources(layer: TofuLayer): readonly Resource[] {\n const seen = new Set<string>();\n return layerResources(layer).filter((resource) => {\n const address = resourceAddress(resource);\n if (seen.has(address)) return false;\n seen.add(address);\n return true;\n });\n}\n\n/**\n * This function gives the addresses of the resources of each part, by the `id` of the part.\n * The addresses of a part are sorted. With them, a host joins a plan or a state to the parts of the stack.\n */\nexport function resourcesByPart(layer: TofuLayer): Map<string, string[]> {\n const byPart = new Map<string, string[]>();\n for (const resource of firstResources(layer)) {\n const addresses = byPart.get(resource.part) ?? [];\n addresses.push(resourceAddress(resource));\n byPart.set(resource.part, addresses);\n }\n for (const addresses of byPart.values()) addresses.sort();\n return byPart;\n}\n\n/**\n * This function gives the address of each resource that the arguments of a resource read, sorted.\n * Each address comes one time. An address can name a resource that the layer does not have.\n */\nexport function resourceRefs(resource: Resource): string[] {\n const addresses = new Set<string>();\n for (const form of valueUses(resource.values ?? {}).forms) {\n // The arguments as a whole are not a value, so a form at the empty place reads nothing.\n const parts = form.kind === \"ref\" && form.text !== undefined && form.path.length > 0 ? refParts(form.text) : undefined;\n if (parts !== undefined) addresses.add(parts.address);\n }\n return [...addresses].sort();\n}\n\n/**\n * This function walks the needs of a part, nearest first. It gives the `id` of each part where the walk stops or goes on.\n * The walk does not go past a part for which `stop` gives `true`. It does not come back to the first part.\n */\nfunction walkNeeds(parts: ReadonlyMap<string, Part>, from: string, stop: (id: string) => boolean): string[] {\n const seen = new Set<string>([from]);\n const found: string[] = [];\n let level = partNeeds(parts.get(from) ?? { id: from, kind: \"\" });\n while (level.length > 0) {\n const next: string[] = [];\n for (const id of level) {\n if (seen.has(id)) continue;\n seen.add(id);\n found.push(id);\n const part = parts.get(id);\n if (part !== undefined && !stop(id)) next.push(...partNeeds(part));\n }\n level = next;\n }\n return found;\n}\n\n// The core has `neededParts` since system-stack 0.1.6. This entry gives it again, so the API of the package does not change.\nexport { neededParts } from \"@mark1russell7/system-stack\";\n\n/**\n * This function gives the dependencies of each resource that come from the needs of the stack, by the address of the resource.\n *\n * - A resource depends on the resources of each part that its part needs.\n * - For a needed part with no resource, the walk goes on to the needs of that part. It stops at the nearest parts with resources.\n * - An address that the arguments of the resource read is not in the list: OpenTofu knows that dependence from the arguments.\n *\n * The addresses of a resource are sorted. The generator writes them as `depends_on`.\n */\nexport function dependsOn(layer: TofuLayer, stack: Stack): Map<string, string[]> {\n const parts = partsById(stack);\n const byPart = resourcesByPart(layer);\n const result = new Map<string, string[]>();\n for (const resource of firstResources(layer)) {\n const read = new Set(resourceRefs(resource));\n const addresses = walkNeeds(parts, resource.part, (id) => byPart.has(id)).flatMap((id) => byPart.get(id) ?? []);\n result.set(\n resourceAddress(resource),\n addresses.filter((address) => !read.has(address)).sort(),\n );\n }\n return result;\n}\n\n/**\n * This function gives the cycles of the resources of a layer. In a cycle, each resource waits for a different one, and OpenTofu can make none of them.\n * A resource waits for each resource that its arguments read, and for each one of `dependsOn`.\n * Each cycle is a sorted list of addresses. A resource that reads its own attribute is a cycle of one resource.\n */\nexport function resourceCycles(layer: TofuLayer, stack: Stack): string[][] {\n const depends = dependsOn(layer, stack);\n const waits = new Map<string, string[]>();\n for (const resource of firstResources(layer)) {\n const address = resourceAddress(resource);\n waits.set(address, [...resourceRefs(resource), ...(depends.get(address) ?? [])]);\n }\n const nodes = [...waits.keys()].sort();\n return stronglyConnectedComponents(nodes, (address) => waits.get(address) ?? []).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (waits.get(only) ?? []).includes(only);\n });\n}\n","import { app, axes, each, evaluate, lit, ref, space, type Expr, type Result, type Space } from \"@mark1russell7/vex\";\nimport { BoolDomain, NumDomain, TextDomain } from \"@mark1russell7/vex-domains\";\nimport { isBuiltin, resourceAddress, resourceProvider, type TofuLayer } from \"./layer.ts\";\nimport { firstResources } from \"./queries.ts\";\n\n// The planned cost of the resources, as Vex programs. A program is data: `explain` of Vex shows each step.\n// The layer becomes a tree: the layer, then each account, then each resource of the account.\n\n/**\n * The limit of the cost of a part for a month. A state of a service of the spend add-on has this form.\n * Thus a host gives the states of a spend layer as the budgets, and the two add-ons do not know each other.\n */\nexport interface Budget {\n /** The `id` of the part: an account, a project or a tenant. */\n readonly part: string;\n /** The hard limit of the cost of the part for a month. A part with no hard limit has none. */\n readonly hardLimit?: number | undefined;\n}\n\n/** The key of the layer node: the root of the cost tree. */\nexport const COST_LAYER_KEY = \"layer\";\n\n/** This function gives the key of the node of an account: the text `account:` and the `id` of its part. */\nexport function accountKey(part: string): string {\n return `account:${part}`;\n}\n\n/** This function gives the key of the node of a resource: the text `resource:` and its address. */\nexport function resourceKey(address: string): string {\n return `resource:${address}`;\n}\n\n/** This function tells if a value is a finite number, 0 or more. */\nexport function isZeroOrMore(value: number): boolean {\n return Number.isFinite(value) && value >= 0;\n}\n\n/** This function gives the first budget of each part, by the `id` of the part. */\nexport function budgetsByPart(budgets: readonly Budget[]): Map<string, Budget> {\n const byPart = new Map<string, Budget>();\n for (const budget of budgets) if (!byPart.has(budget.part)) byPart.set(budget.part, budget);\n return byPart;\n}\n\n/** The planned cost of each resource of an account. A resource with no known cost gives an error value. */\nconst COSTS: Expr = each(axes.children, ref(\"cost\"));\n\n/** The planned cost of an account in a month: the sum of the known costs of its resources. The program evaluates at an account node. */\nexport const PLANNED: Expr = app(\"sum\", COSTS);\n\n/** This test tells if a resource node has a known cost. */\nconst HAS_COST: Expr = app(\"ifError\", app(\"eq\", ref(\"cost\"), ref(\"cost\")), lit(false));\n\n/** The count of the resources of an account with no known cost. The program evaluates at an account node. */\nexport const UNKNOWN_COSTS: Expr = app(\"count\", each(axes.where(axes.children, app(\"not\", HAS_COST)), ref(\"kind\")));\n\n/** This test tells if the planned cost of an account is more than its hard limit. An account with no hard limit gives an error value. */\nexport const PLANNED_OVER: Expr = app(\"gt\", PLANNED, ref(\"limit\"));\n\n/** The room of an account: its hard limit less its planned cost. An account with no hard limit gives an error value. */\nexport const PLANNED_ROOM: Expr = app(\"subtract\", ref(\"limit\"), PLANNED);\n\n/** The planned cost of the layer in a month: the sum of the planned costs of its accounts. The program evaluates at the layer node. */\nexport const PLANNED_TOTAL: Expr = app(\"sum\", each(axes.children, PLANNED));\n\n/**\n * This function gives the cost tree of a layer, as a space of Vex.\n *\n * - The layer is the root, with the key `COST_LAYER_KEY`.\n * - An account is a child of the layer: the part of a provider configuration that has one resource or more. Its field `limit` is its hard limit.\n * - A resource is a child of the account of its provider configuration. Its field `cost` is its planned cost.\n *\n * A cost or a limit that is less than 0 or not finite is not in the tree: it is not known.\n * A resource with no provider configuration is not in the tree, because it counts against no account.\n */\nexport function costSpace(layer: TofuLayer, budgets: readonly Budget[] = []): Space {\n const limits = budgetsByPart(budgets);\n const records: Record<string, Readonly<Record<string, unknown>>> = { [COST_LAYER_KEY]: { kind: \"layer\" } };\n const parents: Record<string, string | null> = { [COST_LAYER_KEY]: null };\n for (const resource of firstResources(layer)) {\n const provider = isBuiltin(resource) ? undefined : resourceProvider(layer, resource);\n if (provider === undefined) continue;\n const account = accountKey(provider.part);\n if (records[account] === undefined) {\n const limit = limits.get(provider.part)?.hardLimit;\n records[account] = { kind: \"account\", part: provider.part, ...(limit !== undefined && isZeroOrMore(limit) ? { limit } : {}) };\n parents[account] = COST_LAYER_KEY;\n }\n const key = resourceKey(resourceAddress(resource));\n records[key] = { kind: \"resource\", ...(resource.cost !== undefined && isZeroOrMore(resource.cost) ? { cost: resource.cost } : {}) };\n parents[key] = account;\n }\n return space.tree(records, parents);\n}\n\n/**\n * This function evaluates a program of this module at a node of a cost tree. It gives the value, or the error value.\n * `tree` is the result of `costSpace`, and `key` is the key of a node.\n */\nexport function evaluateCost(program: Expr, tree: Space, key: string): Result<unknown> {\n return evaluate(program, { space: tree, origin: key, domains: [NumDomain, BoolDomain, TextDomain] });\n}\n\n/** This function gives the number of a result, or `undefined` for an error value. */\nfunction numberOf(result: Result<unknown>): number | undefined {\n return result.ok && typeof result.value === \"number\" ? result.value : undefined;\n}\n\n/** The state of the planned cost of one account of a layer. */\nexport interface AccountState {\n /** The `id` of the part of the account. */\n readonly part: string;\n /** The addresses of the resources that count against the account, sorted. */\n readonly resources: readonly string[];\n /** The planned cost of the account in a month: the sum of the known costs of its resources. */\n readonly planned: number;\n /** The count of the resources with no known cost. With one or more, `planned` is not the whole cost. */\n readonly unknown: number;\n /** The hard limit of the account for a month. An account with no budget, or with a budget with no hard limit, has none. */\n readonly limit?: number | undefined;\n /** `true`: the planned cost is more than the hard limit. An account with no hard limit has no value. */\n readonly over?: boolean | undefined;\n /** The hard limit less the planned cost. An account with no hard limit has no value. */\n readonly room?: number | undefined;\n}\n\n/** This function gives the state of the planned cost of each account of a layer, in the sequence of the first resource of each account. */\nexport function accountStates(layer: TofuLayer, budgets: readonly Budget[] = []): AccountState[] {\n const tree = costSpace(layer, budgets);\n const accounts = new Map<string, string[]>();\n for (const resource of firstResources(layer)) {\n const provider = isBuiltin(resource) ? undefined : resourceProvider(layer, resource);\n if (provider === undefined) continue;\n const addresses = accounts.get(provider.part) ?? [];\n addresses.push(resourceAddress(resource));\n accounts.set(provider.part, addresses);\n }\n return [...accounts].map(([part, addresses]) => {\n const key = accountKey(part);\n const limit = numberOf(evaluateCost(ref(\"limit\"), tree, key));\n const over = evaluateCost(PLANNED_OVER, tree, key);\n const room = numberOf(evaluateCost(PLANNED_ROOM, tree, key));\n return {\n part,\n resources: [...addresses].sort(),\n planned: numberOf(evaluateCost(PLANNED, tree, key)) ?? 0,\n unknown: numberOf(evaluateCost(UNKNOWN_COSTS, tree, key)) ?? 0,\n ...(limit === undefined ? {} : { limit }),\n ...(over.ok && typeof over.value === \"boolean\" ? { over: over.value } : {}),\n ...(room === undefined ? {} : { room }),\n };\n });\n}\n\n/** This function gives the planned cost of a layer in a month: the sum of the planned costs of its accounts. */\nexport function plannedTotal(layer: TofuLayer): number {\n return numberOf(evaluateCost(PLANNED_TOTAL, costSpace(layer), COST_LAYER_KEY)) ?? 0;\n}\n","import { neededParts, partsById, type Fault, type FaultLevel, type Stack } from \"@mark1russell7/system-stack\";\nimport { accountStates, isZeroOrMore, type Budget } from \"./cost.ts\";\nimport { BUILTIN_PROVIDER, isBuiltin, providerAddress, resourceAddress, resourceName, resourceProvider, typeProvider, type Provider, type TofuLayer, type TofuObject } from \"./layer.ts\";\nimport { groupFaults, layerResources } from \"./groups.ts\";\nimport { firstResources, resourceCycles } from \"./queries.ts\";\nimport { isForm, NAME_FORM, PATH_FORM, pathText, PROVIDER_FORM, refParts, SOURCE_FORM, TYPE_FORM, valueUses, VERSION_FORM } from \"./values.ts\";\n\n// The gate of the OpenTofu layer. A gate that passes tells that the files are safe to write:\n// each record has a correct form, no resource waits in a cycle, and the planned cost of each account is known and not more than its hard limit.\n\n/** These are the codes of the faults of an OpenTofu layer. */\nexport const TOFU_CODES: readonly [\n \"version\",\n \"backend\",\n \"variable-form\",\n \"variable-duplicate\",\n \"provider-form\",\n \"provider-duplicate\",\n \"provider-source\",\n \"provider-part\",\n \"provider-value\",\n \"resource-form\",\n \"resource-duplicate\",\n \"resource-part\",\n \"provider-none\",\n \"ignore-form\",\n \"value-name\",\n \"value-meta\",\n \"value-form\",\n \"value-number\",\n \"ref-none\",\n \"var-none\",\n \"cycle\",\n \"cost-amount\",\n \"cost-none\",\n \"cost-builtin\",\n \"budget-duplicate\",\n \"budget-amount\",\n \"budget-none\",\n \"limit-none\",\n \"cost-over\",\n \"provider-need\",\n \"variable-unused\",\n \"group-form\",\n \"group-duplicate\",\n \"group-shadow\",\n \"group-none\",\n \"param-none\",\n \"param-missing\",\n \"param-unknown\",\n \"copy-provider\",\n \"group-unused\",\n \"param-unused\",\n] = [\n \"version\",\n \"backend\",\n \"variable-form\",\n \"variable-duplicate\",\n \"provider-form\",\n \"provider-duplicate\",\n \"provider-source\",\n \"provider-part\",\n \"provider-value\",\n \"resource-form\",\n \"resource-duplicate\",\n \"resource-part\",\n \"provider-none\",\n \"ignore-form\",\n \"value-name\",\n \"value-meta\",\n \"value-form\",\n \"value-number\",\n \"ref-none\",\n \"var-none\",\n \"cycle\",\n \"cost-amount\",\n \"cost-none\",\n \"cost-builtin\",\n \"budget-duplicate\",\n \"budget-amount\",\n \"budget-none\",\n \"limit-none\",\n \"cost-over\",\n \"provider-need\",\n \"variable-unused\",\n \"group-form\",\n \"group-duplicate\",\n \"group-shadow\",\n \"group-none\",\n \"param-none\",\n \"param-missing\",\n \"param-unknown\",\n \"copy-provider\",\n \"group-unused\",\n \"param-unused\",\n];\n\n/** A code of a fault of an OpenTofu layer. */\nexport type TofuCode = (typeof TOFU_CODES)[number];\n\n/**\n * A fault of an OpenTofu layer. Its field `at` is the place of the fault in the files.\n *\n * - For a resource, `at` is its address.\n * - For a provider configuration, `at` is `provider.` and its address.\n * - For a variable, `at` is `var.` and its name.\n * - For the settings, `at` is `terraform`.\n *\n * For a fault of a budget or of an account, `at` is the `id` of the part.\n */\nexport interface TofuFault extends Fault {\n readonly code: TofuCode;\n /** The `id` of the part of the stack of the record with the fault. */\n readonly part?: string | undefined;\n}\n\n/** The options of the gate and of the generator. */\nexport interface TofuOptions {\n /**\n * The limit of the cost of each account for a month. The states of a spend layer have this form.\n * An account with resources and no budget stops the gate: the gate has no read of its limit.\n */\n readonly budgets?: readonly Budget[] | undefined;\n /** The currency of the costs and of the budgets, for the text of a fault. */\n readonly currency?: string | undefined;\n}\n\n/** These arguments of a resource are meta-arguments. The generator writes them from the records, so the arguments of a record cannot have them. */\nexport const RESOURCE_META: readonly string[] = [\"provider\", \"depends_on\", \"lifecycle\", \"count\", \"for_each\", \"provisioner\", \"connection\", \"dynamic\"];\n\n/** These arguments of a provider configuration are meta-arguments. The generator writes them from the records. */\nexport const PROVIDER_META: readonly string[] = [\"alias\", \"version\", \"for_each\"];\n\n/** This function gives a list of names for a message, for example `\"a\", \"b\"`. */\nfunction names(items: readonly string[]): string {\n return items.map((item) => `\"${item}\"`).join(\", \");\n}\n\n/**\n * This function gives each fault of an OpenTofu layer for a stack. A list with no error tells that the gate passes.\n *\n * The settings, the variables and the providers, as errors:\n * - `version`: the versions of OpenTofu do not have the form of a list of versions.\n * - `backend`: the type of the backend does not have the form of a type, or a value of the backend is not literal.\n * - `variable-form`: the name of a variable does not have the form of a name.\n * - `variable-duplicate`: two variables have one name.\n * - `provider-form`: the name, the alias, the source or the versions of a provider configuration do not have their form.\n * - `provider-duplicate`: two provider configurations have one address.\n * - `provider-source`: two configurations of one provider have different sources or versions.\n * - `provider-part`: a provider configuration names no part of the stack.\n * - `provider-value`: a value of a provider configuration reads a resource.\n *\n * The resources, as errors:\n * - `resource-form`: the type, the name or the import id of a resource does not have its form.\n * - `resource-duplicate`: two resources have one address.\n * - `resource-part`: a resource names no part of the stack.\n * - `provider-none`: the layer does not have the provider configuration of a resource.\n * - `ignore-form`: an attribute of `ignore` does not have the form of a path.\n *\n * The values, as errors:\n * - `value-name`: the name of an argument does not have the form of a name.\n * - `value-meta`: an argument is a meta-argument. The generator writes each meta-argument.\n * - `value-form`: an object has a key that starts with `$`, and it is not a correct reference or variable.\n * - `value-number`: a number is not finite. JSON cannot hold it.\n * - `ref-none`: a reference names a resource that the layer does not have.\n * - `var-none`: a value names a variable that the layer does not have.\n *\n * The queries, as errors:\n * - `cycle`: resources wait for each other, so OpenTofu can make none of them.\n *\n * The costs, as errors:\n * - `cost-amount`: the planned cost of a resource is less than 0 or not finite.\n * - `cost-none`: a resource of a provider has no planned cost. A cost that is not known is not 0.\n * - `cost-builtin`: a resource that is a part of OpenTofu has a planned cost above 0. It counts against no account.\n * - `budget-duplicate`: two budgets name one part.\n * - `budget-amount`: the hard limit of a budget is less than 0 or not finite.\n * - `budget-none`: no budget names an account with resources. The gate has no read of its limit, so it does not pass.\n * - `limit-none`: the resources of an account have a planned cost above 0, and the account has no hard limit.\n * - `cost-over`: the planned cost of an account is more than its hard limit.\n *\n * The groups and the copies, as errors: `group-form`, `group-duplicate`, `group-shadow`, `group-none`, `param-none`,\n * `param-missing`, `param-unknown` and `copy-provider`. `groupFaults` tells each one. The gate also examines each resource of\n * each copy as a resource, so a fault of a resource of a group comes at each copy.\n *\n * The warnings:\n * - `provider-need`: the part of a resource does not need the part of its provider configuration. The stack does not show that dependence.\n * - `variable-unused`: no value reads a variable.\n * - `group-unused`: no copy names a group.\n * - `param-unused`: no resource of a group reads a parameter.\n *\n * The gate does not examine the stack: `checkStack` of the core does. The function is pure.\n */\nexport function checkTofu(layer: TofuLayer, stack: Stack, options: TofuOptions = {}): TofuFault[] {\n const faults: TofuFault[] = [];\n const add = (level: FaultLevel, code: TofuCode, at: string, message: string, more: { readonly other?: string; readonly part?: string } = {}): void => {\n faults.push({ level, code, at, message, ...more });\n };\n const error = (code: TofuCode, at: string, message: string, more: { readonly other?: string; readonly part?: string } = {}): void => {\n add(\"error\", code, at, message, more);\n };\n const money = (amount: number): string => (options.currency === undefined ? String(amount) : `${String(amount)} ${options.currency}`);\n const parts = partsById(stack);\n const addresses = new Set(firstResources(layer).map(resourceAddress));\n\n const variables = new Set<string>();\n const readVariables = new Set<string>();\n for (const variable of layer.variables ?? []) {\n const at = `var.${variable.name}`;\n if (variables.has(variable.name)) {\n error(\"variable-duplicate\", at, `Two variables have the name \"${variable.name}\".`);\n continue;\n }\n variables.add(variable.name);\n if (!NAME_FORM.test(variable.name)) error(\"variable-form\", at, `The name \"${variable.name}\" of a variable does not have the form of a name.`);\n }\n\n /** This function examines the arguments of one record. `owner` is the record in words, for a message. */\n const checkValues = (values: TofuObject | undefined, at: string, owner: string, kind: \"resource\" | \"provider\" | \"backend\", meta: readonly string[], part?: string): void => {\n if (values === undefined) return;\n const more = part === undefined ? {} : { part };\n if (isForm(values)) {\n error(\"value-form\", at, `The arguments of ${owner} have a key that starts with \"$\". The arguments of a record are not a reference and not a variable.`, more);\n return;\n }\n for (const name of Object.keys(values)) {\n if (meta.includes(name)) error(\"value-meta\", at, `The argument \"${name}\" of ${owner} is a meta-argument. The generator writes it from the records.`, more);\n else if (!NAME_FORM.test(name)) error(\"value-name\", at, `The name \"${name}\" of an argument of ${owner} does not have the form of a name.`, more);\n }\n const uses = valueUses(values);\n for (const number of uses.numbers) error(\"value-number\", at, `The number ${String(number.value)} at \"${pathText(number.path)}\" of ${owner} is not finite.`, more);\n for (const form of uses.forms) {\n const place = pathText(form.path);\n if (form.kind === \"bad\" || form.text === undefined) {\n error(\"value-form\", at, `The object at \"${place}\" of ${owner} has a key that starts with \"$\", and it is not a correct reference or variable.`, more);\n } else if (kind === \"backend\") {\n error(\"backend\", at, `The value at \"${place}\" of ${owner} is not literal. A backend reads no variable and no resource.`, more);\n } else if (form.kind === \"var\") {\n if (variables.has(form.text)) readVariables.add(form.text);\n else error(\"var-none\", at, `The value at \"${place}\" of ${owner} names the variable \"${form.text}\", which the layer does not have.`, { ...more, other: `var.${form.text}` });\n } else if (kind === \"provider\") {\n error(\"provider-value\", at, `The value at \"${place}\" of ${owner} reads the resource attribute \"${form.text}\". A provider configuration reads no resource.`, more);\n } else {\n const address = refParts(form.text)?.address ?? \"\";\n if (!addresses.has(address)) error(\"ref-none\", at, `The value at \"${place}\" of ${owner} reads \"${form.text}\", and the layer has no resource \"${address}\".`, { ...more, other: address });\n }\n }\n };\n\n if (layer.version !== undefined && !VERSION_FORM.test(layer.version)) {\n error(\"version\", \"terraform\", `The versions \"${layer.version}\" of OpenTofu do not have the form of a list of versions, for example \">= 1.8\".`);\n }\n if (layer.backend !== undefined) {\n if (!TYPE_FORM.test(layer.backend.type)) error(\"backend\", \"terraform\", `The type \"${layer.backend.type}\" of the backend does not have the form of a type.`);\n checkValues(layer.backend.values, \"terraform\", \"the backend\", \"backend\", []);\n }\n\n const providers = new Set<string>();\n const firstOfName = new Map<string, Provider>();\n for (const provider of layer.providers ?? []) {\n const address = providerAddress(provider);\n const at = `provider.${address}`;\n const more = { part: provider.part };\n if (providers.has(address)) {\n error(\"provider-duplicate\", at, `Two provider configurations have the address \"${address}\".`, more);\n continue;\n }\n providers.add(address);\n if (!PROVIDER_FORM.test(provider.name)) error(\"provider-form\", at, `The name \"${provider.name}\" of a provider does not have the form of a provider name.`, more);\n else if (provider.name === BUILTIN_PROVIDER) error(\"provider-form\", at, `The provider \"${BUILTIN_PROVIDER}\" is a part of OpenTofu. It has no configuration.`, more);\n if (provider.alias !== undefined && !NAME_FORM.test(provider.alias)) error(\"provider-form\", at, `The alias \"${provider.alias}\" of the provider \"${provider.name}\" does not have the form of a name.`, more);\n if (!SOURCE_FORM.test(provider.source)) error(\"provider-form\", at, `The source \"${provider.source}\" of the provider \"${provider.name}\" does not have the form of a source, for example \"example-org/example\".`, more);\n if (provider.version !== undefined && !VERSION_FORM.test(provider.version)) {\n error(\"provider-form\", at, `The versions \"${provider.version}\" of the provider \"${provider.name}\" do not have the form of a list of versions, for example \"~> 2.0\".`, more);\n }\n const first = firstOfName.get(provider.name);\n if (first === undefined) firstOfName.set(provider.name, provider);\n else if (first.source !== provider.source || first.version !== provider.version) {\n error(\"provider-source\", at, `Two configurations of the provider \"${provider.name}\" have different sources or versions. A provider has one source and one list of versions.`, more);\n }\n if (!parts.has(provider.part)) error(\"provider-part\", at, `The provider configuration \"${address}\" names \"${provider.part}\", which is no part of the stack.`, { ...more, other: provider.part });\n checkValues(provider.values, at, `the provider configuration \"${address}\"`, \"provider\", PROVIDER_META, provider.part);\n }\n\n const seen = new Set<string>();\n for (const resource of layerResources(layer)) {\n const at = resourceAddress(resource);\n const more = { part: resource.part };\n if (seen.has(at)) {\n error(\"resource-duplicate\", at, `Two resources have the address \"${at}\".`, more);\n continue;\n }\n seen.add(at);\n if (!TYPE_FORM.test(resource.type)) error(\"resource-form\", at, `The type \"${resource.type}\" of a resource of \"${resource.part}\" does not have the form of a type.`, more);\n if (!NAME_FORM.test(resourceName(resource))) error(\"resource-form\", at, `The name \"${resourceName(resource)}\" of a resource of \"${resource.part}\" does not have the form of a name.`, more);\n if (resource.import === \"\") error(\"resource-form\", at, `The import id of the resource \"${at}\" is empty.`, more);\n if (!parts.has(resource.part)) error(\"resource-part\", at, `The resource \"${at}\" names \"${resource.part}\", which is no part of the stack.`, { ...more, other: resource.part });\n for (const path of resource.ignore ?? []) {\n if (!PATH_FORM.test(path)) error(\"ignore-form\", at, `The attribute \"${path}\" of the field \"ignore\" of the resource \"${at}\" does not have the form of a path.`, more);\n }\n checkValues(resource.values, at, `the resource \"${at}\"`, \"resource\", RESOURCE_META, resource.part);\n\n const builtin = isBuiltin(resource);\n const provider = builtin ? undefined : resourceProvider(layer, resource);\n if (!builtin && provider === undefined) {\n const wanted = resource.provider ?? typeProvider(resource.type);\n error(\"provider-none\", at, `The resource \"${at}\" uses the provider configuration \"${wanted}\", which the layer does not have.`, more);\n }\n if (resource.cost !== undefined && !isZeroOrMore(resource.cost)) {\n error(\"cost-amount\", at, `The planned cost ${String(resource.cost)} of the resource \"${at}\" is less than 0 or not finite.`, more);\n } else if (builtin) {\n if (resource.cost !== undefined && resource.cost > 0) {\n error(\"cost-builtin\", at, `The resource \"${at}\" is a part of OpenTofu, and its record has a planned cost of ${money(resource.cost)}. It counts against no account.`, more);\n }\n } else if (resource.cost === undefined) {\n error(\"cost-none\", at, `The resource \"${at}\" has no planned cost. A cost that is not known is not 0: give the cost of a month, or 0 for a resource with no price.`, more);\n }\n if (provider !== undefined && provider.part !== resource.part && parts.has(resource.part) && parts.has(provider.part) && !neededParts(stack, resource.part).has(provider.part)) {\n add(\n \"warning\",\n \"provider-need\",\n at,\n `The resource \"${at}\" makes the part \"${resource.part}\" with the provider configuration of \"${provider.part}\", and \"${resource.part}\" does not need \"${provider.part}\" in the stack.`,\n { ...more, other: provider.part },\n );\n }\n }\n faults.push(...groupFaults(layer));\n\n for (const cycle of resourceCycles(layer, stack)) {\n const [first = \"\", second] = cycle;\n const message = cycle.length === 1 ? `The resource \"${first}\" reads its own attribute, so OpenTofu cannot make it.` : `The resources ${names(cycle)} wait for each other, so OpenTofu can make none of them.`;\n error(\"cycle\", first, message, second === undefined ? {} : { other: second });\n }\n\n const budgets = options.budgets ?? [];\n const budgetParts = new Set<string>();\n const wrongBudgets = new Set<string>();\n for (const budget of budgets) {\n if (budgetParts.has(budget.part)) {\n error(\"budget-duplicate\", budget.part, `Two budgets name the part \"${budget.part}\".`, { part: budget.part });\n continue;\n }\n budgetParts.add(budget.part);\n if (budget.hardLimit !== undefined && !isZeroOrMore(budget.hardLimit)) {\n wrongBudgets.add(budget.part);\n error(\"budget-amount\", budget.part, `The hard limit ${String(budget.hardLimit)} of the budget of \"${budget.part}\" is less than 0 or not finite.`, { part: budget.part });\n }\n }\n for (const state of accountStates(layer, budgets)) {\n const at = state.part;\n const more = { part: at };\n if (!budgetParts.has(at)) {\n error(\"budget-none\", at, `The resources ${names(state.resources)} count against \"${at}\", and no budget names \"${at}\". The gate has no read of its limit.`, more);\n } else if (state.limit === undefined) {\n // A hard limit with a wrong amount has its own fault.\n if (state.planned > 0 && !wrongBudgets.has(at)) error(\"limit-none\", at, `The planned cost of the resources of \"${at}\" is ${money(state.planned)} for a month, and \"${at}\" has no hard limit.`, more);\n } else if (state.over === true) {\n error(\"cost-over\", at, `The planned cost of the resources of \"${at}\" is ${money(state.planned)} for a month. Its hard limit is ${money(state.limit)}.`, more);\n }\n }\n\n for (const name of variables) {\n if (!readVariables.has(name)) add(\"warning\", \"variable-unused\", `var.${name}`, `No value reads the variable \"${name}\".`);\n }\n return faults;\n}\n","import { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { copyName, providerAddress, resourceAddress, TOFU_SCHEMA, type TofuLayer } from \"./layer.ts\";\n\n// The join of the OpenTofu layers of the fragments of a stack, for example one file of resources for each owner.\n\n/**\n * This function joins the OpenTofu layers of the fragments of a stack into one layer.\n *\n * - The resources, the provider configurations and the variables are in the order of the fragments.\n * - A resource address in two or more fragments is a fault, also when the resources are equal.\n * - The same rule holds for the address of a provider configuration, the name of a variable, of a group and of a copy.\n * - The layer has one version of OpenTofu. A fragment with a different value is a fault.\n * - The state has one place. Thus a backend in two or more fragments is a fault, also when the backends are equal.\n *\n * A resource of one fragment can use a provider configuration or a variable of a different fragment.\n * A copy of one fragment can name a group of a different fragment.\n * The joined layer has the field `providers`, `variables`, `groups` or `copies` when a fragment has it. The function is pure, and it\n * changes no layer. The gate `checkTofu` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinTofu(pieces: readonly LayerPiece<TofuLayer>[]): LayerParse<TofuLayer> {\n const version = joinSetting(pieces, (layer) => layer.version, \"version of OpenTofu\");\n const backends = pieces.filter((piece) => piece.layer.backend !== undefined);\n const providers = joinRecords(pieces, (layer) => layer.providers, providerAddress, \"provider configuration\");\n const variables = joinRecords(\n pieces,\n (layer) => layer.variables,\n (variable) => variable.name,\n \"variable\",\n );\n const resources = joinRecords(pieces, (layer) => layer.resources, resourceAddress, \"resource\");\n const groups = joinRecords(\n pieces,\n (layer) => layer.groups,\n (group) => group.name,\n \"group\",\n );\n const copies = joinRecords(pieces, (layer) => layer.copies, copyName, \"copy\");\n const errors = [...version.errors];\n if (backends.length > 1) errors.push(`The fragments ${backends.map((piece) => `\"${piece.from}\"`).join(\", \")} each have a backend. The state has one place.`);\n errors.push(...providers.errors, ...variables.errors, ...resources.errors, ...groups.errors, ...copies.errors);\n if (errors.length > 0) return { ok: false, errors };\n const backend = backends[0]?.layer.backend;\n return {\n ok: true,\n layer: {\n schema: TOFU_SCHEMA,\n ...(version.value === undefined ? {} : { version: version.value }),\n ...(backend === undefined ? {} : { backend }),\n ...(pieces.some((piece) => piece.layer.providers !== undefined) ? { providers: providers.items } : {}),\n ...(pieces.some((piece) => piece.layer.variables !== undefined) ? { variables: variables.items } : {}),\n resources: resources.items,\n ...(pieces.some((piece) => piece.layer.groups !== undefined) ? { groups: groups.items } : {}),\n ...(pieces.some((piece) => piece.layer.copies !== undefined) ? { copies: copies.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;;;AAMA,MAAa,YAAoB;;AAGjC,MAAa,gBAAwB;;AAGrC,MAAa,YAAoB;;;;;AAMjC,MAAa,YAAoB;;AAGjC,MAAa,cAAsB;;AAGnC,MAAa,eAAuB;;;;;AAYpC,SAAgB,SAAS,KAAmC;CAC1D,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,IAAI,MAAM,GAAG;CAC3C,IAAI,SAAS,KAAA,KAAa,SAAS,KAAA,KAAa,KAAK,WAAW,GAAG,OAAO,KAAA;CAE1E,MAAM,YAAY,KAAK,KAAK,GAAG;CAC/B,IAAI,CAAC,UAAU,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS,GAAG,OAAO,KAAA;CACzF,OAAO;EAAE,SAAS,GAAG,KAAK,GAAG;EAAQ;CAAU;A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CAC3J,OAAO,KAAK,GAAG,UAAU,QAAQ,GAAG,UAAU,QAAQ,GAAG,UAAU,QAAQ,GAAG,OAAO,QAAQ,GAAG,OAAO,MAAM;CAC7G,IAAI,OAAO,SAAS,GAAG,OAAO;EAAE,IAAI;EAAO;CAAO;CAClD,MAAM,UAAU,SAAS,EAAE,EAAE,MAAM;CACnC,OAAO;EACL,IAAI;EACJ,OAAO;GACL,QAAQ;GACR,GAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,MAAM;GAChE,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;GAC3C,GAAI,OAAO,MAAM,UAAU,MAAM,MAAM,cAAc,KAAA,CAAS,IAAI,EAAE,WAAW,UAAU,MAAM,IAAI,CAAC;GACpG,GAAI,OAAO,MAAM,UAAU,MAAM,MAAM,cAAc,KAAA,CAAS,IAAI,EAAE,WAAW,UAAU,MAAM,IAAI,CAAC;GACpG,WAAW,UAAU;GACrB,GAAI,OAAO,MAAM,UAAU,MAAM,MAAM,WAAW,KAAA,CAAS,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;GAC3F,GAAI,OAAO,MAAM,UAAU,MAAM,MAAM,WAAW,KAAA,CAAS,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;EAC7F;CACF;AACF"}
|
|
@@ -17,10 +17,17 @@ const BUILTIN_PROVIDER = "terraform";
|
|
|
17
17
|
* In a name from an `id`, `_` replaces each character that a name cannot have, and a name does not start with a digit.
|
|
18
18
|
*/
|
|
19
19
|
function resourceName(resource) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
return resource.name ?? partName(resource.part);
|
|
21
|
+
}
|
|
22
|
+
/** This function gives a name from the `id` of a part. `_` replaces each character that a name cannot have, and a name does not start with a digit. */
|
|
23
|
+
function partName(part) {
|
|
24
|
+
const name = part.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
22
25
|
return /^[A-Za-z_]/.test(name) ? name : `_${name}`;
|
|
23
26
|
}
|
|
27
|
+
/** This function gives the name of a copy: its field `name`, or a name from the `id` of its part. */
|
|
28
|
+
function copyName(copy) {
|
|
29
|
+
return copy.name ?? partName(copy.part);
|
|
30
|
+
}
|
|
24
31
|
/** This function gives the address of a resource in the files: its type, a point and its name. */
|
|
25
32
|
function resourceAddress(resource) {
|
|
26
33
|
return `${resource.type}.${resourceName(resource)}`;
|
|
@@ -46,6 +53,6 @@ function resourceProvider(layer, resource) {
|
|
|
46
53
|
const address = resource.provider ?? typeProvider(resource.type);
|
|
47
54
|
return (layer.providers ?? []).find((provider) => providerAddress(provider) === address);
|
|
48
55
|
}
|
|
49
|
-
export {
|
|
56
|
+
export { isBuiltin as a, resourceAddress as c, typeProvider as d, copyName as i, resourceName as l, TOFU_SCHEMA as n, partName as o, VARIABLE_TYPES as r, providerAddress as s, BUILTIN_PROVIDER as t, resourceProvider as u };
|
|
50
57
|
|
|
51
|
-
//# sourceMappingURL=layer-
|
|
58
|
+
//# sourceMappingURL=layer-CS1ZZFFP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-CS1ZZFFP.js","names":[],"sources":["../src/layer.ts"],"sourcesContent":["// The records of the OpenTofu add-on. They are one layer of a stack, with the key `tofu/1` in `Stack.layers`.\n// Each record tells how a part of the stack becomes a resource of OpenTofu.\n// The add-on knows no provider: the type of a resource and its arguments are data.\n\n/** The name of the format of an OpenTofu layer. It is the key of the layer in `Stack.layers`. */\nexport const TOFU_SCHEMA = \"tofu/1\";\n\n/**\n * A value of an argument, as JSON.\n *\n * - A text is literal. The generator escapes each template sequence, so a text of a record is not an expression.\n * - `{ \"$ref\": \"type.name.attribute\" }` is an attribute of a resource of the layer.\n * - `{ \"$var\": \"name\" }` is the value of a variable of the layer.\n *\n * A key that starts with `$` has no other use.\n */\nexport type TofuValue = string | number | boolean | null | readonly TofuValue[] | TofuObject;\n\n/** An object of values. Its keys are the names of arguments, or the keys of a map. */\nexport interface TofuObject {\n readonly [key: string]: TofuValue;\n}\n\n/**\n * A configuration of a provider. It acts for one part of the stack: an account, a project or a tenant.\n * The cost of each resource of the configuration counts against the limit of that part.\n */\nexport interface Provider {\n /** The local name of the provider, for example `example`. It is the first word of the types of its resources. */\n readonly name: string;\n /** The address of the provider in a registry, for example `example-org/example`. */\n readonly source: string;\n /** The versions of the provider that the files accept, for example `~> 2.0`. */\n readonly version?: string | undefined;\n /** The alias of the configuration. One provider can have one configuration with no alias, and others with an alias each. */\n readonly alias?: string | undefined;\n /** The `id` of the part of the stack that pays for the resources of the configuration. */\n readonly part: string;\n /** The arguments of the configuration. */\n readonly values?: TofuObject | undefined;\n}\n\n/** These are the types of a variable. */\nexport const VARIABLE_TYPES: readonly [\"string\", \"number\", \"bool\"] = [\"string\", \"number\", \"bool\"];\n\n/** A type of a variable. */\nexport type VariableType = (typeof VARIABLE_TYPES)[number];\n\n/**\n * A variable of the files. A person or a program gives its value when OpenTofu runs.\n * A secret is a variable, so no record holds its value. A variable has no default for that reason.\n */\nexport interface Variable {\n readonly name: string;\n /** The type of the variable. The default is `string`. */\n readonly type?: VariableType | undefined;\n /** `true`: OpenTofu does not show the value. */\n readonly sensitive?: boolean | undefined;\n readonly description?: string | undefined;\n}\n\n/** The place where OpenTofu keeps its state. Each value is literal: a backend reads no variable and no resource. */\nexport interface Backend {\n /** The type of the backend, for example `local`. */\n readonly type: string;\n readonly values?: TofuObject | undefined;\n}\n\n/** A resource of OpenTofu that makes a part of the stack, or a piece of it. */\nexport interface Resource {\n /** The `id` of the part of the stack that the resource makes. One part can have two resources or more. */\n readonly part: string;\n /** The type of the resource, for example `example_server`. */\n readonly type: string;\n /** The name of the resource in the files. The default comes from the `id` of the part. */\n readonly name?: string | undefined;\n /**\n * The provider configuration of the resource: a name, or a name, a point and an alias.\n * The default is the configuration with no alias whose name is the first word of the type.\n */\n readonly provider?: string | undefined;\n /** The arguments of the resource. A meta-argument is not an argument: the generator writes each one. */\n readonly values?: TofuObject | undefined;\n /**\n * The planned cost of the resource in a month, in the currency of the budgets.\n * It is the standing price of the resource. The cost that grows with the use is not in it.\n */\n readonly cost?: number | undefined;\n /** `true`: the resource holds data or a name that must stay. The files stop a plan that destroys it. */\n readonly keep?: boolean | undefined;\n /** The attributes whose changes outside the files are permitted, for example `labels`. */\n readonly ignore?: readonly string[] | undefined;\n /** The id of an object that exists at the provider. The files import the object as this resource. */\n readonly import?: string | undefined;\n}\n\n/** A parameter of a group. Each copy of the group gives its value. */\nexport interface GroupParam {\n readonly name: string;\n /** The value for a copy that does not give one. Without a default, each copy must give a value. */\n readonly default?: TofuValue | undefined;\n readonly description?: string | undefined;\n}\n\n/**\n * A resource of a group. It has no part, because each copy of the group gives the part.\n * Its name is local to the group: the name in the files is the name of the copy, `_` and this name.\n *\n * Its values can have the form `{ \"$param\": \"name\" }`: the value of a parameter, from the copy.\n * A reference to the local address of a resource of the group reads the resource of the same copy.\n * The resource has no import id, because one object at the provider cannot be the resource of each copy.\n */\nexport interface GroupResource {\n /** The local name of the resource in the group. */\n readonly name: string;\n readonly type: string;\n readonly provider?: string | undefined;\n readonly values?: TofuObject | undefined;\n readonly cost?: number | undefined;\n readonly keep?: boolean | undefined;\n readonly ignore?: readonly string[] | undefined;\n}\n\n/**\n * A group of resources as one record, for example the server, the disk and the address of a host.\n * Each copy of the group makes the resources of one part. Thus a new copy of a host is one record.\n */\nexport interface Group {\n readonly name: string;\n readonly params?: readonly GroupParam[] | undefined;\n readonly resources: readonly GroupResource[];\n}\n\n/** A copy of a group: the resources of the group for one part of the stack. */\nexport interface Copy {\n /** The `id` of the part of the stack that the resources of the copy make. */\n readonly part: string;\n /** The name of the group. */\n readonly group: string;\n /** The first word of the names of the resources of the copy. The default comes from the `id` of the part. */\n readonly name?: string | undefined;\n /** The value of each parameter of the group, by the name of the parameter. */\n readonly values?: TofuObject | undefined;\n /**\n * The provider configurations of the copy, for example `example.east`. Each one replaces the configuration of the same\n * provider name in each resource of the group. Thus a copy in a different region or account is one record.\n */\n readonly providers?: readonly string[] | undefined;\n}\n\n/** An OpenTofu layer: the resources of the parts of a stack, with their providers. */\nexport interface TofuLayer {\n readonly schema: typeof TOFU_SCHEMA;\n /** The versions of OpenTofu that the files accept, for example `>= 1.8`. */\n readonly version?: string | undefined;\n readonly backend?: Backend | undefined;\n readonly providers?: readonly Provider[] | undefined;\n readonly variables?: readonly Variable[] | undefined;\n readonly resources: readonly Resource[];\n /** The groups of resources. A group makes no resource until a copy names it. */\n readonly groups?: readonly Group[] | undefined;\n /** The copies of the groups. `layerResources` gives their resources after the resources of the field `resources`. */\n readonly copies?: readonly Copy[] | undefined;\n}\n\n/**\n * The first word of the types of the resources that are a part of OpenTofu, for example `terraform_data`.\n * Such a resource has no provider configuration, no account and no cost.\n */\nexport const BUILTIN_PROVIDER = \"terraform\";\n\n/**\n * This function gives the name of a resource in the files: its field `name`, or a name from the `id` of its part.\n * In a name from an `id`, `_` replaces each character that a name cannot have, and a name does not start with a digit.\n */\nexport function resourceName(resource: Resource): string {\n return resource.name ?? partName(resource.part);\n}\n\n/** This function gives a name from the `id` of a part. `_` replaces each character that a name cannot have, and a name does not start with a digit. */\nexport function partName(part: string): string {\n const name = part.replace(/[^A-Za-z0-9_-]/g, \"_\");\n return /^[A-Za-z_]/.test(name) ? name : `_${name}`;\n}\n\n/** This function gives the name of a copy: its field `name`, or a name from the `id` of its part. */\nexport function copyName(copy: Copy): string {\n return copy.name ?? partName(copy.part);\n}\n\n/** This function gives the address of a resource in the files: its type, a point and its name. */\nexport function resourceAddress(resource: Resource): string {\n return `${resource.type}.${resourceName(resource)}`;\n}\n\n/** This function gives the address of a provider configuration: its name, or its name, a point and its alias. */\nexport function providerAddress(provider: Provider): string {\n return provider.alias === undefined ? provider.name : `${provider.name}.${provider.alias}`;\n}\n\n/** This function gives the first word of a type: the local name of the provider of the type. */\nexport function typeProvider(type: string): string {\n const end = type.indexOf(\"_\");\n return end === -1 ? type : type.slice(0, end);\n}\n\n/** This function tells if a resource is a part of OpenTofu, with no provider configuration. */\nexport function isBuiltin(resource: Resource): boolean {\n return resource.provider === undefined && typeProvider(resource.type) === BUILTIN_PROVIDER;\n}\n\n/**\n * This function gives the provider configuration of a resource, or `undefined` when the layer has none for it.\n * For two configurations with one address, it gives the first one.\n */\nexport function resourceProvider(layer: TofuLayer, resource: Resource): Provider | undefined {\n const address = resource.provider ?? typeProvider(resource.type);\n return (layer.providers ?? []).find((provider) => providerAddress(provider) === address);\n}\n"],"mappings":";;AAKA,MAAa,cAAc;;AAsC3B,MAAa,iBAAwD;CAAC;CAAU;CAAU;AAAM;;;;;AA8HhG,MAAa,mBAAmB;;;;;AAMhC,SAAgB,aAAa,UAA4B;CACvD,OAAO,SAAS,QAAQ,SAAS,SAAS,IAAI;AAChD;;AAGA,SAAgB,SAAS,MAAsB;CAC7C,MAAM,OAAO,KAAK,QAAQ,mBAAmB,GAAG;CAChD,OAAO,aAAa,KAAK,IAAI,IAAI,OAAO,IAAI;AAC9C;;AAGA,SAAgB,SAAS,MAAoB;CAC3C,OAAO,KAAK,QAAQ,SAAS,KAAK,IAAI;AACxC;;AAGA,SAAgB,gBAAgB,UAA4B;CAC1D,OAAO,GAAG,SAAS,KAAK,GAAG,aAAa,QAAQ;AAClD;;AAGA,SAAgB,gBAAgB,UAA4B;CAC1D,OAAO,SAAS,UAAU,KAAA,IAAY,SAAS,OAAO,GAAG,SAAS,KAAK,GAAG,SAAS;AACrF;;AAGA,SAAgB,aAAa,MAAsB;CACjD,MAAM,MAAM,KAAK,QAAQ,GAAG;CAC5B,OAAO,QAAQ,KAAK,OAAO,KAAK,MAAM,GAAG,GAAG;AAC9C;;AAGA,SAAgB,UAAU,UAA6B;CACrD,OAAO,SAAS,aAAa,KAAA,KAAa,aAAa,SAAS,IAAI,MAAA;AACtE;;;;;AAMA,SAAgB,iBAAiB,OAAkB,UAA0C;CAC3F,MAAM,UAAU,SAAS,YAAY,aAAa,SAAS,IAAI;CAC/D,QAAQ,MAAM,aAAa,CAAC,EAAA,CAAG,MAAM,aAAa,gBAAgB,QAAQ,MAAM,OAAO;AACzF"}
|