@terraforge/terraform 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +309 -0
- package/dist/index.mjs +2372 -0
- package/package.json +7 -7
- package/dist/index.d.ts +0 -97
- package/dist/index.js +0 -1996
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2372 @@
|
|
|
1
|
+
import { camelCase, pascalCase, snakeCase } from "change-case";
|
|
2
|
+
import { ResourceNotFound, createDebugger, createMeta, nodeMetaSymbol } from "@terraforge/core";
|
|
3
|
+
import { credentials, loadPackageDefinition } from "@grpc/grpc-js";
|
|
4
|
+
import { fromJSON } from "@grpc/proto-loader";
|
|
5
|
+
import jszip from "jszip";
|
|
6
|
+
import { mkdir, rm, stat, writeFile } from "node:fs/promises";
|
|
7
|
+
import { arch, homedir, platform } from "node:os";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { compare } from "semver";
|
|
10
|
+
import { spawn } from "node:child_process";
|
|
11
|
+
import { pack, unpack } from "msgpackr";
|
|
12
|
+
|
|
13
|
+
//#region src/type-gen.ts
|
|
14
|
+
const tab = (indent) => {
|
|
15
|
+
return " ".repeat(indent);
|
|
16
|
+
};
|
|
17
|
+
const generateTypes = (namespace, provider, resources, dataSources) => {
|
|
18
|
+
return [
|
|
19
|
+
generateImport("c", "@terraforge/core"),
|
|
20
|
+
generateImport("t", "@terraforge/terraform"),
|
|
21
|
+
"type _Record<T> = Record<string, T>",
|
|
22
|
+
generateInstallHelperFunctions(namespace),
|
|
23
|
+
generateProviderFactoryTypes(namespace, provider),
|
|
24
|
+
generateResourceTypes(resources),
|
|
25
|
+
generateDataSourceTypes(dataSources)
|
|
26
|
+
].join("\n\n");
|
|
27
|
+
};
|
|
28
|
+
const generateResourceTypes = (resources) => {
|
|
29
|
+
return generateNamespace(resources, (name, prop, indent) => {
|
|
30
|
+
const typeName = pascalCase(name);
|
|
31
|
+
return [
|
|
32
|
+
`${tab(indent)}export type ${typeName}Input = ${generatePropertyInputType(prop, indent)}`,
|
|
33
|
+
`${tab(indent)}export type ${typeName}Output = ${generatePropertyOutputType(prop, indent)}`,
|
|
34
|
+
`${tab(indent)}export class ${typeName} {`,
|
|
35
|
+
`${tab(indent + 1)}constructor(parent: c.Group, id: string, props: ${typeName}Input, config?:c.ResourceConfig)`,
|
|
36
|
+
`${tab(indent + 2)}readonly [c.nodeMetaSymbol]: c.ResourceMeta`,
|
|
37
|
+
`${tab(indent + 2)}readonly urn: c.URN`,
|
|
38
|
+
generateClassProperties(prop, indent + 1),
|
|
39
|
+
`${tab(indent)}}`
|
|
40
|
+
].join("\n\n");
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const generateDataSourceTypes = (dataSources) => {
|
|
44
|
+
return generateNamespace(dataSources, (name, prop, indent) => {
|
|
45
|
+
const typeName = pascalCase(name);
|
|
46
|
+
return [
|
|
47
|
+
`${tab(indent)}export type Get${typeName}Input = ${generatePropertyInputType(prop, indent)}`,
|
|
48
|
+
`${tab(indent)}export type Get${typeName}Output = ${generatePropertyOutputType(prop, indent)}`,
|
|
49
|
+
`${tab(indent)}export const get${typeName}:c.DataSourceFunction<Get${typeName}Input, Get${typeName}Output>`
|
|
50
|
+
].join("\n\n");
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const generateProviderFactoryTypes = (namespace, provider) => {
|
|
54
|
+
return `export declare function ${namespace.toLowerCase()}(props: ${generatePropertyInputConst(provider, 0)}, config?: t.TerraformProviderConfig): t.TerraformProvider`;
|
|
55
|
+
};
|
|
56
|
+
const generateImport = (name, from) => {
|
|
57
|
+
return `import * as ${name} from '${from}'`;
|
|
58
|
+
};
|
|
59
|
+
const generateInstallHelperFunctions = (namespace) => {
|
|
60
|
+
return [
|
|
61
|
+
`export declare namespace ${namespace.toLowerCase()} {`,
|
|
62
|
+
`${tab(1)}export function install(props?: t.InstallProps): Promise<void>`,
|
|
63
|
+
`${tab(1)}export function uninstall(props?: t.InstallProps): Promise<void>`,
|
|
64
|
+
`${tab(1)}export function isInstalled(props?: t.InstallProps): Promise<boolean>`,
|
|
65
|
+
`}`
|
|
66
|
+
].join("\n");
|
|
67
|
+
};
|
|
68
|
+
const generatePropertyInputConst = (prop, indent) => {
|
|
69
|
+
return generateValue(prop, {
|
|
70
|
+
depth: 0,
|
|
71
|
+
indent: indent + 1,
|
|
72
|
+
wrap: (v, _, ctx) => {
|
|
73
|
+
return `${v}${ctx.depth === 1 ? "," : ""}`;
|
|
74
|
+
},
|
|
75
|
+
filter: () => true,
|
|
76
|
+
optional: (p) => p.optional ?? false
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const generatePropertyInputType = (prop, indent) => {
|
|
80
|
+
return generateValue(prop, {
|
|
81
|
+
depth: 0,
|
|
82
|
+
indent: indent + 1,
|
|
83
|
+
wrap: (v, p, ctx) => {
|
|
84
|
+
return ctx.depth > 0 ? p.optional ? `c.OptionalInput<${v}>` : `c.Input<${v}>` : v;
|
|
85
|
+
},
|
|
86
|
+
filter: (prop$1) => !(prop$1.computed && typeof prop$1.optional === "undefined" && typeof prop$1.required === "undefined"),
|
|
87
|
+
optional: (p) => p.optional ?? false
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
const generatePropertyOutputType = (prop, indent) => {
|
|
91
|
+
return generateValue(prop, {
|
|
92
|
+
depth: 0,
|
|
93
|
+
indent: indent + 1,
|
|
94
|
+
wrap: (v, p, ctx) => ctx.depth === 1 ? p.optional && !p.computed ? `c.OptionalOutput<${v}>` : `c.Output<${v}>` : v,
|
|
95
|
+
filter: () => true,
|
|
96
|
+
readonly: true,
|
|
97
|
+
optional: (p, ctx) => ctx.depth > 1 && p.optional && !p.computed || false
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const generateClassProperties = (prop, indent) => {
|
|
101
|
+
if (prop.type !== "object") return "";
|
|
102
|
+
return Object.entries(prop.properties).map(([name, prop$1]) => {
|
|
103
|
+
return [
|
|
104
|
+
prop$1.description ? [
|
|
105
|
+
`\n`,
|
|
106
|
+
`\t`.repeat(indent),
|
|
107
|
+
`/** `,
|
|
108
|
+
prop$1.description.trim(),
|
|
109
|
+
" */",
|
|
110
|
+
"\n"
|
|
111
|
+
].join("") : "",
|
|
112
|
+
`\t`.repeat(indent),
|
|
113
|
+
"readonly ",
|
|
114
|
+
camelCase(name),
|
|
115
|
+
": ",
|
|
116
|
+
generateValue(prop$1, {
|
|
117
|
+
readonly: true,
|
|
118
|
+
filter: () => true,
|
|
119
|
+
optional: (p, ctx) => ctx.depth > 1 && p.optional && !p.computed || false,
|
|
120
|
+
wrap: (v, p, ctx) => {
|
|
121
|
+
return ctx.depth === 1 ? p.optional && !p.computed ? `c.OptionalOutput<${v}>` : `c.Output<${v}>` : v;
|
|
122
|
+
},
|
|
123
|
+
indent: indent + 1,
|
|
124
|
+
depth: 1
|
|
125
|
+
})
|
|
126
|
+
].join("");
|
|
127
|
+
}).join("\n");
|
|
128
|
+
};
|
|
129
|
+
const groupByNamespace = (resources, minLevel, maxLevel) => {
|
|
130
|
+
const grouped = {};
|
|
131
|
+
const types = Object.keys(resources).sort();
|
|
132
|
+
for (const type of types) {
|
|
133
|
+
const names = type.split("_");
|
|
134
|
+
if (names.length < minLevel) throw new Error(`Resource not properly namespaced: ${type}`);
|
|
135
|
+
let current = grouped;
|
|
136
|
+
let count = Math.min(maxLevel, names.length - 1);
|
|
137
|
+
while (count--) {
|
|
138
|
+
const ns = camelCase(names.shift());
|
|
139
|
+
if (!current[ns]) current[ns] = {};
|
|
140
|
+
current = current[ns];
|
|
141
|
+
}
|
|
142
|
+
const name = pascalCase(names.join("_"));
|
|
143
|
+
current[name] = type;
|
|
144
|
+
}
|
|
145
|
+
return grouped;
|
|
146
|
+
};
|
|
147
|
+
const generateNamespace = (resources, render) => {
|
|
148
|
+
const grouped = groupByNamespace(resources, 1, 2);
|
|
149
|
+
const renderNamespace = (name, group, indent) => {
|
|
150
|
+
if (name === "default") name = "$default";
|
|
151
|
+
if (typeof group === "string") return render(name, resources[group], indent);
|
|
152
|
+
return [
|
|
153
|
+
`${tab(indent)}export ${indent === 0 ? "declare " : ""}namespace ${name.toLowerCase()} {`,
|
|
154
|
+
Object.entries(group).map(([name$1, entry]) => {
|
|
155
|
+
if (typeof entry !== "string") return renderNamespace(name$1, entry, indent + 1);
|
|
156
|
+
else return render(name$1, resources[entry], indent + 1);
|
|
157
|
+
}).join("\n"),
|
|
158
|
+
`${tab(indent)}}`
|
|
159
|
+
].join("\n");
|
|
160
|
+
};
|
|
161
|
+
return Object.entries(grouped).map(([name, entry]) => {
|
|
162
|
+
return renderNamespace(name, entry, 0);
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const generateValue = (prop, ctx) => {
|
|
166
|
+
if ([
|
|
167
|
+
"string",
|
|
168
|
+
"number",
|
|
169
|
+
"boolean",
|
|
170
|
+
"unknown"
|
|
171
|
+
].includes(prop.type)) return ctx.wrap(prop.type, prop, ctx);
|
|
172
|
+
if (prop.type === "array") {
|
|
173
|
+
const type = generateValue(prop.item, {
|
|
174
|
+
...ctx,
|
|
175
|
+
depth: ctx.depth + 1
|
|
176
|
+
});
|
|
177
|
+
const array = ctx.readonly ? `ReadonlyArray<${type}>` : `Array<${type}>`;
|
|
178
|
+
return ctx.wrap(array, prop, ctx);
|
|
179
|
+
}
|
|
180
|
+
if (prop.type === "record") {
|
|
181
|
+
const type = generateValue(prop.item, {
|
|
182
|
+
...ctx,
|
|
183
|
+
depth: ctx.depth + 1
|
|
184
|
+
});
|
|
185
|
+
const record = ctx.readonly ? `Readonly<_Record<${type}>>` : `_Record<${type}>`;
|
|
186
|
+
return ctx.wrap(record, prop, ctx);
|
|
187
|
+
}
|
|
188
|
+
if (prop.type === "object" || prop.type === "array-object") {
|
|
189
|
+
const type = [
|
|
190
|
+
"{",
|
|
191
|
+
Object.entries(prop.properties).filter(([_, p]) => ctx.filter(p)).map(([name, prop$1]) => [
|
|
192
|
+
prop$1.description ? [
|
|
193
|
+
`\n`,
|
|
194
|
+
`\t`.repeat(ctx.indent),
|
|
195
|
+
`/** `,
|
|
196
|
+
prop$1.description.trim(),
|
|
197
|
+
" */",
|
|
198
|
+
"\n"
|
|
199
|
+
].join("") : "",
|
|
200
|
+
`\t`.repeat(ctx.indent),
|
|
201
|
+
camelCase(name),
|
|
202
|
+
ctx.optional(prop$1, ctx) ? "?" : "",
|
|
203
|
+
": ",
|
|
204
|
+
generateValue(prop$1, {
|
|
205
|
+
...ctx,
|
|
206
|
+
indent: ctx.indent + 1,
|
|
207
|
+
depth: ctx.depth + 1
|
|
208
|
+
})
|
|
209
|
+
].join("")).join("\n"),
|
|
210
|
+
`${`\t`.repeat(ctx.indent - 1)}}`
|
|
211
|
+
].join("\n");
|
|
212
|
+
const object = ctx.readonly ? `Readonly<${type}>` : type;
|
|
213
|
+
return ctx.wrap(object, prop, ctx);
|
|
214
|
+
}
|
|
215
|
+
throw new Error(`Unknown property type: ${prop.type}`);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/provider.ts
|
|
220
|
+
var TerraformProvider = class {
|
|
221
|
+
configured;
|
|
222
|
+
plugin;
|
|
223
|
+
constructor(type, id, createPlugin, config) {
|
|
224
|
+
this.type = type;
|
|
225
|
+
this.id = id;
|
|
226
|
+
this.createPlugin = createPlugin;
|
|
227
|
+
this.config = config;
|
|
228
|
+
}
|
|
229
|
+
async configure() {
|
|
230
|
+
const plugin = await this.prepare();
|
|
231
|
+
if (!this.configured) this.configured = plugin.configure(this.config);
|
|
232
|
+
await this.configured;
|
|
233
|
+
return plugin;
|
|
234
|
+
}
|
|
235
|
+
prepare() {
|
|
236
|
+
if (!this.plugin) this.plugin = this.createPlugin();
|
|
237
|
+
return this.plugin;
|
|
238
|
+
}
|
|
239
|
+
async destroy() {
|
|
240
|
+
if (this.plugin) {
|
|
241
|
+
(await this.plugin).stop();
|
|
242
|
+
this.plugin = void 0;
|
|
243
|
+
this.configured = void 0;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
ownResource(id) {
|
|
247
|
+
return `terraform:${this.type}:${this.id}` === id;
|
|
248
|
+
}
|
|
249
|
+
async getResource({ type, state }) {
|
|
250
|
+
const newState = await (await this.configure()).readResource(type, state);
|
|
251
|
+
if (!newState) throw new ResourceNotFound();
|
|
252
|
+
return {
|
|
253
|
+
version: 0,
|
|
254
|
+
state: newState
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
async createResource({ type, state }) {
|
|
258
|
+
return {
|
|
259
|
+
version: 0,
|
|
260
|
+
state: await (await this.configure()).applyResourceChange(type, null, state)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
async updateResource({ type, priorState, proposedState }) {
|
|
264
|
+
const plugin = await this.configure();
|
|
265
|
+
const { requiresReplace } = await plugin.planResourceChange(type, priorState, proposedState);
|
|
266
|
+
if (requiresReplace.length > 0) {
|
|
267
|
+
const formattedAttrs = requiresReplace.map((p) => p.join(".")).join("\", \"");
|
|
268
|
+
throw new Error(`Updating the "${formattedAttrs}" properties for the "${type}" resource will require the resource to be replaced.`);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
version: 0,
|
|
272
|
+
state: await plugin.applyResourceChange(type, priorState, proposedState)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async deleteResource({ type, state }) {
|
|
276
|
+
const plugin = await this.configure();
|
|
277
|
+
try {
|
|
278
|
+
await plugin.applyResourceChange(type, state, null);
|
|
279
|
+
} catch (error) {
|
|
280
|
+
try {
|
|
281
|
+
if (!await plugin.readResource(type, state)) throw new ResourceNotFound();
|
|
282
|
+
} catch (_) {}
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async planResourceChange({ type, priorState, proposedState }) {
|
|
287
|
+
const result = await (await this.configure()).planResourceChange(type, priorState, proposedState);
|
|
288
|
+
return {
|
|
289
|
+
version: 0,
|
|
290
|
+
requiresReplacement: result.requiresReplace.length > 0,
|
|
291
|
+
state: result.plannedState
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
async getData({ type, state }) {
|
|
295
|
+
const data = await (await this.configure()).readDataSource(type, state);
|
|
296
|
+
if (!data) throw new Error(`Data source not found ${type}`);
|
|
297
|
+
return { state: data };
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/plugin/diagnostic.ts
|
|
303
|
+
var DiagnosticsError = class extends Error {
|
|
304
|
+
constructor(diagnostics) {
|
|
305
|
+
super(formatDiagnosticErrorMessage(diagnostics));
|
|
306
|
+
this.diagnostics = diagnostics;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const formatDiagnosticErrorMessage = (diagnostics) => {
|
|
310
|
+
if (diagnostics.length === 0) return "Unknown diagnostic error";
|
|
311
|
+
const diagnostic = diagnostics[0];
|
|
312
|
+
if (diagnostic.detail) return `${diagnostic.summary}\n${diagnostic.detail}`;
|
|
313
|
+
return diagnostic.summary;
|
|
314
|
+
};
|
|
315
|
+
const throwDiagnosticError = (response) => {
|
|
316
|
+
return new DiagnosticsError(response.diagnostics.map((item) => ({
|
|
317
|
+
severity: item.severity === 1 ? "error" : "warning",
|
|
318
|
+
summary: item.summary,
|
|
319
|
+
detail: item.detail,
|
|
320
|
+
path: item.attribute?.steps.map((step) => step.attributeName)
|
|
321
|
+
})));
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/plugin/protocol/tfplugin5.ts
|
|
326
|
+
var tfplugin5_default = {
|
|
327
|
+
options: { syntax: "proto3" },
|
|
328
|
+
nested: { tfplugin5: { nested: {
|
|
329
|
+
DynamicValue: { fields: {
|
|
330
|
+
msgpack: {
|
|
331
|
+
type: "bytes",
|
|
332
|
+
id: 1
|
|
333
|
+
},
|
|
334
|
+
json: {
|
|
335
|
+
type: "bytes",
|
|
336
|
+
id: 2
|
|
337
|
+
}
|
|
338
|
+
} },
|
|
339
|
+
Diagnostic: {
|
|
340
|
+
fields: {
|
|
341
|
+
severity: {
|
|
342
|
+
type: "Severity",
|
|
343
|
+
id: 1
|
|
344
|
+
},
|
|
345
|
+
summary: {
|
|
346
|
+
type: "string",
|
|
347
|
+
id: 2
|
|
348
|
+
},
|
|
349
|
+
detail: {
|
|
350
|
+
type: "string",
|
|
351
|
+
id: 3
|
|
352
|
+
},
|
|
353
|
+
attribute: {
|
|
354
|
+
type: "AttributePath",
|
|
355
|
+
id: 4
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
nested: { Severity: { values: {
|
|
359
|
+
INVALID: 0,
|
|
360
|
+
ERROR: 1,
|
|
361
|
+
WARNING: 2
|
|
362
|
+
} } }
|
|
363
|
+
},
|
|
364
|
+
AttributePath: {
|
|
365
|
+
fields: { steps: {
|
|
366
|
+
rule: "repeated",
|
|
367
|
+
type: "Step",
|
|
368
|
+
id: 1
|
|
369
|
+
} },
|
|
370
|
+
nested: { Step: {
|
|
371
|
+
oneofs: { selector: { oneof: [
|
|
372
|
+
"attributeName",
|
|
373
|
+
"elementKeyString",
|
|
374
|
+
"elementKeyInt"
|
|
375
|
+
] } },
|
|
376
|
+
fields: {
|
|
377
|
+
attributeName: {
|
|
378
|
+
type: "string",
|
|
379
|
+
id: 1
|
|
380
|
+
},
|
|
381
|
+
elementKeyString: {
|
|
382
|
+
type: "string",
|
|
383
|
+
id: 2
|
|
384
|
+
},
|
|
385
|
+
elementKeyInt: {
|
|
386
|
+
type: "int64",
|
|
387
|
+
id: 3
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} }
|
|
391
|
+
},
|
|
392
|
+
Stop: {
|
|
393
|
+
fields: {},
|
|
394
|
+
nested: {
|
|
395
|
+
Request: { fields: {} },
|
|
396
|
+
Response: { fields: { Error: {
|
|
397
|
+
type: "string",
|
|
398
|
+
id: 1
|
|
399
|
+
} } }
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
RawState: { fields: {
|
|
403
|
+
json: {
|
|
404
|
+
type: "bytes",
|
|
405
|
+
id: 1
|
|
406
|
+
},
|
|
407
|
+
flatmap: {
|
|
408
|
+
keyType: "string",
|
|
409
|
+
type: "string",
|
|
410
|
+
id: 2
|
|
411
|
+
}
|
|
412
|
+
} },
|
|
413
|
+
Schema: {
|
|
414
|
+
fields: {
|
|
415
|
+
version: {
|
|
416
|
+
type: "int64",
|
|
417
|
+
id: 1
|
|
418
|
+
},
|
|
419
|
+
block: {
|
|
420
|
+
type: "Block",
|
|
421
|
+
id: 2
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
nested: {
|
|
425
|
+
Block: { fields: {
|
|
426
|
+
version: {
|
|
427
|
+
type: "int64",
|
|
428
|
+
id: 1
|
|
429
|
+
},
|
|
430
|
+
attributes: {
|
|
431
|
+
rule: "repeated",
|
|
432
|
+
type: "Attribute",
|
|
433
|
+
id: 2
|
|
434
|
+
},
|
|
435
|
+
blockTypes: {
|
|
436
|
+
rule: "repeated",
|
|
437
|
+
type: "NestedBlock",
|
|
438
|
+
id: 3
|
|
439
|
+
}
|
|
440
|
+
} },
|
|
441
|
+
Attribute: { fields: {
|
|
442
|
+
name: {
|
|
443
|
+
type: "string",
|
|
444
|
+
id: 1
|
|
445
|
+
},
|
|
446
|
+
type: {
|
|
447
|
+
type: "bytes",
|
|
448
|
+
id: 2
|
|
449
|
+
},
|
|
450
|
+
description: {
|
|
451
|
+
type: "string",
|
|
452
|
+
id: 3
|
|
453
|
+
},
|
|
454
|
+
required: {
|
|
455
|
+
type: "bool",
|
|
456
|
+
id: 4
|
|
457
|
+
},
|
|
458
|
+
optional: {
|
|
459
|
+
type: "bool",
|
|
460
|
+
id: 5
|
|
461
|
+
},
|
|
462
|
+
computed: {
|
|
463
|
+
type: "bool",
|
|
464
|
+
id: 6
|
|
465
|
+
},
|
|
466
|
+
sensitive: {
|
|
467
|
+
type: "bool",
|
|
468
|
+
id: 7
|
|
469
|
+
}
|
|
470
|
+
} },
|
|
471
|
+
NestedBlock: {
|
|
472
|
+
fields: {
|
|
473
|
+
typeName: {
|
|
474
|
+
type: "string",
|
|
475
|
+
id: 1
|
|
476
|
+
},
|
|
477
|
+
block: {
|
|
478
|
+
type: "Block",
|
|
479
|
+
id: 2
|
|
480
|
+
},
|
|
481
|
+
nesting: {
|
|
482
|
+
type: "NestingMode",
|
|
483
|
+
id: 3
|
|
484
|
+
},
|
|
485
|
+
minItems: {
|
|
486
|
+
type: "int64",
|
|
487
|
+
id: 4
|
|
488
|
+
},
|
|
489
|
+
maxItems: {
|
|
490
|
+
type: "int64",
|
|
491
|
+
id: 5
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
nested: { NestingMode: { values: {
|
|
495
|
+
INVALID: 0,
|
|
496
|
+
SINGLE: 1,
|
|
497
|
+
LIST: 2,
|
|
498
|
+
SET: 3,
|
|
499
|
+
MAP: 4,
|
|
500
|
+
GROUP: 5
|
|
501
|
+
} } }
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
Provider: { methods: {
|
|
506
|
+
GetSchema: {
|
|
507
|
+
requestType: "GetProviderSchema.Request",
|
|
508
|
+
responseType: "GetProviderSchema.Response"
|
|
509
|
+
},
|
|
510
|
+
PrepareProviderConfig: {
|
|
511
|
+
requestType: "PrepareProviderConfig.Request",
|
|
512
|
+
responseType: "PrepareProviderConfig.Response"
|
|
513
|
+
},
|
|
514
|
+
ValidateResourceTypeConfig: {
|
|
515
|
+
requestType: "ValidateResourceTypeConfig.Request",
|
|
516
|
+
responseType: "ValidateResourceTypeConfig.Response"
|
|
517
|
+
},
|
|
518
|
+
ValidateDataSourceConfig: {
|
|
519
|
+
requestType: "ValidateDataSourceConfig.Request",
|
|
520
|
+
responseType: "ValidateDataSourceConfig.Response"
|
|
521
|
+
},
|
|
522
|
+
UpgradeResourceState: {
|
|
523
|
+
requestType: "UpgradeResourceState.Request",
|
|
524
|
+
responseType: "UpgradeResourceState.Response"
|
|
525
|
+
},
|
|
526
|
+
Configure: {
|
|
527
|
+
requestType: "Configure.Request",
|
|
528
|
+
responseType: "Configure.Response"
|
|
529
|
+
},
|
|
530
|
+
ReadResource: {
|
|
531
|
+
requestType: "ReadResource.Request",
|
|
532
|
+
responseType: "ReadResource.Response"
|
|
533
|
+
},
|
|
534
|
+
PlanResourceChange: {
|
|
535
|
+
requestType: "PlanResourceChange.Request",
|
|
536
|
+
responseType: "PlanResourceChange.Response"
|
|
537
|
+
},
|
|
538
|
+
ApplyResourceChange: {
|
|
539
|
+
requestType: "ApplyResourceChange.Request",
|
|
540
|
+
responseType: "ApplyResourceChange.Response"
|
|
541
|
+
},
|
|
542
|
+
ImportResourceState: {
|
|
543
|
+
requestType: "ImportResourceState.Request",
|
|
544
|
+
responseType: "ImportResourceState.Response"
|
|
545
|
+
},
|
|
546
|
+
ReadDataSource: {
|
|
547
|
+
requestType: "ReadDataSource.Request",
|
|
548
|
+
responseType: "ReadDataSource.Response"
|
|
549
|
+
},
|
|
550
|
+
Stop: {
|
|
551
|
+
requestType: "Stop.Request",
|
|
552
|
+
responseType: "Stop.Response"
|
|
553
|
+
}
|
|
554
|
+
} },
|
|
555
|
+
GetProviderSchema: {
|
|
556
|
+
fields: {},
|
|
557
|
+
nested: {
|
|
558
|
+
Request: { fields: {} },
|
|
559
|
+
Response: { fields: {
|
|
560
|
+
provider: {
|
|
561
|
+
type: "Schema",
|
|
562
|
+
id: 1
|
|
563
|
+
},
|
|
564
|
+
resourceSchemas: {
|
|
565
|
+
keyType: "string",
|
|
566
|
+
type: "Schema",
|
|
567
|
+
id: 2
|
|
568
|
+
},
|
|
569
|
+
dataSourceSchemas: {
|
|
570
|
+
keyType: "string",
|
|
571
|
+
type: "Schema",
|
|
572
|
+
id: 3
|
|
573
|
+
},
|
|
574
|
+
diagnostics: {
|
|
575
|
+
rule: "repeated",
|
|
576
|
+
type: "Diagnostic",
|
|
577
|
+
id: 4
|
|
578
|
+
}
|
|
579
|
+
} }
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
PrepareProviderConfig: {
|
|
583
|
+
fields: {},
|
|
584
|
+
nested: {
|
|
585
|
+
Request: { fields: { config: {
|
|
586
|
+
type: "DynamicValue",
|
|
587
|
+
id: 1
|
|
588
|
+
} } },
|
|
589
|
+
Response: { fields: {
|
|
590
|
+
preparedConfig: {
|
|
591
|
+
type: "DynamicValue",
|
|
592
|
+
id: 1
|
|
593
|
+
},
|
|
594
|
+
diagnostics: {
|
|
595
|
+
rule: "repeated",
|
|
596
|
+
type: "Diagnostic",
|
|
597
|
+
id: 2
|
|
598
|
+
}
|
|
599
|
+
} }
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
UpgradeResourceState: {
|
|
603
|
+
fields: {},
|
|
604
|
+
nested: {
|
|
605
|
+
Request: { fields: {
|
|
606
|
+
typeName: {
|
|
607
|
+
type: "string",
|
|
608
|
+
id: 1
|
|
609
|
+
},
|
|
610
|
+
version: {
|
|
611
|
+
type: "int64",
|
|
612
|
+
id: 2
|
|
613
|
+
},
|
|
614
|
+
rawState: {
|
|
615
|
+
type: "RawState",
|
|
616
|
+
id: 3
|
|
617
|
+
}
|
|
618
|
+
} },
|
|
619
|
+
Response: { fields: {
|
|
620
|
+
upgradedState: {
|
|
621
|
+
type: "DynamicValue",
|
|
622
|
+
id: 1
|
|
623
|
+
},
|
|
624
|
+
diagnostics: {
|
|
625
|
+
rule: "repeated",
|
|
626
|
+
type: "Diagnostic",
|
|
627
|
+
id: 2
|
|
628
|
+
}
|
|
629
|
+
} }
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
ValidateResourceTypeConfig: {
|
|
633
|
+
fields: {},
|
|
634
|
+
nested: {
|
|
635
|
+
Request: { fields: {
|
|
636
|
+
typeName: {
|
|
637
|
+
type: "string",
|
|
638
|
+
id: 1
|
|
639
|
+
},
|
|
640
|
+
config: {
|
|
641
|
+
type: "DynamicValue",
|
|
642
|
+
id: 2
|
|
643
|
+
}
|
|
644
|
+
} },
|
|
645
|
+
Response: { fields: { diagnostics: {
|
|
646
|
+
rule: "repeated",
|
|
647
|
+
type: "Diagnostic",
|
|
648
|
+
id: 1
|
|
649
|
+
} } }
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
ValidateDataSourceConfig: {
|
|
653
|
+
fields: {},
|
|
654
|
+
nested: {
|
|
655
|
+
Request: { fields: {
|
|
656
|
+
typeName: {
|
|
657
|
+
type: "string",
|
|
658
|
+
id: 1
|
|
659
|
+
},
|
|
660
|
+
config: {
|
|
661
|
+
type: "DynamicValue",
|
|
662
|
+
id: 2
|
|
663
|
+
}
|
|
664
|
+
} },
|
|
665
|
+
Response: { fields: { diagnostics: {
|
|
666
|
+
rule: "repeated",
|
|
667
|
+
type: "Diagnostic",
|
|
668
|
+
id: 1
|
|
669
|
+
} } }
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
Configure: {
|
|
673
|
+
fields: {},
|
|
674
|
+
nested: {
|
|
675
|
+
Request: { fields: {
|
|
676
|
+
terraformVersion: {
|
|
677
|
+
type: "string",
|
|
678
|
+
id: 1
|
|
679
|
+
},
|
|
680
|
+
config: {
|
|
681
|
+
type: "DynamicValue",
|
|
682
|
+
id: 2
|
|
683
|
+
}
|
|
684
|
+
} },
|
|
685
|
+
Response: { fields: { diagnostics: {
|
|
686
|
+
rule: "repeated",
|
|
687
|
+
type: "Diagnostic",
|
|
688
|
+
id: 1
|
|
689
|
+
} } }
|
|
690
|
+
}
|
|
691
|
+
},
|
|
692
|
+
ReadResource: {
|
|
693
|
+
fields: {},
|
|
694
|
+
nested: {
|
|
695
|
+
Request: { fields: {
|
|
696
|
+
typeName: {
|
|
697
|
+
type: "string",
|
|
698
|
+
id: 1
|
|
699
|
+
},
|
|
700
|
+
currentState: {
|
|
701
|
+
type: "DynamicValue",
|
|
702
|
+
id: 2
|
|
703
|
+
},
|
|
704
|
+
private: {
|
|
705
|
+
type: "bytes",
|
|
706
|
+
id: 3
|
|
707
|
+
}
|
|
708
|
+
} },
|
|
709
|
+
Response: { fields: {
|
|
710
|
+
newState: {
|
|
711
|
+
type: "DynamicValue",
|
|
712
|
+
id: 1
|
|
713
|
+
},
|
|
714
|
+
diagnostics: {
|
|
715
|
+
rule: "repeated",
|
|
716
|
+
type: "Diagnostic",
|
|
717
|
+
id: 2
|
|
718
|
+
},
|
|
719
|
+
private: {
|
|
720
|
+
type: "bytes",
|
|
721
|
+
id: 3
|
|
722
|
+
}
|
|
723
|
+
} }
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
PlanResourceChange: {
|
|
727
|
+
fields: {},
|
|
728
|
+
nested: {
|
|
729
|
+
Request: { fields: {
|
|
730
|
+
typeName: {
|
|
731
|
+
type: "string",
|
|
732
|
+
id: 1
|
|
733
|
+
},
|
|
734
|
+
priorState: {
|
|
735
|
+
type: "DynamicValue",
|
|
736
|
+
id: 2
|
|
737
|
+
},
|
|
738
|
+
proposedNewState: {
|
|
739
|
+
type: "DynamicValue",
|
|
740
|
+
id: 3
|
|
741
|
+
},
|
|
742
|
+
config: {
|
|
743
|
+
type: "DynamicValue",
|
|
744
|
+
id: 4
|
|
745
|
+
},
|
|
746
|
+
priorPrivate: {
|
|
747
|
+
type: "bytes",
|
|
748
|
+
id: 5
|
|
749
|
+
}
|
|
750
|
+
} },
|
|
751
|
+
Response: { fields: {
|
|
752
|
+
plannedState: {
|
|
753
|
+
type: "DynamicValue",
|
|
754
|
+
id: 1
|
|
755
|
+
},
|
|
756
|
+
requiresReplace: {
|
|
757
|
+
rule: "repeated",
|
|
758
|
+
type: "AttributePath",
|
|
759
|
+
id: 2
|
|
760
|
+
},
|
|
761
|
+
plannedPrivate: {
|
|
762
|
+
type: "bytes",
|
|
763
|
+
id: 3
|
|
764
|
+
},
|
|
765
|
+
diagnostics: {
|
|
766
|
+
rule: "repeated",
|
|
767
|
+
type: "Diagnostic",
|
|
768
|
+
id: 4
|
|
769
|
+
},
|
|
770
|
+
legacyTypeSystem: {
|
|
771
|
+
type: "bool",
|
|
772
|
+
id: 5
|
|
773
|
+
}
|
|
774
|
+
} }
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
ApplyResourceChange: {
|
|
778
|
+
fields: {},
|
|
779
|
+
nested: {
|
|
780
|
+
Request: { fields: {
|
|
781
|
+
typeName: {
|
|
782
|
+
type: "string",
|
|
783
|
+
id: 1
|
|
784
|
+
},
|
|
785
|
+
priorState: {
|
|
786
|
+
type: "DynamicValue",
|
|
787
|
+
id: 2
|
|
788
|
+
},
|
|
789
|
+
plannedState: {
|
|
790
|
+
type: "DynamicValue",
|
|
791
|
+
id: 3
|
|
792
|
+
},
|
|
793
|
+
config: {
|
|
794
|
+
type: "DynamicValue",
|
|
795
|
+
id: 4
|
|
796
|
+
},
|
|
797
|
+
plannedPrivate: {
|
|
798
|
+
type: "bytes",
|
|
799
|
+
id: 5
|
|
800
|
+
}
|
|
801
|
+
} },
|
|
802
|
+
Response: { fields: {
|
|
803
|
+
newState: {
|
|
804
|
+
type: "DynamicValue",
|
|
805
|
+
id: 1
|
|
806
|
+
},
|
|
807
|
+
private: {
|
|
808
|
+
type: "bytes",
|
|
809
|
+
id: 2
|
|
810
|
+
},
|
|
811
|
+
diagnostics: {
|
|
812
|
+
rule: "repeated",
|
|
813
|
+
type: "Diagnostic",
|
|
814
|
+
id: 3
|
|
815
|
+
},
|
|
816
|
+
legacyTypeSystem: {
|
|
817
|
+
type: "bool",
|
|
818
|
+
id: 4
|
|
819
|
+
}
|
|
820
|
+
} }
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
ImportResourceState: {
|
|
824
|
+
fields: {},
|
|
825
|
+
nested: {
|
|
826
|
+
Request: { fields: {
|
|
827
|
+
typeName: {
|
|
828
|
+
type: "string",
|
|
829
|
+
id: 1
|
|
830
|
+
},
|
|
831
|
+
id: {
|
|
832
|
+
type: "string",
|
|
833
|
+
id: 2
|
|
834
|
+
}
|
|
835
|
+
} },
|
|
836
|
+
ImportedResource: { fields: {
|
|
837
|
+
typeName: {
|
|
838
|
+
type: "string",
|
|
839
|
+
id: 1
|
|
840
|
+
},
|
|
841
|
+
state: {
|
|
842
|
+
type: "DynamicValue",
|
|
843
|
+
id: 2
|
|
844
|
+
},
|
|
845
|
+
private: {
|
|
846
|
+
type: "bytes",
|
|
847
|
+
id: 3
|
|
848
|
+
}
|
|
849
|
+
} },
|
|
850
|
+
Response: { fields: {
|
|
851
|
+
importedResources: {
|
|
852
|
+
rule: "repeated",
|
|
853
|
+
type: "ImportedResource",
|
|
854
|
+
id: 1
|
|
855
|
+
},
|
|
856
|
+
diagnostics: {
|
|
857
|
+
rule: "repeated",
|
|
858
|
+
type: "Diagnostic",
|
|
859
|
+
id: 2
|
|
860
|
+
}
|
|
861
|
+
} }
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
ReadDataSource: {
|
|
865
|
+
fields: {},
|
|
866
|
+
nested: {
|
|
867
|
+
Request: { fields: {
|
|
868
|
+
typeName: {
|
|
869
|
+
type: "string",
|
|
870
|
+
id: 1
|
|
871
|
+
},
|
|
872
|
+
config: {
|
|
873
|
+
type: "DynamicValue",
|
|
874
|
+
id: 2
|
|
875
|
+
}
|
|
876
|
+
} },
|
|
877
|
+
Response: { fields: {
|
|
878
|
+
state: {
|
|
879
|
+
type: "DynamicValue",
|
|
880
|
+
id: 1
|
|
881
|
+
},
|
|
882
|
+
diagnostics: {
|
|
883
|
+
rule: "repeated",
|
|
884
|
+
type: "Diagnostic",
|
|
885
|
+
id: 2
|
|
886
|
+
}
|
|
887
|
+
} }
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
Provisioner: { methods: {
|
|
891
|
+
GetSchema: {
|
|
892
|
+
requestType: "GetProvisionerSchema.Request",
|
|
893
|
+
responseType: "GetProvisionerSchema.Response"
|
|
894
|
+
},
|
|
895
|
+
ValidateProvisionerConfig: {
|
|
896
|
+
requestType: "ValidateProvisionerConfig.Request",
|
|
897
|
+
responseType: "ValidateProvisionerConfig.Response"
|
|
898
|
+
},
|
|
899
|
+
ProvisionResource: {
|
|
900
|
+
requestType: "ProvisionResource.Request",
|
|
901
|
+
responseType: "ProvisionResource.Response",
|
|
902
|
+
responseStream: true
|
|
903
|
+
},
|
|
904
|
+
Stop: {
|
|
905
|
+
requestType: "Stop.Request",
|
|
906
|
+
responseType: "Stop.Response"
|
|
907
|
+
}
|
|
908
|
+
} },
|
|
909
|
+
GetProvisionerSchema: {
|
|
910
|
+
fields: {},
|
|
911
|
+
nested: {
|
|
912
|
+
Request: { fields: {} },
|
|
913
|
+
Response: { fields: {
|
|
914
|
+
provisioner: {
|
|
915
|
+
type: "Schema",
|
|
916
|
+
id: 1
|
|
917
|
+
},
|
|
918
|
+
diagnostics: {
|
|
919
|
+
rule: "repeated",
|
|
920
|
+
type: "Diagnostic",
|
|
921
|
+
id: 2
|
|
922
|
+
}
|
|
923
|
+
} }
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
ValidateProvisionerConfig: {
|
|
927
|
+
fields: {},
|
|
928
|
+
nested: {
|
|
929
|
+
Request: { fields: { config: {
|
|
930
|
+
type: "DynamicValue",
|
|
931
|
+
id: 1
|
|
932
|
+
} } },
|
|
933
|
+
Response: { fields: { diagnostics: {
|
|
934
|
+
rule: "repeated",
|
|
935
|
+
type: "Diagnostic",
|
|
936
|
+
id: 1
|
|
937
|
+
} } }
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
ProvisionResource: {
|
|
941
|
+
fields: {},
|
|
942
|
+
nested: {
|
|
943
|
+
Request: { fields: {
|
|
944
|
+
config: {
|
|
945
|
+
type: "DynamicValue",
|
|
946
|
+
id: 1
|
|
947
|
+
},
|
|
948
|
+
connection: {
|
|
949
|
+
type: "DynamicValue",
|
|
950
|
+
id: 2
|
|
951
|
+
}
|
|
952
|
+
} },
|
|
953
|
+
Response: { fields: {
|
|
954
|
+
output: {
|
|
955
|
+
type: "string",
|
|
956
|
+
id: 1
|
|
957
|
+
},
|
|
958
|
+
diagnostics: {
|
|
959
|
+
rule: "repeated",
|
|
960
|
+
type: "Diagnostic",
|
|
961
|
+
id: 2
|
|
962
|
+
}
|
|
963
|
+
} }
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
} } }
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
//#endregion
|
|
970
|
+
//#region src/plugin/protocol/tfplugin6.ts
|
|
971
|
+
var tfplugin6_default = {
|
|
972
|
+
options: {
|
|
973
|
+
syntax: "proto3",
|
|
974
|
+
go_package: "github.com/hashicorp/terraform/internal/tfplugin6"
|
|
975
|
+
},
|
|
976
|
+
nested: { tfplugin6: { nested: {
|
|
977
|
+
DynamicValue: { fields: {
|
|
978
|
+
msgpack: {
|
|
979
|
+
type: "bytes",
|
|
980
|
+
id: 1
|
|
981
|
+
},
|
|
982
|
+
json: {
|
|
983
|
+
type: "bytes",
|
|
984
|
+
id: 2
|
|
985
|
+
}
|
|
986
|
+
} },
|
|
987
|
+
Diagnostic: {
|
|
988
|
+
fields: {
|
|
989
|
+
severity: {
|
|
990
|
+
type: "Severity",
|
|
991
|
+
id: 1
|
|
992
|
+
},
|
|
993
|
+
summary: {
|
|
994
|
+
type: "string",
|
|
995
|
+
id: 2
|
|
996
|
+
},
|
|
997
|
+
detail: {
|
|
998
|
+
type: "string",
|
|
999
|
+
id: 3
|
|
1000
|
+
},
|
|
1001
|
+
attribute: {
|
|
1002
|
+
type: "AttributePath",
|
|
1003
|
+
id: 4
|
|
1004
|
+
}
|
|
1005
|
+
},
|
|
1006
|
+
nested: { Severity: { values: {
|
|
1007
|
+
INVALID: 0,
|
|
1008
|
+
ERROR: 1,
|
|
1009
|
+
WARNING: 2
|
|
1010
|
+
} } }
|
|
1011
|
+
},
|
|
1012
|
+
AttributePath: {
|
|
1013
|
+
fields: { steps: {
|
|
1014
|
+
rule: "repeated",
|
|
1015
|
+
type: "Step",
|
|
1016
|
+
id: 1
|
|
1017
|
+
} },
|
|
1018
|
+
nested: { Step: {
|
|
1019
|
+
oneofs: { selector: { oneof: [
|
|
1020
|
+
"attributeName",
|
|
1021
|
+
"elementKeyString",
|
|
1022
|
+
"elementKeyInt"
|
|
1023
|
+
] } },
|
|
1024
|
+
fields: {
|
|
1025
|
+
attributeName: {
|
|
1026
|
+
type: "string",
|
|
1027
|
+
id: 1
|
|
1028
|
+
},
|
|
1029
|
+
elementKeyString: {
|
|
1030
|
+
type: "string",
|
|
1031
|
+
id: 2
|
|
1032
|
+
},
|
|
1033
|
+
elementKeyInt: {
|
|
1034
|
+
type: "int64",
|
|
1035
|
+
id: 3
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
} }
|
|
1039
|
+
},
|
|
1040
|
+
StopProvider: {
|
|
1041
|
+
fields: {},
|
|
1042
|
+
nested: {
|
|
1043
|
+
Request: { fields: {} },
|
|
1044
|
+
Response: { fields: { Error: {
|
|
1045
|
+
type: "string",
|
|
1046
|
+
id: 1
|
|
1047
|
+
} } }
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1050
|
+
RawState: { fields: {
|
|
1051
|
+
json: {
|
|
1052
|
+
type: "bytes",
|
|
1053
|
+
id: 1
|
|
1054
|
+
},
|
|
1055
|
+
flatmap: {
|
|
1056
|
+
keyType: "string",
|
|
1057
|
+
type: "string",
|
|
1058
|
+
id: 2
|
|
1059
|
+
}
|
|
1060
|
+
} },
|
|
1061
|
+
StringKind: { values: {
|
|
1062
|
+
PLAIN: 0,
|
|
1063
|
+
MARKDOWN: 1
|
|
1064
|
+
} },
|
|
1065
|
+
Schema: {
|
|
1066
|
+
fields: {
|
|
1067
|
+
version: {
|
|
1068
|
+
type: "int64",
|
|
1069
|
+
id: 1
|
|
1070
|
+
},
|
|
1071
|
+
block: {
|
|
1072
|
+
type: "Block",
|
|
1073
|
+
id: 2
|
|
1074
|
+
}
|
|
1075
|
+
},
|
|
1076
|
+
nested: {
|
|
1077
|
+
Block: { fields: {
|
|
1078
|
+
version: {
|
|
1079
|
+
type: "int64",
|
|
1080
|
+
id: 1
|
|
1081
|
+
},
|
|
1082
|
+
attributes: {
|
|
1083
|
+
rule: "repeated",
|
|
1084
|
+
type: "Attribute",
|
|
1085
|
+
id: 2
|
|
1086
|
+
},
|
|
1087
|
+
blockTypes: {
|
|
1088
|
+
rule: "repeated",
|
|
1089
|
+
type: "NestedBlock",
|
|
1090
|
+
id: 3
|
|
1091
|
+
},
|
|
1092
|
+
description: {
|
|
1093
|
+
type: "string",
|
|
1094
|
+
id: 4
|
|
1095
|
+
},
|
|
1096
|
+
descriptionKind: {
|
|
1097
|
+
type: "StringKind",
|
|
1098
|
+
id: 5
|
|
1099
|
+
},
|
|
1100
|
+
deprecated: {
|
|
1101
|
+
type: "bool",
|
|
1102
|
+
id: 6
|
|
1103
|
+
}
|
|
1104
|
+
} },
|
|
1105
|
+
Attribute: { fields: {
|
|
1106
|
+
name: {
|
|
1107
|
+
type: "string",
|
|
1108
|
+
id: 1
|
|
1109
|
+
},
|
|
1110
|
+
type: {
|
|
1111
|
+
type: "bytes",
|
|
1112
|
+
id: 2
|
|
1113
|
+
},
|
|
1114
|
+
nestedType: {
|
|
1115
|
+
type: "Object",
|
|
1116
|
+
id: 10
|
|
1117
|
+
},
|
|
1118
|
+
description: {
|
|
1119
|
+
type: "string",
|
|
1120
|
+
id: 3
|
|
1121
|
+
},
|
|
1122
|
+
required: {
|
|
1123
|
+
type: "bool",
|
|
1124
|
+
id: 4
|
|
1125
|
+
},
|
|
1126
|
+
optional: {
|
|
1127
|
+
type: "bool",
|
|
1128
|
+
id: 5
|
|
1129
|
+
},
|
|
1130
|
+
computed: {
|
|
1131
|
+
type: "bool",
|
|
1132
|
+
id: 6
|
|
1133
|
+
},
|
|
1134
|
+
sensitive: {
|
|
1135
|
+
type: "bool",
|
|
1136
|
+
id: 7
|
|
1137
|
+
},
|
|
1138
|
+
descriptionKind: {
|
|
1139
|
+
type: "StringKind",
|
|
1140
|
+
id: 8
|
|
1141
|
+
},
|
|
1142
|
+
deprecated: {
|
|
1143
|
+
type: "bool",
|
|
1144
|
+
id: 9
|
|
1145
|
+
}
|
|
1146
|
+
} },
|
|
1147
|
+
NestedBlock: {
|
|
1148
|
+
fields: {
|
|
1149
|
+
typeName: {
|
|
1150
|
+
type: "string",
|
|
1151
|
+
id: 1
|
|
1152
|
+
},
|
|
1153
|
+
block: {
|
|
1154
|
+
type: "Block",
|
|
1155
|
+
id: 2
|
|
1156
|
+
},
|
|
1157
|
+
nesting: {
|
|
1158
|
+
type: "NestingMode",
|
|
1159
|
+
id: 3
|
|
1160
|
+
},
|
|
1161
|
+
minItems: {
|
|
1162
|
+
type: "int64",
|
|
1163
|
+
id: 4
|
|
1164
|
+
},
|
|
1165
|
+
maxItems: {
|
|
1166
|
+
type: "int64",
|
|
1167
|
+
id: 5
|
|
1168
|
+
}
|
|
1169
|
+
},
|
|
1170
|
+
nested: { NestingMode: { values: {
|
|
1171
|
+
INVALID: 0,
|
|
1172
|
+
SINGLE: 1,
|
|
1173
|
+
LIST: 2,
|
|
1174
|
+
SET: 3,
|
|
1175
|
+
MAP: 4,
|
|
1176
|
+
GROUP: 5
|
|
1177
|
+
} } }
|
|
1178
|
+
},
|
|
1179
|
+
Object: {
|
|
1180
|
+
fields: {
|
|
1181
|
+
attributes: {
|
|
1182
|
+
rule: "repeated",
|
|
1183
|
+
type: "Attribute",
|
|
1184
|
+
id: 1
|
|
1185
|
+
},
|
|
1186
|
+
nesting: {
|
|
1187
|
+
type: "NestingMode",
|
|
1188
|
+
id: 3
|
|
1189
|
+
},
|
|
1190
|
+
minItems: {
|
|
1191
|
+
type: "int64",
|
|
1192
|
+
id: 4
|
|
1193
|
+
},
|
|
1194
|
+
maxItems: {
|
|
1195
|
+
type: "int64",
|
|
1196
|
+
id: 5
|
|
1197
|
+
}
|
|
1198
|
+
},
|
|
1199
|
+
nested: { NestingMode: { values: {
|
|
1200
|
+
INVALID: 0,
|
|
1201
|
+
SINGLE: 1,
|
|
1202
|
+
LIST: 2,
|
|
1203
|
+
SET: 3,
|
|
1204
|
+
MAP: 4
|
|
1205
|
+
} } }
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
Provider: { methods: {
|
|
1210
|
+
GetProviderSchema: {
|
|
1211
|
+
requestType: "GetProviderSchema.Request",
|
|
1212
|
+
responseType: "GetProviderSchema.Response"
|
|
1213
|
+
},
|
|
1214
|
+
ValidateProviderConfig: {
|
|
1215
|
+
requestType: "ValidateProviderConfig.Request",
|
|
1216
|
+
responseType: "ValidateProviderConfig.Response"
|
|
1217
|
+
},
|
|
1218
|
+
ValidateResourceConfig: {
|
|
1219
|
+
requestType: "ValidateResourceConfig.Request",
|
|
1220
|
+
responseType: "ValidateResourceConfig.Response"
|
|
1221
|
+
},
|
|
1222
|
+
ValidateDataResourceConfig: {
|
|
1223
|
+
requestType: "ValidateDataResourceConfig.Request",
|
|
1224
|
+
responseType: "ValidateDataResourceConfig.Response"
|
|
1225
|
+
},
|
|
1226
|
+
UpgradeResourceState: {
|
|
1227
|
+
requestType: "UpgradeResourceState.Request",
|
|
1228
|
+
responseType: "UpgradeResourceState.Response"
|
|
1229
|
+
},
|
|
1230
|
+
ConfigureProvider: {
|
|
1231
|
+
requestType: "ConfigureProvider.Request",
|
|
1232
|
+
responseType: "ConfigureProvider.Response"
|
|
1233
|
+
},
|
|
1234
|
+
ReadResource: {
|
|
1235
|
+
requestType: "ReadResource.Request",
|
|
1236
|
+
responseType: "ReadResource.Response"
|
|
1237
|
+
},
|
|
1238
|
+
PlanResourceChange: {
|
|
1239
|
+
requestType: "PlanResourceChange.Request",
|
|
1240
|
+
responseType: "PlanResourceChange.Response"
|
|
1241
|
+
},
|
|
1242
|
+
ApplyResourceChange: {
|
|
1243
|
+
requestType: "ApplyResourceChange.Request",
|
|
1244
|
+
responseType: "ApplyResourceChange.Response"
|
|
1245
|
+
},
|
|
1246
|
+
ImportResourceState: {
|
|
1247
|
+
requestType: "ImportResourceState.Request",
|
|
1248
|
+
responseType: "ImportResourceState.Response"
|
|
1249
|
+
},
|
|
1250
|
+
ReadDataSource: {
|
|
1251
|
+
requestType: "ReadDataSource.Request",
|
|
1252
|
+
responseType: "ReadDataSource.Response"
|
|
1253
|
+
},
|
|
1254
|
+
StopProvider: {
|
|
1255
|
+
requestType: "StopProvider.Request",
|
|
1256
|
+
responseType: "StopProvider.Response"
|
|
1257
|
+
}
|
|
1258
|
+
} },
|
|
1259
|
+
GetProviderSchema: {
|
|
1260
|
+
fields: {},
|
|
1261
|
+
nested: {
|
|
1262
|
+
Request: { fields: {} },
|
|
1263
|
+
Response: { fields: {
|
|
1264
|
+
provider: {
|
|
1265
|
+
type: "Schema",
|
|
1266
|
+
id: 1
|
|
1267
|
+
},
|
|
1268
|
+
resourceSchemas: {
|
|
1269
|
+
keyType: "string",
|
|
1270
|
+
type: "Schema",
|
|
1271
|
+
id: 2
|
|
1272
|
+
},
|
|
1273
|
+
dataSourceSchemas: {
|
|
1274
|
+
keyType: "string",
|
|
1275
|
+
type: "Schema",
|
|
1276
|
+
id: 3
|
|
1277
|
+
},
|
|
1278
|
+
diagnostics: {
|
|
1279
|
+
rule: "repeated",
|
|
1280
|
+
type: "Diagnostic",
|
|
1281
|
+
id: 4
|
|
1282
|
+
},
|
|
1283
|
+
providerMeta: {
|
|
1284
|
+
type: "Schema",
|
|
1285
|
+
id: 5
|
|
1286
|
+
}
|
|
1287
|
+
} }
|
|
1288
|
+
}
|
|
1289
|
+
},
|
|
1290
|
+
ValidateProviderConfig: {
|
|
1291
|
+
fields: {},
|
|
1292
|
+
nested: {
|
|
1293
|
+
Request: { fields: { config: {
|
|
1294
|
+
type: "DynamicValue",
|
|
1295
|
+
id: 1
|
|
1296
|
+
} } },
|
|
1297
|
+
Response: { fields: { diagnostics: {
|
|
1298
|
+
rule: "repeated",
|
|
1299
|
+
type: "Diagnostic",
|
|
1300
|
+
id: 2
|
|
1301
|
+
} } }
|
|
1302
|
+
}
|
|
1303
|
+
},
|
|
1304
|
+
UpgradeResourceState: {
|
|
1305
|
+
fields: {},
|
|
1306
|
+
nested: {
|
|
1307
|
+
Request: { fields: {
|
|
1308
|
+
typeName: {
|
|
1309
|
+
type: "string",
|
|
1310
|
+
id: 1
|
|
1311
|
+
},
|
|
1312
|
+
version: {
|
|
1313
|
+
type: "int64",
|
|
1314
|
+
id: 2
|
|
1315
|
+
},
|
|
1316
|
+
rawState: {
|
|
1317
|
+
type: "RawState",
|
|
1318
|
+
id: 3
|
|
1319
|
+
}
|
|
1320
|
+
} },
|
|
1321
|
+
Response: { fields: {
|
|
1322
|
+
upgradedState: {
|
|
1323
|
+
type: "DynamicValue",
|
|
1324
|
+
id: 1
|
|
1325
|
+
},
|
|
1326
|
+
diagnostics: {
|
|
1327
|
+
rule: "repeated",
|
|
1328
|
+
type: "Diagnostic",
|
|
1329
|
+
id: 2
|
|
1330
|
+
}
|
|
1331
|
+
} }
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
ValidateResourceConfig: {
|
|
1335
|
+
fields: {},
|
|
1336
|
+
nested: {
|
|
1337
|
+
Request: { fields: {
|
|
1338
|
+
typeName: {
|
|
1339
|
+
type: "string",
|
|
1340
|
+
id: 1
|
|
1341
|
+
},
|
|
1342
|
+
config: {
|
|
1343
|
+
type: "DynamicValue",
|
|
1344
|
+
id: 2
|
|
1345
|
+
}
|
|
1346
|
+
} },
|
|
1347
|
+
Response: { fields: { diagnostics: {
|
|
1348
|
+
rule: "repeated",
|
|
1349
|
+
type: "Diagnostic",
|
|
1350
|
+
id: 1
|
|
1351
|
+
} } }
|
|
1352
|
+
}
|
|
1353
|
+
},
|
|
1354
|
+
ValidateDataResourceConfig: {
|
|
1355
|
+
fields: {},
|
|
1356
|
+
nested: {
|
|
1357
|
+
Request: { fields: {
|
|
1358
|
+
typeName: {
|
|
1359
|
+
type: "string",
|
|
1360
|
+
id: 1
|
|
1361
|
+
},
|
|
1362
|
+
config: {
|
|
1363
|
+
type: "DynamicValue",
|
|
1364
|
+
id: 2
|
|
1365
|
+
}
|
|
1366
|
+
} },
|
|
1367
|
+
Response: { fields: { diagnostics: {
|
|
1368
|
+
rule: "repeated",
|
|
1369
|
+
type: "Diagnostic",
|
|
1370
|
+
id: 1
|
|
1371
|
+
} } }
|
|
1372
|
+
}
|
|
1373
|
+
},
|
|
1374
|
+
ConfigureProvider: {
|
|
1375
|
+
fields: {},
|
|
1376
|
+
nested: {
|
|
1377
|
+
Request: { fields: {
|
|
1378
|
+
terraformVersion: {
|
|
1379
|
+
type: "string",
|
|
1380
|
+
id: 1
|
|
1381
|
+
},
|
|
1382
|
+
config: {
|
|
1383
|
+
type: "DynamicValue",
|
|
1384
|
+
id: 2
|
|
1385
|
+
}
|
|
1386
|
+
} },
|
|
1387
|
+
Response: { fields: { diagnostics: {
|
|
1388
|
+
rule: "repeated",
|
|
1389
|
+
type: "Diagnostic",
|
|
1390
|
+
id: 1
|
|
1391
|
+
} } }
|
|
1392
|
+
}
|
|
1393
|
+
},
|
|
1394
|
+
ReadResource: {
|
|
1395
|
+
fields: {},
|
|
1396
|
+
nested: {
|
|
1397
|
+
Request: { fields: {
|
|
1398
|
+
typeName: {
|
|
1399
|
+
type: "string",
|
|
1400
|
+
id: 1
|
|
1401
|
+
},
|
|
1402
|
+
currentState: {
|
|
1403
|
+
type: "DynamicValue",
|
|
1404
|
+
id: 2
|
|
1405
|
+
},
|
|
1406
|
+
private: {
|
|
1407
|
+
type: "bytes",
|
|
1408
|
+
id: 3
|
|
1409
|
+
},
|
|
1410
|
+
providerMeta: {
|
|
1411
|
+
type: "DynamicValue",
|
|
1412
|
+
id: 4
|
|
1413
|
+
}
|
|
1414
|
+
} },
|
|
1415
|
+
Response: { fields: {
|
|
1416
|
+
newState: {
|
|
1417
|
+
type: "DynamicValue",
|
|
1418
|
+
id: 1
|
|
1419
|
+
},
|
|
1420
|
+
diagnostics: {
|
|
1421
|
+
rule: "repeated",
|
|
1422
|
+
type: "Diagnostic",
|
|
1423
|
+
id: 2
|
|
1424
|
+
},
|
|
1425
|
+
private: {
|
|
1426
|
+
type: "bytes",
|
|
1427
|
+
id: 3
|
|
1428
|
+
}
|
|
1429
|
+
} }
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
PlanResourceChange: {
|
|
1433
|
+
fields: {},
|
|
1434
|
+
nested: {
|
|
1435
|
+
Request: { fields: {
|
|
1436
|
+
typeName: {
|
|
1437
|
+
type: "string",
|
|
1438
|
+
id: 1
|
|
1439
|
+
},
|
|
1440
|
+
priorState: {
|
|
1441
|
+
type: "DynamicValue",
|
|
1442
|
+
id: 2
|
|
1443
|
+
},
|
|
1444
|
+
proposedNewState: {
|
|
1445
|
+
type: "DynamicValue",
|
|
1446
|
+
id: 3
|
|
1447
|
+
},
|
|
1448
|
+
config: {
|
|
1449
|
+
type: "DynamicValue",
|
|
1450
|
+
id: 4
|
|
1451
|
+
},
|
|
1452
|
+
priorPrivate: {
|
|
1453
|
+
type: "bytes",
|
|
1454
|
+
id: 5
|
|
1455
|
+
},
|
|
1456
|
+
providerMeta: {
|
|
1457
|
+
type: "DynamicValue",
|
|
1458
|
+
id: 6
|
|
1459
|
+
}
|
|
1460
|
+
} },
|
|
1461
|
+
Response: { fields: {
|
|
1462
|
+
plannedState: {
|
|
1463
|
+
type: "DynamicValue",
|
|
1464
|
+
id: 1
|
|
1465
|
+
},
|
|
1466
|
+
requiresReplace: {
|
|
1467
|
+
rule: "repeated",
|
|
1468
|
+
type: "AttributePath",
|
|
1469
|
+
id: 2
|
|
1470
|
+
},
|
|
1471
|
+
plannedPrivate: {
|
|
1472
|
+
type: "bytes",
|
|
1473
|
+
id: 3
|
|
1474
|
+
},
|
|
1475
|
+
diagnostics: {
|
|
1476
|
+
rule: "repeated",
|
|
1477
|
+
type: "Diagnostic",
|
|
1478
|
+
id: 4
|
|
1479
|
+
}
|
|
1480
|
+
} }
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
ApplyResourceChange: {
|
|
1484
|
+
fields: {},
|
|
1485
|
+
nested: {
|
|
1486
|
+
Request: { fields: {
|
|
1487
|
+
typeName: {
|
|
1488
|
+
type: "string",
|
|
1489
|
+
id: 1
|
|
1490
|
+
},
|
|
1491
|
+
priorState: {
|
|
1492
|
+
type: "DynamicValue",
|
|
1493
|
+
id: 2
|
|
1494
|
+
},
|
|
1495
|
+
plannedState: {
|
|
1496
|
+
type: "DynamicValue",
|
|
1497
|
+
id: 3
|
|
1498
|
+
},
|
|
1499
|
+
config: {
|
|
1500
|
+
type: "DynamicValue",
|
|
1501
|
+
id: 4
|
|
1502
|
+
},
|
|
1503
|
+
plannedPrivate: {
|
|
1504
|
+
type: "bytes",
|
|
1505
|
+
id: 5
|
|
1506
|
+
},
|
|
1507
|
+
providerMeta: {
|
|
1508
|
+
type: "DynamicValue",
|
|
1509
|
+
id: 6
|
|
1510
|
+
}
|
|
1511
|
+
} },
|
|
1512
|
+
Response: { fields: {
|
|
1513
|
+
newState: {
|
|
1514
|
+
type: "DynamicValue",
|
|
1515
|
+
id: 1
|
|
1516
|
+
},
|
|
1517
|
+
private: {
|
|
1518
|
+
type: "bytes",
|
|
1519
|
+
id: 2
|
|
1520
|
+
},
|
|
1521
|
+
diagnostics: {
|
|
1522
|
+
rule: "repeated",
|
|
1523
|
+
type: "Diagnostic",
|
|
1524
|
+
id: 3
|
|
1525
|
+
}
|
|
1526
|
+
} }
|
|
1527
|
+
}
|
|
1528
|
+
},
|
|
1529
|
+
ImportResourceState: {
|
|
1530
|
+
fields: {},
|
|
1531
|
+
nested: {
|
|
1532
|
+
Request: { fields: {
|
|
1533
|
+
typeName: {
|
|
1534
|
+
type: "string",
|
|
1535
|
+
id: 1
|
|
1536
|
+
},
|
|
1537
|
+
id: {
|
|
1538
|
+
type: "string",
|
|
1539
|
+
id: 2
|
|
1540
|
+
}
|
|
1541
|
+
} },
|
|
1542
|
+
ImportedResource: { fields: {
|
|
1543
|
+
typeName: {
|
|
1544
|
+
type: "string",
|
|
1545
|
+
id: 1
|
|
1546
|
+
},
|
|
1547
|
+
state: {
|
|
1548
|
+
type: "DynamicValue",
|
|
1549
|
+
id: 2
|
|
1550
|
+
},
|
|
1551
|
+
private: {
|
|
1552
|
+
type: "bytes",
|
|
1553
|
+
id: 3
|
|
1554
|
+
}
|
|
1555
|
+
} },
|
|
1556
|
+
Response: { fields: {
|
|
1557
|
+
importedResources: {
|
|
1558
|
+
rule: "repeated",
|
|
1559
|
+
type: "ImportedResource",
|
|
1560
|
+
id: 1
|
|
1561
|
+
},
|
|
1562
|
+
diagnostics: {
|
|
1563
|
+
rule: "repeated",
|
|
1564
|
+
type: "Diagnostic",
|
|
1565
|
+
id: 2
|
|
1566
|
+
}
|
|
1567
|
+
} }
|
|
1568
|
+
}
|
|
1569
|
+
},
|
|
1570
|
+
ReadDataSource: {
|
|
1571
|
+
fields: {},
|
|
1572
|
+
nested: {
|
|
1573
|
+
Request: { fields: {
|
|
1574
|
+
typeName: {
|
|
1575
|
+
type: "string",
|
|
1576
|
+
id: 1
|
|
1577
|
+
},
|
|
1578
|
+
config: {
|
|
1579
|
+
type: "DynamicValue",
|
|
1580
|
+
id: 2
|
|
1581
|
+
},
|
|
1582
|
+
providerMeta: {
|
|
1583
|
+
type: "DynamicValue",
|
|
1584
|
+
id: 3
|
|
1585
|
+
}
|
|
1586
|
+
} },
|
|
1587
|
+
Response: { fields: {
|
|
1588
|
+
state: {
|
|
1589
|
+
type: "DynamicValue",
|
|
1590
|
+
id: 1
|
|
1591
|
+
},
|
|
1592
|
+
diagnostics: {
|
|
1593
|
+
rule: "repeated",
|
|
1594
|
+
type: "Diagnostic",
|
|
1595
|
+
id: 2
|
|
1596
|
+
}
|
|
1597
|
+
} }
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
} } }
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
//#endregion
|
|
1604
|
+
//#region src/plugin/client.ts
|
|
1605
|
+
const debug$2 = createDebugger("Client");
|
|
1606
|
+
const protocols = {
|
|
1607
|
+
tfplugin5: tfplugin5_default,
|
|
1608
|
+
tfplugin6: tfplugin6_default
|
|
1609
|
+
};
|
|
1610
|
+
const createPluginClient = async (props) => {
|
|
1611
|
+
const proto = protocols[props.protocol.split(".").at(0) ?? ""];
|
|
1612
|
+
if (!proto) throw new Error(`We don't have support for the ${props.protocol} protocol`);
|
|
1613
|
+
/** @ts-ignore */
|
|
1614
|
+
const client = new (loadPackageDefinition(fromJSON(proto)))["tfplugin" + props.version].Provider(`unix://${props.endpoint}`, credentials.createInsecure(), {
|
|
1615
|
+
"grpc.max_receive_message_length": 100 * 1024 * 1024,
|
|
1616
|
+
"grpc.max_send_message_length": 100 * 1024 * 1024
|
|
1617
|
+
});
|
|
1618
|
+
debug$2("init", props.protocol);
|
|
1619
|
+
await new Promise((resolve, reject) => {
|
|
1620
|
+
const deadline = /* @__PURE__ */ new Date();
|
|
1621
|
+
deadline.setSeconds(deadline.getSeconds() + 10);
|
|
1622
|
+
client.waitForReady(deadline, (error) => {
|
|
1623
|
+
if (error) reject(error);
|
|
1624
|
+
else resolve();
|
|
1625
|
+
});
|
|
1626
|
+
});
|
|
1627
|
+
debug$2("connected");
|
|
1628
|
+
return { call(method, payload) {
|
|
1629
|
+
return new Promise((resolve, reject) => {
|
|
1630
|
+
const fn = client[method];
|
|
1631
|
+
debug$2("call", method);
|
|
1632
|
+
if (!fn) {
|
|
1633
|
+
reject(/* @__PURE__ */ new Error(`Unknown method call: ${method}`));
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
fn.call(client, payload, (error, response) => {
|
|
1637
|
+
if (error) {
|
|
1638
|
+
debug$2("failed", error);
|
|
1639
|
+
reject(error);
|
|
1640
|
+
} else if (response.diagnostics) {
|
|
1641
|
+
debug$2("failed", response.diagnostics);
|
|
1642
|
+
reject(throwDiagnosticError(response));
|
|
1643
|
+
} else resolve(response);
|
|
1644
|
+
});
|
|
1645
|
+
});
|
|
1646
|
+
} };
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1649
|
+
//#endregion
|
|
1650
|
+
//#region src/plugin/registry.ts
|
|
1651
|
+
const baseUrl = "https://registry.terraform.io/v1/providers";
|
|
1652
|
+
const getProviderVersions = async (org, type) => {
|
|
1653
|
+
const versions = (await (await fetch(`${baseUrl}/${org}/${type}/versions`)).json()).versions;
|
|
1654
|
+
const os = getOS();
|
|
1655
|
+
const ar = getArchitecture();
|
|
1656
|
+
const supported = versions.filter((v) => {
|
|
1657
|
+
return !!v.platforms.find((p) => p.os === os && p.arch === ar);
|
|
1658
|
+
});
|
|
1659
|
+
const latest = supported.sort((a, b) => compare(a.version, b.version)).at(-1);
|
|
1660
|
+
if (!latest) throw new Error("Version is unsupported for your platform.");
|
|
1661
|
+
return {
|
|
1662
|
+
versions,
|
|
1663
|
+
supported,
|
|
1664
|
+
latest: latest.version
|
|
1665
|
+
};
|
|
1666
|
+
};
|
|
1667
|
+
const getProviderDownloadUrl = async (org, type, version) => {
|
|
1668
|
+
const url = [
|
|
1669
|
+
baseUrl,
|
|
1670
|
+
org,
|
|
1671
|
+
type,
|
|
1672
|
+
version,
|
|
1673
|
+
"download",
|
|
1674
|
+
getOS(),
|
|
1675
|
+
getArchitecture()
|
|
1676
|
+
].join("/");
|
|
1677
|
+
const result = await (await fetch(url)).json();
|
|
1678
|
+
return {
|
|
1679
|
+
url: result.download_url,
|
|
1680
|
+
shasum: result.shasum,
|
|
1681
|
+
protocols: result.protocols
|
|
1682
|
+
};
|
|
1683
|
+
};
|
|
1684
|
+
const getOS = () => {
|
|
1685
|
+
const os = platform();
|
|
1686
|
+
switch (os) {
|
|
1687
|
+
case "linux": return "linux";
|
|
1688
|
+
case "win32": return "windows";
|
|
1689
|
+
case "darwin": return "darwin";
|
|
1690
|
+
case "freebsd": return "freebsd";
|
|
1691
|
+
case "openbsd": return "openbsd";
|
|
1692
|
+
}
|
|
1693
|
+
throw new Error(`Unsupported OS platform: ${os}`);
|
|
1694
|
+
};
|
|
1695
|
+
const getArchitecture = () => {
|
|
1696
|
+
const ar = arch();
|
|
1697
|
+
switch (ar) {
|
|
1698
|
+
case "arm": return "arm";
|
|
1699
|
+
case "arm64": return "arm64";
|
|
1700
|
+
case "x64": return "amd64";
|
|
1701
|
+
case "ia32": return "386";
|
|
1702
|
+
}
|
|
1703
|
+
throw new Error(`Unsupported architecture: ${ar}`);
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
//#endregion
|
|
1707
|
+
//#region src/plugin/download.ts
|
|
1708
|
+
const exists = async (file) => {
|
|
1709
|
+
try {
|
|
1710
|
+
await stat(file);
|
|
1711
|
+
} catch (error) {
|
|
1712
|
+
return false;
|
|
1713
|
+
}
|
|
1714
|
+
return true;
|
|
1715
|
+
};
|
|
1716
|
+
const debug$1 = createDebugger("Downloader");
|
|
1717
|
+
const installPath = join(homedir(), ".terraforge", "plugins");
|
|
1718
|
+
const getInstallPath = (props) => {
|
|
1719
|
+
return join(props.location ?? installPath, `${props.org}-${props.type}-${props.version}`);
|
|
1720
|
+
};
|
|
1721
|
+
const isPluginInstalled = (props) => {
|
|
1722
|
+
return exists(getInstallPath(props));
|
|
1723
|
+
};
|
|
1724
|
+
const deletePlugin = async (props) => {
|
|
1725
|
+
const file = getInstallPath(props);
|
|
1726
|
+
if (await isPluginInstalled(props)) {
|
|
1727
|
+
debug$1(props.type, "deleting...");
|
|
1728
|
+
await rm(file);
|
|
1729
|
+
debug$1(props.type, "deleted");
|
|
1730
|
+
} else debug$1(props.type, "not installed");
|
|
1731
|
+
};
|
|
1732
|
+
const downloadPlugin = async (props) => {
|
|
1733
|
+
if (props.version === "latest") {
|
|
1734
|
+
const { latest } = await getProviderVersions(props.org, props.type);
|
|
1735
|
+
props.version = latest;
|
|
1736
|
+
}
|
|
1737
|
+
const file = getInstallPath(props);
|
|
1738
|
+
if (!await isPluginInstalled(props)) {
|
|
1739
|
+
debug$1(props.type, "downloading...");
|
|
1740
|
+
const info = await getProviderDownloadUrl(props.org, props.type, props.version);
|
|
1741
|
+
const buf = await (await fetch(info.url)).bytes();
|
|
1742
|
+
const zipped = (await jszip.loadAsync(buf)).filter((file$1) => file$1.startsWith("terraform-provider")).at(0);
|
|
1743
|
+
if (!zipped) throw new Error(`Can't find the provider inside the downloaded zip file.`);
|
|
1744
|
+
const binary = await zipped.async("nodebuffer");
|
|
1745
|
+
debug$1(props.type, "done");
|
|
1746
|
+
await mkdir(dirname(file), { recursive: true });
|
|
1747
|
+
await writeFile(file, binary, { mode: 509 });
|
|
1748
|
+
} else debug$1(props.type, "already downloaded");
|
|
1749
|
+
return {
|
|
1750
|
+
file,
|
|
1751
|
+
version: props.version
|
|
1752
|
+
};
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
//#endregion
|
|
1756
|
+
//#region src/plugin/server.ts
|
|
1757
|
+
const debug = createDebugger("Server");
|
|
1758
|
+
const createPluginServer = (props) => {
|
|
1759
|
+
return new Promise((resolve, reject) => {
|
|
1760
|
+
debug("init");
|
|
1761
|
+
const process = spawn(`${props.file}`, ["-debug"]);
|
|
1762
|
+
process.stderr.on("data", (data) => {
|
|
1763
|
+
if (props.debug) {
|
|
1764
|
+
const message = data.toString("utf8");
|
|
1765
|
+
console.log(message);
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
process.stdout.once("data", (data) => {
|
|
1769
|
+
try {
|
|
1770
|
+
const matches = data.toString("utf8").match(/TF_REATTACH_PROVIDERS\=\'(.*)\'/);
|
|
1771
|
+
if (matches && matches.length > 0) {
|
|
1772
|
+
const json = matches[0].slice(23, -1);
|
|
1773
|
+
const data$1 = JSON.parse(json);
|
|
1774
|
+
const entries = Object.values(data$1);
|
|
1775
|
+
if (entries.length > 0) {
|
|
1776
|
+
const entry = entries[0];
|
|
1777
|
+
const version = entry.ProtocolVersion;
|
|
1778
|
+
const endpoint = entry.Addr.String;
|
|
1779
|
+
debug("started", endpoint);
|
|
1780
|
+
resolve({
|
|
1781
|
+
kill() {
|
|
1782
|
+
process.kill();
|
|
1783
|
+
},
|
|
1784
|
+
protocol: "tfplugin" + version.toFixed(1),
|
|
1785
|
+
version,
|
|
1786
|
+
endpoint
|
|
1787
|
+
});
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
} catch (error) {}
|
|
1792
|
+
debug("failed");
|
|
1793
|
+
reject(/* @__PURE__ */ new Error("Failed to start the plugin"));
|
|
1794
|
+
});
|
|
1795
|
+
});
|
|
1796
|
+
};
|
|
1797
|
+
|
|
1798
|
+
//#endregion
|
|
1799
|
+
//#region src/plugin/schema.ts
|
|
1800
|
+
const NestingMode = {
|
|
1801
|
+
INVALID: 0,
|
|
1802
|
+
SINGLE: 1,
|
|
1803
|
+
LIST: 2,
|
|
1804
|
+
SET: 3,
|
|
1805
|
+
MAP: 4,
|
|
1806
|
+
GROUP: 5
|
|
1807
|
+
};
|
|
1808
|
+
const parseResourceSchema = (schemas) => {
|
|
1809
|
+
const props = {};
|
|
1810
|
+
for (const [name, schema] of Object.entries(schemas)) if (schema.block) {
|
|
1811
|
+
const block = parseBlock(schema.block);
|
|
1812
|
+
props[name] = {
|
|
1813
|
+
...block,
|
|
1814
|
+
version: block.version ?? schema.version
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
return props;
|
|
1818
|
+
};
|
|
1819
|
+
const parseProviderSchema = (schema) => {
|
|
1820
|
+
if (schema.block) {
|
|
1821
|
+
const block = parseBlock(schema.block);
|
|
1822
|
+
return {
|
|
1823
|
+
...block,
|
|
1824
|
+
version: block.version ?? schema.version
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
throw new Error("Invalid block");
|
|
1828
|
+
};
|
|
1829
|
+
const parseBlock = (block) => {
|
|
1830
|
+
const properties = {};
|
|
1831
|
+
for (const entry of block.attributes ?? []) properties[entry.name] = parseAttribute(entry);
|
|
1832
|
+
for (const entry of block.blockTypes ?? []) properties[entry.typeName] = parseNestedBlock(entry);
|
|
1833
|
+
if (block.deprecated) console.warn("Deprecated block");
|
|
1834
|
+
return {
|
|
1835
|
+
type: "object",
|
|
1836
|
+
version: block.version,
|
|
1837
|
+
description: block.description,
|
|
1838
|
+
properties
|
|
1839
|
+
};
|
|
1840
|
+
};
|
|
1841
|
+
const parseNestedBlock = (block) => {
|
|
1842
|
+
const type = parseNestedBlockType(block);
|
|
1843
|
+
const item = parseBlock(block.block);
|
|
1844
|
+
const prop = {
|
|
1845
|
+
optional: true,
|
|
1846
|
+
required: false,
|
|
1847
|
+
computed: false
|
|
1848
|
+
};
|
|
1849
|
+
if (type === "array" || type === "record") return {
|
|
1850
|
+
...prop,
|
|
1851
|
+
type,
|
|
1852
|
+
item
|
|
1853
|
+
};
|
|
1854
|
+
if (type === "array-object") return {
|
|
1855
|
+
...prop,
|
|
1856
|
+
...item,
|
|
1857
|
+
type
|
|
1858
|
+
};
|
|
1859
|
+
return {
|
|
1860
|
+
...prop,
|
|
1861
|
+
...item
|
|
1862
|
+
};
|
|
1863
|
+
};
|
|
1864
|
+
const parseNestedBlockType = (block) => {
|
|
1865
|
+
if (block.nesting === NestingMode.SET) return "array";
|
|
1866
|
+
if (block.nesting === NestingMode.LIST) {
|
|
1867
|
+
if (block.maxItems?.eq(1)) return "array-object";
|
|
1868
|
+
return "array";
|
|
1869
|
+
}
|
|
1870
|
+
if (block.nesting === NestingMode.MAP) return "record";
|
|
1871
|
+
if (block.nesting === NestingMode.GROUP) return "object";
|
|
1872
|
+
if (block.nesting === NestingMode.SINGLE) return "object";
|
|
1873
|
+
throw new Error(`Invalid nested block type ${block.nesting}`);
|
|
1874
|
+
};
|
|
1875
|
+
const parseAttribute = (attr) => {
|
|
1876
|
+
const prop = {
|
|
1877
|
+
description: attr.description,
|
|
1878
|
+
required: attr.required,
|
|
1879
|
+
optional: attr.optional,
|
|
1880
|
+
computed: attr.computed,
|
|
1881
|
+
deprecated: attr.deprecated,
|
|
1882
|
+
sensitive: attr.sensitive
|
|
1883
|
+
};
|
|
1884
|
+
if (attr.type) {
|
|
1885
|
+
const json = JSON.parse(attr.type.toString("utf8"));
|
|
1886
|
+
return {
|
|
1887
|
+
...prop,
|
|
1888
|
+
...parseAttributeType(json)
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
1891
|
+
if (attr.nestedType) return {
|
|
1892
|
+
...prop,
|
|
1893
|
+
...parseBlock(attr.nestedType)
|
|
1894
|
+
};
|
|
1895
|
+
throw new Error("Empty attr");
|
|
1896
|
+
};
|
|
1897
|
+
const parseAttributeType = (item) => {
|
|
1898
|
+
if (Array.isArray(item)) {
|
|
1899
|
+
const type$1 = parseType(item[0]);
|
|
1900
|
+
if (type$1 === "array" || type$1 === "record" && item) {
|
|
1901
|
+
const record = item[1];
|
|
1902
|
+
return {
|
|
1903
|
+
type: type$1,
|
|
1904
|
+
item: parseAttributeType(record)
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
if (type$1 === "object") {
|
|
1908
|
+
const object = item[1];
|
|
1909
|
+
const properties = {};
|
|
1910
|
+
for (const [name, prop] of Object.entries(object)) properties[name] = parseAttributeType(prop);
|
|
1911
|
+
return {
|
|
1912
|
+
type: type$1,
|
|
1913
|
+
properties
|
|
1914
|
+
};
|
|
1915
|
+
}
|
|
1916
|
+
throw new Error("Invalid attribute type");
|
|
1917
|
+
}
|
|
1918
|
+
const type = parseType(item);
|
|
1919
|
+
if (isLeafType(type)) return { type };
|
|
1920
|
+
throw new Error(`Invalid attribute type`);
|
|
1921
|
+
};
|
|
1922
|
+
const isLeafType = (type) => {
|
|
1923
|
+
return [
|
|
1924
|
+
"string",
|
|
1925
|
+
"number",
|
|
1926
|
+
"boolean",
|
|
1927
|
+
"unknown"
|
|
1928
|
+
].includes(type);
|
|
1929
|
+
};
|
|
1930
|
+
const parseType = (type) => {
|
|
1931
|
+
if (type === "string") return "string";
|
|
1932
|
+
if (type === "number") return "number";
|
|
1933
|
+
if (type === "bool") return "boolean";
|
|
1934
|
+
if (["set", "list"].includes(type)) return "array";
|
|
1935
|
+
if (type === "object") return "object";
|
|
1936
|
+
if (type === "map") return "record";
|
|
1937
|
+
if (type === "dynamic") return "unknown";
|
|
1938
|
+
throw new Error(`Invalid type: ${type}`);
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
//#endregion
|
|
1942
|
+
//#region src/plugin/version/util.ts
|
|
1943
|
+
const encodeDynamicValue = (value) => {
|
|
1944
|
+
return {
|
|
1945
|
+
msgpack: pack(value),
|
|
1946
|
+
json: value
|
|
1947
|
+
};
|
|
1948
|
+
};
|
|
1949
|
+
const decodeDynamicValue = (value) => {
|
|
1950
|
+
return unpack(value.msgpack);
|
|
1951
|
+
};
|
|
1952
|
+
const getResourceSchema = (resources, type) => {
|
|
1953
|
+
const resource = resources[type];
|
|
1954
|
+
if (!resource) throw new Error(`Unknown resource type: ${type}`);
|
|
1955
|
+
return resource;
|
|
1956
|
+
};
|
|
1957
|
+
const formatAttributePath = (state) => {
|
|
1958
|
+
if (!state) return [];
|
|
1959
|
+
return state.map((item) => {
|
|
1960
|
+
if (!item.steps) throw new Error("AttributePath should always have steps");
|
|
1961
|
+
return item.steps.map((attr) => {
|
|
1962
|
+
if ("attributeName" in attr) return attr.attributeName;
|
|
1963
|
+
if ("elementKeyString" in attr) return attr.elementKeyString;
|
|
1964
|
+
if ("elementKeyInt" in attr) return attr.elementKeyInt;
|
|
1965
|
+
throw new Error("AttributePath step should always have an element");
|
|
1966
|
+
});
|
|
1967
|
+
});
|
|
1968
|
+
};
|
|
1969
|
+
var IncorrectType = class extends TypeError {
|
|
1970
|
+
constructor(type, path) {
|
|
1971
|
+
super(`${path.join(".")} should be a ${type}`);
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
const formatInputState = (schema, state, includeSchemaFields = true, path = []) => {
|
|
1975
|
+
if (state === null) return null;
|
|
1976
|
+
if (typeof state === "undefined") return null;
|
|
1977
|
+
if (schema.type === "unknown") return state;
|
|
1978
|
+
if (schema.type === "string") {
|
|
1979
|
+
if (typeof state === "string") return state;
|
|
1980
|
+
throw new IncorrectType(schema.type, path);
|
|
1981
|
+
}
|
|
1982
|
+
if (schema.type === "number") {
|
|
1983
|
+
if (typeof state === "number") return state;
|
|
1984
|
+
throw new IncorrectType(schema.type, path);
|
|
1985
|
+
}
|
|
1986
|
+
if (schema.type === "boolean") {
|
|
1987
|
+
if (typeof state === "boolean") return state;
|
|
1988
|
+
throw new IncorrectType(schema.type, path);
|
|
1989
|
+
}
|
|
1990
|
+
if (schema.type === "array") {
|
|
1991
|
+
if (Array.isArray(state)) return state.map((item, i) => formatInputState(schema.item, item, includeSchemaFields, [...path, i]));
|
|
1992
|
+
throw new IncorrectType(schema.type, path);
|
|
1993
|
+
}
|
|
1994
|
+
if (schema.type === "record") {
|
|
1995
|
+
if (typeof state === "object" && state !== null) {
|
|
1996
|
+
const record = {};
|
|
1997
|
+
for (const [key, value] of Object.entries(state)) record[key] = formatInputState(schema.item, value, includeSchemaFields, [...path, key]);
|
|
1998
|
+
return record;
|
|
1999
|
+
}
|
|
2000
|
+
throw new IncorrectType(schema.type, path);
|
|
2001
|
+
}
|
|
2002
|
+
if (schema.type === "object" || schema.type === "array-object") {
|
|
2003
|
+
if (typeof state === "object" && state !== null) {
|
|
2004
|
+
const object = {};
|
|
2005
|
+
if (includeSchemaFields) for (const [key, prop] of Object.entries(schema.properties)) {
|
|
2006
|
+
const value = state[camelCase(key)];
|
|
2007
|
+
object[key] = formatInputState(prop, value, true, [...path, key]);
|
|
2008
|
+
}
|
|
2009
|
+
else for (const [key, value] of Object.entries(state)) {
|
|
2010
|
+
const prop = schema.properties[snakeCase(key)];
|
|
2011
|
+
if (prop) object[key] = formatInputState(prop, value, false, [...path, key]);
|
|
2012
|
+
}
|
|
2013
|
+
if (schema.type === "array-object") return [object];
|
|
2014
|
+
return object;
|
|
2015
|
+
}
|
|
2016
|
+
throw new IncorrectType(schema.type, path);
|
|
2017
|
+
}
|
|
2018
|
+
throw new Error(`Unknown schema type: ${schema.type}`);
|
|
2019
|
+
};
|
|
2020
|
+
const formatOutputState = (schema, state, path = []) => {
|
|
2021
|
+
if (state === null) return;
|
|
2022
|
+
if (schema.type === "array") {
|
|
2023
|
+
if (Array.isArray(state)) return state.map((item, i) => formatOutputState(schema.item, item, [...path, i]));
|
|
2024
|
+
throw new IncorrectType(schema.type, path);
|
|
2025
|
+
}
|
|
2026
|
+
if (schema.type === "record") {
|
|
2027
|
+
if (typeof state === "object" && state !== null) {
|
|
2028
|
+
const record = {};
|
|
2029
|
+
for (const [key, value] of Object.entries(state)) record[key] = formatOutputState(schema.item, value, [...path, key]);
|
|
2030
|
+
return record;
|
|
2031
|
+
}
|
|
2032
|
+
throw new IncorrectType(schema.type, path);
|
|
2033
|
+
}
|
|
2034
|
+
if (schema.type === "object") {
|
|
2035
|
+
if (typeof state === "object" && state !== null) {
|
|
2036
|
+
const object = {};
|
|
2037
|
+
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
2038
|
+
const value = state[key];
|
|
2039
|
+
object[camelCase(key)] = formatOutputState(prop, value, [...path, key]);
|
|
2040
|
+
}
|
|
2041
|
+
return object;
|
|
2042
|
+
}
|
|
2043
|
+
throw new IncorrectType(schema.type, path);
|
|
2044
|
+
}
|
|
2045
|
+
if (schema.type === "array-object") {
|
|
2046
|
+
if (Array.isArray(state)) if (state.length === 1) {
|
|
2047
|
+
const object = {};
|
|
2048
|
+
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
2049
|
+
const value = state[0][key];
|
|
2050
|
+
object[camelCase(key)] = formatOutputState(prop, value, [...path, key]);
|
|
2051
|
+
}
|
|
2052
|
+
return object;
|
|
2053
|
+
} else return;
|
|
2054
|
+
throw new IncorrectType(schema.type, path);
|
|
2055
|
+
}
|
|
2056
|
+
return state;
|
|
2057
|
+
};
|
|
2058
|
+
|
|
2059
|
+
//#endregion
|
|
2060
|
+
//#region src/plugin/version/5.ts
|
|
2061
|
+
const createPlugin5 = async ({ server, client }) => {
|
|
2062
|
+
const schema = await client.call("GetSchema");
|
|
2063
|
+
const provider = parseProviderSchema(schema.provider);
|
|
2064
|
+
const resources = parseResourceSchema(schema.resourceSchemas);
|
|
2065
|
+
const dataSources = parseResourceSchema(schema.dataSourceSchemas);
|
|
2066
|
+
return {
|
|
2067
|
+
schema() {
|
|
2068
|
+
return {
|
|
2069
|
+
provider,
|
|
2070
|
+
resources,
|
|
2071
|
+
dataSources
|
|
2072
|
+
};
|
|
2073
|
+
},
|
|
2074
|
+
async stop() {
|
|
2075
|
+
await client.call("Stop");
|
|
2076
|
+
server.kill();
|
|
2077
|
+
},
|
|
2078
|
+
async configure(config) {
|
|
2079
|
+
const prepared = await client.call("PrepareProviderConfig", { config: encodeDynamicValue(formatInputState(provider, config)) });
|
|
2080
|
+
await client.call("Configure", { config: prepared.preparedConfig });
|
|
2081
|
+
},
|
|
2082
|
+
async readResource(type, state) {
|
|
2083
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2084
|
+
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ReadResource", {
|
|
2085
|
+
typeName: type,
|
|
2086
|
+
currentState: encodeDynamicValue(formatInputState(schema$1, state))
|
|
2087
|
+
})).newState));
|
|
2088
|
+
},
|
|
2089
|
+
async readDataSource(type, state) {
|
|
2090
|
+
const schema$1 = getResourceSchema(dataSources, type);
|
|
2091
|
+
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ReadDataSource", {
|
|
2092
|
+
typeName: type,
|
|
2093
|
+
config: encodeDynamicValue(formatInputState(schema$1, state))
|
|
2094
|
+
})).state));
|
|
2095
|
+
},
|
|
2096
|
+
async validateResource(type, state) {
|
|
2097
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2098
|
+
await client.call("ValidateResourceTypeConfig", {
|
|
2099
|
+
typeName: type,
|
|
2100
|
+
config: encodeDynamicValue(formatInputState(schema$1, state))
|
|
2101
|
+
});
|
|
2102
|
+
},
|
|
2103
|
+
async planResourceChange(type, priorState, proposedState) {
|
|
2104
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2105
|
+
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2106
|
+
const preparedProposedState = formatInputState(schema$1, proposedState);
|
|
2107
|
+
const plan = await client.call("PlanResourceChange", {
|
|
2108
|
+
typeName: type,
|
|
2109
|
+
priorState: encodeDynamicValue(preparedPriorState),
|
|
2110
|
+
proposedNewState: encodeDynamicValue(preparedProposedState),
|
|
2111
|
+
config: encodeDynamicValue(preparedProposedState)
|
|
2112
|
+
});
|
|
2113
|
+
const plannedState = decodeDynamicValue(plan.plannedState);
|
|
2114
|
+
return {
|
|
2115
|
+
requiresReplace: formatAttributePath(plan.requiresReplace),
|
|
2116
|
+
plannedState
|
|
2117
|
+
};
|
|
2118
|
+
},
|
|
2119
|
+
async applyResourceChange(type, priorState, proposedState) {
|
|
2120
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2121
|
+
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2122
|
+
const preparedProposedState = formatInputState(schema$1, proposedState);
|
|
2123
|
+
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
|
|
2124
|
+
typeName: type,
|
|
2125
|
+
priorState: encodeDynamicValue(preparedPriorState),
|
|
2126
|
+
plannedState: encodeDynamicValue(preparedProposedState),
|
|
2127
|
+
config: encodeDynamicValue(preparedProposedState)
|
|
2128
|
+
})).newState));
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
};
|
|
2132
|
+
|
|
2133
|
+
//#endregion
|
|
2134
|
+
//#region src/plugin/version/6.ts
|
|
2135
|
+
const createPlugin6 = async ({ server, client }) => {
|
|
2136
|
+
const schema = await client.call("GetProviderSchema");
|
|
2137
|
+
const provider = parseProviderSchema(schema.provider);
|
|
2138
|
+
const resources = parseResourceSchema(schema.resourceSchemas);
|
|
2139
|
+
const dataSources = parseResourceSchema(schema.dataSourceSchemas);
|
|
2140
|
+
return {
|
|
2141
|
+
schema() {
|
|
2142
|
+
return {
|
|
2143
|
+
provider,
|
|
2144
|
+
resources,
|
|
2145
|
+
dataSources
|
|
2146
|
+
};
|
|
2147
|
+
},
|
|
2148
|
+
async stop() {
|
|
2149
|
+
await client.call("StopProvider");
|
|
2150
|
+
server.kill();
|
|
2151
|
+
},
|
|
2152
|
+
async configure(config) {
|
|
2153
|
+
const prepared = await client.call("ValidateProviderConfig", { config: encodeDynamicValue(formatInputState(provider, config)) });
|
|
2154
|
+
await client.call("ConfigureProvider", { config: prepared.preparedConfig });
|
|
2155
|
+
},
|
|
2156
|
+
async readResource(type, state) {
|
|
2157
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2158
|
+
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ReadResource", {
|
|
2159
|
+
typeName: type,
|
|
2160
|
+
currentState: encodeDynamicValue(formatInputState(schema$1, state))
|
|
2161
|
+
})).newState));
|
|
2162
|
+
},
|
|
2163
|
+
async readDataSource(type, state) {
|
|
2164
|
+
const schema$1 = getResourceSchema(dataSources, type);
|
|
2165
|
+
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ReadDataSource", {
|
|
2166
|
+
typeName: type,
|
|
2167
|
+
config: encodeDynamicValue(formatInputState(schema$1, state))
|
|
2168
|
+
})).state));
|
|
2169
|
+
},
|
|
2170
|
+
async validateResource(type, state) {
|
|
2171
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2172
|
+
await client.call("ValidateResourceConfig", {
|
|
2173
|
+
typeName: type,
|
|
2174
|
+
config: encodeDynamicValue(formatInputState(schema$1, state))
|
|
2175
|
+
});
|
|
2176
|
+
},
|
|
2177
|
+
async planResourceChange(type, priorState, proposedState) {
|
|
2178
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2179
|
+
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2180
|
+
const preparedProposedState = formatInputState(schema$1, proposedState);
|
|
2181
|
+
const plan = await client.call("PlanResourceChange", {
|
|
2182
|
+
typeName: type,
|
|
2183
|
+
priorState: encodeDynamicValue(preparedPriorState),
|
|
2184
|
+
proposedNewState: encodeDynamicValue(preparedProposedState),
|
|
2185
|
+
config: encodeDynamicValue(preparedProposedState)
|
|
2186
|
+
});
|
|
2187
|
+
const plannedState = decodeDynamicValue(plan.plannedState);
|
|
2188
|
+
return {
|
|
2189
|
+
requiresReplace: formatAttributePath(plan.requiresReplace),
|
|
2190
|
+
plannedState
|
|
2191
|
+
};
|
|
2192
|
+
},
|
|
2193
|
+
async applyResourceChange(type, priorState, proposedState) {
|
|
2194
|
+
const schema$1 = getResourceSchema(resources, type);
|
|
2195
|
+
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2196
|
+
const preparedProposedState = formatInputState(schema$1, proposedState);
|
|
2197
|
+
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
|
|
2198
|
+
typeName: type,
|
|
2199
|
+
priorState: encodeDynamicValue(preparedPriorState),
|
|
2200
|
+
plannedState: encodeDynamicValue(preparedProposedState),
|
|
2201
|
+
config: encodeDynamicValue(preparedProposedState)
|
|
2202
|
+
})).newState));
|
|
2203
|
+
}
|
|
2204
|
+
};
|
|
2205
|
+
};
|
|
2206
|
+
|
|
2207
|
+
//#endregion
|
|
2208
|
+
//#region src/lazy-plugin.ts
|
|
2209
|
+
const createLazyPlugin = (props) => {
|
|
2210
|
+
return async () => {
|
|
2211
|
+
const { file } = await downloadPlugin(props);
|
|
2212
|
+
const server = await retry(3, () => createPluginServer({
|
|
2213
|
+
file,
|
|
2214
|
+
debug: false
|
|
2215
|
+
}));
|
|
2216
|
+
const client = await retry(3, () => createPluginClient(server));
|
|
2217
|
+
const plugin = await {
|
|
2218
|
+
5: () => createPlugin5({
|
|
2219
|
+
server,
|
|
2220
|
+
client
|
|
2221
|
+
}),
|
|
2222
|
+
6: () => createPlugin6({
|
|
2223
|
+
server,
|
|
2224
|
+
client
|
|
2225
|
+
})
|
|
2226
|
+
}[server.version]?.();
|
|
2227
|
+
if (!plugin) throw new Error(`No plugin client available for protocol version ${server.version}`);
|
|
2228
|
+
return plugin;
|
|
2229
|
+
};
|
|
2230
|
+
};
|
|
2231
|
+
const retry = async (tries, cb) => {
|
|
2232
|
+
let latestError;
|
|
2233
|
+
while (--tries) try {
|
|
2234
|
+
return await cb();
|
|
2235
|
+
} catch (error) {
|
|
2236
|
+
latestError = error;
|
|
2237
|
+
}
|
|
2238
|
+
throw latestError;
|
|
2239
|
+
};
|
|
2240
|
+
|
|
2241
|
+
//#endregion
|
|
2242
|
+
//#region src/proxy.ts
|
|
2243
|
+
const createResourceProxy = (cb) => {
|
|
2244
|
+
return new Proxy({}, {
|
|
2245
|
+
get(_, key) {
|
|
2246
|
+
return cb(key);
|
|
2247
|
+
},
|
|
2248
|
+
set(_, key) {
|
|
2249
|
+
if (typeof key === "string") throw new Error(`Cannot set property ${key} on read-only object.`);
|
|
2250
|
+
throw new Error(`This object is read-only.`);
|
|
2251
|
+
}
|
|
2252
|
+
});
|
|
2253
|
+
};
|
|
2254
|
+
const createNamespaceProxy = (cb) => {
|
|
2255
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2256
|
+
return new Proxy({}, {
|
|
2257
|
+
get(_, key) {
|
|
2258
|
+
if (typeof key === "string") {
|
|
2259
|
+
if (!cache.has(key)) {
|
|
2260
|
+
const value = cb(key);
|
|
2261
|
+
cache.set(key, value);
|
|
2262
|
+
}
|
|
2263
|
+
return cache.get(key);
|
|
2264
|
+
}
|
|
2265
|
+
},
|
|
2266
|
+
set(_, key) {
|
|
2267
|
+
if (typeof key === "string") throw new Error(`Cannot set property ${key} on read-only object.`);
|
|
2268
|
+
throw new Error(`This object is read-only.`);
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
};
|
|
2272
|
+
const createRootProxy = (apply, get) => {
|
|
2273
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2274
|
+
return new Proxy(() => {}, {
|
|
2275
|
+
apply(_, _this, args) {
|
|
2276
|
+
return apply(...args);
|
|
2277
|
+
},
|
|
2278
|
+
get(_, key) {
|
|
2279
|
+
if (typeof key === "string") {
|
|
2280
|
+
if (!cache.has(key)) {
|
|
2281
|
+
const value = get(key);
|
|
2282
|
+
cache.set(key, value);
|
|
2283
|
+
}
|
|
2284
|
+
return cache.get(key);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
});
|
|
2288
|
+
};
|
|
2289
|
+
const createClassProxy = (construct, get) => {
|
|
2290
|
+
return new Proxy(class {}, {
|
|
2291
|
+
construct(_, args) {
|
|
2292
|
+
return construct(...args);
|
|
2293
|
+
},
|
|
2294
|
+
get(_, key) {
|
|
2295
|
+
if (key === "get") return (...args) => {
|
|
2296
|
+
return get(...args);
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
});
|
|
2300
|
+
};
|
|
2301
|
+
const createRecursiveProxy = ({ provider, install, uninstall, isInstalled, resource, dataSource }) => {
|
|
2302
|
+
const findNextProxy = (ns, name) => {
|
|
2303
|
+
if (name === name.toLowerCase()) return createNamespaceProxy((key) => {
|
|
2304
|
+
return findNextProxy([...ns, name], key);
|
|
2305
|
+
});
|
|
2306
|
+
else if (name.startsWith("get")) return (...args) => {
|
|
2307
|
+
return dataSource([...ns, name.substring(3)], ...args);
|
|
2308
|
+
};
|
|
2309
|
+
else return createClassProxy((...args) => {
|
|
2310
|
+
return resource([...ns, name], ...args);
|
|
2311
|
+
}, (...args) => {
|
|
2312
|
+
return dataSource([...ns, name], ...args);
|
|
2313
|
+
});
|
|
2314
|
+
};
|
|
2315
|
+
return createRootProxy(provider, (key) => {
|
|
2316
|
+
if (key === "install") return install;
|
|
2317
|
+
if (key === "uninstall") return uninstall;
|
|
2318
|
+
if (key === "isInstalled") return isInstalled;
|
|
2319
|
+
return findNextProxy([], key);
|
|
2320
|
+
});
|
|
2321
|
+
};
|
|
2322
|
+
const createTerraformProxy = (props) => {
|
|
2323
|
+
return createRecursiveProxy({
|
|
2324
|
+
provider(input, config) {
|
|
2325
|
+
return new TerraformProvider(props.namespace, config?.id ?? "default", createLazyPlugin({
|
|
2326
|
+
...props.provider,
|
|
2327
|
+
location: config?.location
|
|
2328
|
+
}), input);
|
|
2329
|
+
},
|
|
2330
|
+
async install(installProps) {
|
|
2331
|
+
await downloadPlugin({
|
|
2332
|
+
...props.provider,
|
|
2333
|
+
...installProps
|
|
2334
|
+
});
|
|
2335
|
+
},
|
|
2336
|
+
async uninstall(installProps) {
|
|
2337
|
+
await deletePlugin({
|
|
2338
|
+
...props.provider,
|
|
2339
|
+
...installProps
|
|
2340
|
+
});
|
|
2341
|
+
},
|
|
2342
|
+
isInstalled(installProps) {
|
|
2343
|
+
return isPluginInstalled({
|
|
2344
|
+
...props.provider,
|
|
2345
|
+
...installProps
|
|
2346
|
+
});
|
|
2347
|
+
},
|
|
2348
|
+
resource: (ns, parent, id, input, config) => {
|
|
2349
|
+
const type = snakeCase([props.namespace, ...ns].join("_"));
|
|
2350
|
+
const meta = createMeta("resource", `terraform:${props.namespace}:${config?.provider ?? "default"}`, parent, type, id, input, config);
|
|
2351
|
+
const resource = createResourceProxy((key) => {
|
|
2352
|
+
if (typeof key === "string") return meta.output((data) => data[key]);
|
|
2353
|
+
else if (key === nodeMetaSymbol) return meta;
|
|
2354
|
+
});
|
|
2355
|
+
parent.add(resource);
|
|
2356
|
+
return resource;
|
|
2357
|
+
},
|
|
2358
|
+
dataSource: (ns, parent, id, input, config) => {
|
|
2359
|
+
const type = snakeCase([props.namespace, ...ns].join("_"));
|
|
2360
|
+
const meta = createMeta("data", `terraform:${props.namespace}:${config?.provider ?? "default"}`, parent, type, id, input, config);
|
|
2361
|
+
const dataSource = createResourceProxy((key) => {
|
|
2362
|
+
if (typeof key === "string") return meta.output((data) => data[key]);
|
|
2363
|
+
else if (key === nodeMetaSymbol) return meta;
|
|
2364
|
+
});
|
|
2365
|
+
parent.add(dataSource);
|
|
2366
|
+
return dataSource;
|
|
2367
|
+
}
|
|
2368
|
+
});
|
|
2369
|
+
};
|
|
2370
|
+
|
|
2371
|
+
//#endregion
|
|
2372
|
+
export { TerraformProvider, createTerraformProxy, generateTypes };
|