@cdktn/provider-generator 0.26.0-pre.3 → 0.26.0-pre.31
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/build/__tests__/erasable-syntax.test.d.ts +2 -0
- package/build/__tests__/erasable-syntax.test.js +96 -0
- package/build/get/__tests__/generator/empty-provider-resources.test.js +5 -1
- package/build/get/__tests__/generator/module-docs-registry.test.js +8 -10
- package/build/get/__tests__/generator/module-generator.test.js +7 -10
- package/build/get/__tests__/target-versions.test.js +4 -2
- package/build/get/constructs-maker.js +3 -3
- package/build/get/generator/models/scope.js +2 -14
- package/build/get/generator/resource-parser.js +3 -3
- package/eslint.config.mjs +11 -0
- package/jest.config.js +0 -1
- package/package.json +5 -5
- package/package.sh +0 -0
- package/src/__tests__/edge-provider-schema/builder.ts +0 -201
- package/src/__tests__/edge-provider-schema/cli.ts +0 -51
- package/src/__tests__/edge-provider-schema/index.ts +0 -284
- package/src/__tests__/edge-provider-schema.test.ts +0 -24
- package/src/__tests__/provider.test.ts +0 -208
- package/src/get/__tests__/constructs-maker.test.ts +0 -242
- package/src/get/__tests__/generator/complex-computed-types.test.ts +0 -28
- package/src/get/__tests__/generator/deep-nested-attributes.test.ts +0 -56
- package/src/get/__tests__/generator/description-escaping.test.ts +0 -84
- package/src/get/__tests__/generator/empty-provider-resources.test.ts +0 -26
- package/src/get/__tests__/generator/ephemeral-resources.test.ts +0 -46
- package/src/get/__tests__/generator/export-sharding.test.ts +0 -169
- package/src/get/__tests__/generator/import-style.test.ts +0 -129
- package/src/get/__tests__/generator/module-docs-registry.test.ts +0 -89
- package/src/get/__tests__/generator/module-generator.test.ts +0 -528
- package/src/get/__tests__/generator/nested-types.test.ts +0 -54
- package/src/get/__tests__/generator/provider-functions-name-collision.test.ts +0 -84
- package/src/get/__tests__/generator/provider-functions.test.ts +0 -262
- package/src/get/__tests__/generator/provider-source-matching.test.ts +0 -84
- package/src/get/__tests__/generator/provider.test.ts +0 -59
- package/src/get/__tests__/generator/resource-types.test.ts +0 -118
- package/src/get/__tests__/generator/skipped-attributes.test.ts +0 -72
- package/src/get/__tests__/generator/supported-stored-classes.test.ts +0 -147
- package/src/get/__tests__/generator/types.test.ts +0 -686
- package/src/get/__tests__/generator/versions-file.test.ts +0 -77
- package/src/get/__tests__/generator/write-only.test.ts +0 -71
- package/src/get/__tests__/registry-class-invalidation.test.ts +0 -123
- package/src/get/__tests__/target-versions.test.ts +0 -249
- package/src/get/__tests__/util.ts +0 -80
- package/src/get/constructs-maker.ts +0 -991
- package/src/get/generator/custom-defaults.ts +0 -494
- package/src/get/generator/emitter/attributes-emitter.ts +0 -316
- package/src/get/generator/emitter/index.ts +0 -6
- package/src/get/generator/emitter/provider-functions-emitter.ts +0 -117
- package/src/get/generator/emitter/resource-emitter.ts +0 -330
- package/src/get/generator/emitter/struct-emitter.ts +0 -683
- package/src/get/generator/loop-detection.ts +0 -81
- package/src/get/generator/models/attribute-model.ts +0 -273
- package/src/get/generator/models/attribute-type-model.ts +0 -559
- package/src/get/generator/models/index.ts +0 -8
- package/src/get/generator/models/provider-function-model.ts +0 -872
- package/src/get/generator/models/resource-model.ts +0 -206
- package/src/get/generator/models/scope.ts +0 -54
- package/src/get/generator/models/struct.ts +0 -124
- package/src/get/generator/models/supported-stored-classes.ts +0 -88
- package/src/get/generator/module-generator.ts +0 -236
- package/src/get/generator/provider-generator.ts +0 -451
- package/src/get/generator/resource-parser.ts +0 -782
- package/src/get/generator/sanitized-comments.ts +0 -49
- package/src/get/generator/skipped-attributes.ts +0 -27
- package/src/index.ts +0 -40
- package/src/util.ts +0 -26
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
// Copyright (c) HashiCorp, Inc
|
|
2
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
-
import { ProviderSchema, FunctionSignature } from "@cdktn/commons";
|
|
4
|
-
import { schema, SchemaBuilder as S } from "./builder";
|
|
5
|
-
|
|
6
|
-
const required_attribute_resource = new S()
|
|
7
|
-
.addAllPrimitiveTypes({ required: true, computed: false })
|
|
8
|
-
.addAllPrimitiveListTypes({ required: true, computed: false })
|
|
9
|
-
.build();
|
|
10
|
-
|
|
11
|
-
const optional_attribute_resource = new S()
|
|
12
|
-
.addAllPrimitiveTypes({ required: false, computed: false })
|
|
13
|
-
.addAllPrimitiveListTypes({ required: false, computed: false })
|
|
14
|
-
// Write-only attribute (RFC-04 / protocol v6): exercises the deprecated
|
|
15
|
-
// getter + the resolve-time `markWriteOnlyAttribute` wrapping in
|
|
16
|
-
// synthesizeAttributes()/synthesizeHclAttributes() on an existing managed
|
|
17
|
-
// resource. Left optional so no existing usage of
|
|
18
|
-
// OptionalAttributeResource across the edge test suite needs updating
|
|
19
|
-
// (and so it also generates a reset method).
|
|
20
|
-
.attribute({
|
|
21
|
-
name: "secretWo",
|
|
22
|
-
type: "string",
|
|
23
|
-
required: false,
|
|
24
|
-
computed: false,
|
|
25
|
-
writeOnly: true,
|
|
26
|
-
})
|
|
27
|
-
.build();
|
|
28
|
-
|
|
29
|
-
const optional_computed_attribute_resource = new S()
|
|
30
|
-
.addAllPrimitiveTypes({ required: false, computed: true })
|
|
31
|
-
.addAllPrimitiveListTypes({ required: false, computed: true })
|
|
32
|
-
.build();
|
|
33
|
-
|
|
34
|
-
const list_block_resource = new S()
|
|
35
|
-
.listBlock({
|
|
36
|
-
name: "opt",
|
|
37
|
-
block: new S().addAllPrimitivePermutations().asBlock(),
|
|
38
|
-
minItems: 0,
|
|
39
|
-
maxItems: 42,
|
|
40
|
-
})
|
|
41
|
-
.listBlock({
|
|
42
|
-
name: "req",
|
|
43
|
-
block: new S().addAllPrimitivePermutations().asBlock(),
|
|
44
|
-
minItems: 1,
|
|
45
|
-
maxItems: 42,
|
|
46
|
-
})
|
|
47
|
-
.listBlock({
|
|
48
|
-
name: "singleopt",
|
|
49
|
-
block: new S().addAllPrimitivePermutations().asBlock(),
|
|
50
|
-
minItems: 0,
|
|
51
|
-
maxItems: 1,
|
|
52
|
-
})
|
|
53
|
-
.listBlock({
|
|
54
|
-
name: "singlereq",
|
|
55
|
-
block: new S().addAllPrimitivePermutations().asBlock(),
|
|
56
|
-
minItems: 1,
|
|
57
|
-
maxItems: 1,
|
|
58
|
-
})
|
|
59
|
-
.listBlock({
|
|
60
|
-
name: "singleComputedBlock",
|
|
61
|
-
block: new S()
|
|
62
|
-
.attribute({
|
|
63
|
-
computed: true,
|
|
64
|
-
name: "computed",
|
|
65
|
-
type: "string",
|
|
66
|
-
required: false,
|
|
67
|
-
optional: false,
|
|
68
|
-
})
|
|
69
|
-
.attribute({
|
|
70
|
-
computed: false,
|
|
71
|
-
name: "configured",
|
|
72
|
-
type: "string",
|
|
73
|
-
required: false,
|
|
74
|
-
})
|
|
75
|
-
.asBlock(),
|
|
76
|
-
minItems: 0,
|
|
77
|
-
maxItems: 1,
|
|
78
|
-
})
|
|
79
|
-
.attribute({
|
|
80
|
-
name: "computedListOfObject",
|
|
81
|
-
type: [
|
|
82
|
-
"list",
|
|
83
|
-
[
|
|
84
|
-
"object",
|
|
85
|
-
{
|
|
86
|
-
str: "string",
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
],
|
|
90
|
-
computed: true,
|
|
91
|
-
optional: false,
|
|
92
|
-
})
|
|
93
|
-
.attribute({
|
|
94
|
-
name: "computedListOfMapOfObject",
|
|
95
|
-
type: [
|
|
96
|
-
"list",
|
|
97
|
-
[
|
|
98
|
-
"map",
|
|
99
|
-
[
|
|
100
|
-
"object",
|
|
101
|
-
{
|
|
102
|
-
str: "string",
|
|
103
|
-
other: "string",
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
],
|
|
107
|
-
],
|
|
108
|
-
computed: true,
|
|
109
|
-
optional: false,
|
|
110
|
-
})
|
|
111
|
-
.build();
|
|
112
|
-
|
|
113
|
-
const map_list_resource = new S()
|
|
114
|
-
.attribute({
|
|
115
|
-
name: "mapListOfObject",
|
|
116
|
-
type: [
|
|
117
|
-
"map",
|
|
118
|
-
[
|
|
119
|
-
"list",
|
|
120
|
-
[
|
|
121
|
-
"object",
|
|
122
|
-
{
|
|
123
|
-
hello: "string",
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
],
|
|
127
|
-
],
|
|
128
|
-
computed: false,
|
|
129
|
-
optional: false,
|
|
130
|
-
})
|
|
131
|
-
.build();
|
|
132
|
-
|
|
133
|
-
const map_resource = new S()
|
|
134
|
-
.attribute({
|
|
135
|
-
name: "optMap",
|
|
136
|
-
type: ["map", "string"],
|
|
137
|
-
required: false,
|
|
138
|
-
computed: false,
|
|
139
|
-
})
|
|
140
|
-
.attribute({
|
|
141
|
-
name: "reqMap",
|
|
142
|
-
type: ["map", "bool"],
|
|
143
|
-
required: true,
|
|
144
|
-
computed: false,
|
|
145
|
-
})
|
|
146
|
-
.attribute({
|
|
147
|
-
name: "computedMap",
|
|
148
|
-
type: ["map", "number"],
|
|
149
|
-
required: false,
|
|
150
|
-
computed: true,
|
|
151
|
-
})
|
|
152
|
-
.build();
|
|
153
|
-
|
|
154
|
-
const set_block_resource = new S()
|
|
155
|
-
.setBlock({
|
|
156
|
-
name: "set",
|
|
157
|
-
block: new S().addAllPrimitivePermutations().asBlock(),
|
|
158
|
-
})
|
|
159
|
-
.build();
|
|
160
|
-
|
|
161
|
-
// A modest ephemeral resource (plugin protocol v6 / RFC-04): a required
|
|
162
|
-
// string, an optional number, a computed attribute, and a nested single
|
|
163
|
-
// block - consistent with the primitive/nested-block conventions used by
|
|
164
|
-
// the resources above.
|
|
165
|
-
const cached_secret = new S()
|
|
166
|
-
.attribute({ name: "str", type: "string", required: true })
|
|
167
|
-
.attribute({ name: "num", type: "number", required: false })
|
|
168
|
-
.attribute({
|
|
169
|
-
name: "computedStr",
|
|
170
|
-
type: "string",
|
|
171
|
-
computed: true,
|
|
172
|
-
optional: false,
|
|
173
|
-
})
|
|
174
|
-
.singleBlock({
|
|
175
|
-
name: "nested",
|
|
176
|
-
block: new S()
|
|
177
|
-
.attribute({ name: "str", type: "string", required: false })
|
|
178
|
-
.attribute({ name: "num", type: "number", required: false })
|
|
179
|
-
.asBlock(),
|
|
180
|
-
})
|
|
181
|
-
.build();
|
|
182
|
-
|
|
183
|
-
// Provider-defined functions (Terraform >=1.8 / protocol v6), each
|
|
184
|
-
// exercising a distinct generator branch of `provider-function-model.ts`.
|
|
185
|
-
// Reuses shapes from `provider-functions-synthetic.test.fixture.json` where
|
|
186
|
-
// sensible, renamed to fit the edge fixture's naming.
|
|
187
|
-
const functions: { [name: string]: FunctionSignature } = {
|
|
188
|
-
// Simple string -> string function.
|
|
189
|
-
greet: {
|
|
190
|
-
description: "Returns a friendly greeting for the given name.",
|
|
191
|
-
summary: "Greet a name",
|
|
192
|
-
return_type: "string",
|
|
193
|
-
parameters: [{ name: "name", type: "string" }],
|
|
194
|
-
},
|
|
195
|
-
// Nullable TRAILING fixed param: becomes jsii-optional.
|
|
196
|
-
greet_with_title: {
|
|
197
|
-
description: "Greets the given name, optionally with a title.",
|
|
198
|
-
summary: "Greet with an optional title",
|
|
199
|
-
return_type: "string",
|
|
200
|
-
parameters: [
|
|
201
|
-
{ name: "name", type: "string" },
|
|
202
|
-
{ name: "title", type: "string", is_nullable: true },
|
|
203
|
-
],
|
|
204
|
-
},
|
|
205
|
-
// Nullable MID-POSITION fixed param followed by a required param: stays
|
|
206
|
-
// positional, widens to `any` so a caller can still pass an explicit null.
|
|
207
|
-
join_prefixed: {
|
|
208
|
-
description: "Joins a possibly-null prefix with a required suffix.",
|
|
209
|
-
summary: "Join with a nullable prefix",
|
|
210
|
-
return_type: "string",
|
|
211
|
-
parameters: [
|
|
212
|
-
{ name: "prefix", type: "string", is_nullable: true },
|
|
213
|
-
{ name: "suffix", type: "string" },
|
|
214
|
-
],
|
|
215
|
-
},
|
|
216
|
-
// Nullable VARIADIC param: rest parameter widens to `any[]`.
|
|
217
|
-
describe_items: {
|
|
218
|
-
description: "Joins a label with any number of possibly-null items.",
|
|
219
|
-
summary: "Describe items with a label",
|
|
220
|
-
return_type: "string",
|
|
221
|
-
parameters: [{ name: "label", type: "string" }],
|
|
222
|
-
variadic_parameter: { name: "items", type: "string", is_nullable: true },
|
|
223
|
-
},
|
|
224
|
-
// Variadic of bool: union element type -> Array<boolean | IResolvable>
|
|
225
|
-
// rest param.
|
|
226
|
-
all_true: {
|
|
227
|
-
description: "Returns true if every given flag is true.",
|
|
228
|
-
summary: "All flags true",
|
|
229
|
-
return_type: "bool",
|
|
230
|
-
variadic_parameter: { name: "flags", type: "bool" },
|
|
231
|
-
},
|
|
232
|
-
// deprecation_message present (Terraform >=1.8 only, see FunctionSignature
|
|
233
|
-
// docstring) -> surfaced as an `@deprecated` JSDoc tag.
|
|
234
|
-
legacy_greet: {
|
|
235
|
-
description:
|
|
236
|
-
"A deprecated greeting helper kept for backwards compatibility.",
|
|
237
|
-
summary: "Legacy greet",
|
|
238
|
-
deprecation_message: "Use greet instead.",
|
|
239
|
-
return_type: "string",
|
|
240
|
-
parameters: [{ name: "name", type: "string" }],
|
|
241
|
-
},
|
|
242
|
-
// Returns ["object", {...}].
|
|
243
|
-
build_info: {
|
|
244
|
-
description:
|
|
245
|
-
"Returns an object describing the build that produced the given seed.",
|
|
246
|
-
summary: "Build info",
|
|
247
|
-
return_type: ["object", { version: "string", revision: "string" }],
|
|
248
|
-
parameters: [{ name: "seed", type: "string" }],
|
|
249
|
-
},
|
|
250
|
-
// Returns ["list", "number"].
|
|
251
|
-
list_squares: {
|
|
252
|
-
description:
|
|
253
|
-
"Returns the squares of the numbers from 1 to the given count.",
|
|
254
|
-
summary: "List squares",
|
|
255
|
-
return_type: ["list", "number"],
|
|
256
|
-
parameters: [{ name: "count", type: "number" }],
|
|
257
|
-
},
|
|
258
|
-
// A ["map", "string"] param.
|
|
259
|
-
render_tags: {
|
|
260
|
-
description: "Renders the given map of string tags as a single string.",
|
|
261
|
-
summary: "Render tags",
|
|
262
|
-
return_type: "string",
|
|
263
|
-
parameters: [{ name: "tags", type: ["map", "string"] }],
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
export const edgeSchema: ProviderSchema = schema({
|
|
268
|
-
name: "edge",
|
|
269
|
-
provider: new S().addAllPrimitivePermutations().build(),
|
|
270
|
-
resources: {
|
|
271
|
-
required_attribute_resource,
|
|
272
|
-
optional_attribute_resource,
|
|
273
|
-
optional_computed_attribute_resource,
|
|
274
|
-
list_block_resource,
|
|
275
|
-
map_resource,
|
|
276
|
-
set_block_resource,
|
|
277
|
-
map_list_resource,
|
|
278
|
-
},
|
|
279
|
-
dataSources: {},
|
|
280
|
-
ephemeralResources: {
|
|
281
|
-
cached_secret,
|
|
282
|
-
},
|
|
283
|
-
functions,
|
|
284
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Copyright (c) HashiCorp, Inc
|
|
2
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
-
import * as fs from "fs-extra";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import { generateProviderBindingsFromSchema } from "..";
|
|
6
|
-
import { mkdtemp } from "@cdktn/commons";
|
|
7
|
-
import { edgeSchema } from "./edge-provider-schema";
|
|
8
|
-
|
|
9
|
-
describe("Edge Provider Schema", () => {
|
|
10
|
-
it("compiles to Typescript", async () => {
|
|
11
|
-
return mkdtemp(async (dir) => {
|
|
12
|
-
await generateProviderBindingsFromSchema(dir, edgeSchema);
|
|
13
|
-
|
|
14
|
-
fs.readdirSync(path.join(dir, "providers", "edge")).forEach((file) => {
|
|
15
|
-
if (!file.endsWith(".ts")) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
expect(
|
|
19
|
-
fs.readFileSync(path.join(dir, "providers", "edge", file), "utf8"),
|
|
20
|
-
).toMatchSnapshot(file);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
// Copyright (c) HashiCorp, Inc
|
|
2
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import * as fs from "fs-extra";
|
|
5
|
-
import { glob } from "glob";
|
|
6
|
-
import { mkdtemp } from "@cdktn/commons";
|
|
7
|
-
import { ConstructsMaker } from "../get/constructs-maker";
|
|
8
|
-
import { Language, TerraformProviderConstraint } from "@cdktn/commons";
|
|
9
|
-
|
|
10
|
-
interface SynthOutput {
|
|
11
|
-
[filePath: string]: any;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function directorySnapshot(root: string) {
|
|
15
|
-
const output: SynthOutput = {};
|
|
16
|
-
|
|
17
|
-
const files = glob.sync("**", {
|
|
18
|
-
ignore: [".git/**", ".jsii"],
|
|
19
|
-
cwd: root,
|
|
20
|
-
nodir: true,
|
|
21
|
-
dot: true,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
for (const file of files) {
|
|
25
|
-
const filePath = path.join(root, file);
|
|
26
|
-
|
|
27
|
-
let content;
|
|
28
|
-
|
|
29
|
-
if (path.extname(filePath) === ".json") {
|
|
30
|
-
content = fs.readJsonSync(filePath);
|
|
31
|
-
|
|
32
|
-
if (path.basename(filePath) === "constraints.json") {
|
|
33
|
-
delete content.cdktf;
|
|
34
|
-
// cli identity depends on the terraform/opentofu binary installed
|
|
35
|
-
// on the test runner - not deterministic, so excluded like cdktf.
|
|
36
|
-
delete content.cli;
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// glob yields native separators on Windows; key the snapshot by a
|
|
43
|
-
// "/"-separated path so it is identical on every platform.
|
|
44
|
-
output[file.split(path.sep).join(path.posix.sep)] = content;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return output;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function resourceTypesPresentInSnapshot(
|
|
51
|
-
snapshot: SynthOutput,
|
|
52
|
-
providerNameInPath: string,
|
|
53
|
-
) {
|
|
54
|
-
const resources: string[] = [];
|
|
55
|
-
const files = Object.keys(snapshot);
|
|
56
|
-
for (const file of files) {
|
|
57
|
-
const match = file.match(
|
|
58
|
-
`/providers/${providerNameInPath}/(.*?)/index.ts/`,
|
|
59
|
-
);
|
|
60
|
-
// avoids any not resources from being pushed
|
|
61
|
-
if (
|
|
62
|
-
match &&
|
|
63
|
-
!match[1].includes("/") &&
|
|
64
|
-
!match[1].includes("data-") &&
|
|
65
|
-
!match[1].includes("provider")
|
|
66
|
-
) {
|
|
67
|
-
resources.push(match[1]);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return resources;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Rewrites the registry host in any fully-qualified-name key. The host records
|
|
75
|
-
* which CLI fetched the schema - terraform's or tofu's - rather than anything
|
|
76
|
-
* about the generated code, so one snapshot serves both.
|
|
77
|
-
*/
|
|
78
|
-
function stubRegistryHosts(value: any): any {
|
|
79
|
-
if (Array.isArray(value)) return value.map(stubRegistryHosts);
|
|
80
|
-
if (value && typeof value === "object") {
|
|
81
|
-
return Object.fromEntries(
|
|
82
|
-
Object.entries(value).map(([k, v]) => [
|
|
83
|
-
k.replace(
|
|
84
|
-
/^registry\.(?:terraform\.io|opentofu\.org)\//,
|
|
85
|
-
"STUBBED_REGISTRY/",
|
|
86
|
-
),
|
|
87
|
-
stubRegistryHosts(v),
|
|
88
|
-
]),
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
describe("Provider", () => {
|
|
95
|
-
it("generates a provider", async () => {
|
|
96
|
-
const constraint = new TerraformProviderConstraint(
|
|
97
|
-
"DataDog/datadog@= 3.12.0",
|
|
98
|
-
);
|
|
99
|
-
return await mkdtemp(async (workdir) => {
|
|
100
|
-
const jsiiPath = path.join(workdir, ".jsii");
|
|
101
|
-
const maker = new ConstructsMaker(
|
|
102
|
-
{
|
|
103
|
-
codeMakerOutput: workdir,
|
|
104
|
-
outputJsii: jsiiPath,
|
|
105
|
-
targetLanguage: Language.TYPESCRIPT,
|
|
106
|
-
},
|
|
107
|
-
process.env.CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH,
|
|
108
|
-
);
|
|
109
|
-
await maker.generate([constraint]);
|
|
110
|
-
const snapshot = stubRegistryHosts(directorySnapshot(workdir));
|
|
111
|
-
expect(snapshot).toMatchSnapshot();
|
|
112
|
-
});
|
|
113
|
-
}, 600_000);
|
|
114
|
-
|
|
115
|
-
it("has generated provider that includes static import functions", async () => {
|
|
116
|
-
const constraint = new TerraformProviderConstraint(
|
|
117
|
-
"DataDog/datadog@= 3.12.0",
|
|
118
|
-
);
|
|
119
|
-
return await mkdtemp(async (workdir) => {
|
|
120
|
-
const jsiiPath = path.join(workdir, ".jsii");
|
|
121
|
-
const maker = new ConstructsMaker({
|
|
122
|
-
codeMakerOutput: workdir,
|
|
123
|
-
outputJsii: jsiiPath,
|
|
124
|
-
targetLanguage: Language.TYPESCRIPT,
|
|
125
|
-
});
|
|
126
|
-
await maker.generate([constraint]);
|
|
127
|
-
const snapshot = stubRegistryHosts(directorySnapshot(workdir));
|
|
128
|
-
|
|
129
|
-
const terraformResourceTypesPresent: string[] =
|
|
130
|
-
resourceTypesPresentInSnapshot(snapshot, "datadog");
|
|
131
|
-
|
|
132
|
-
terraformResourceTypesPresent.forEach((resource) => {
|
|
133
|
-
let terraformResourceType = resource.replace(/-/g, "_");
|
|
134
|
-
if (!terraformResourceType.includes("datadog")) {
|
|
135
|
-
terraformResourceType = `datadog_${terraformResourceType}`;
|
|
136
|
-
}
|
|
137
|
-
expect(snapshot[`providers/datadog/${resource}/index.ts`]).toContain(
|
|
138
|
-
`public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktn.TerraformProvider) {`,
|
|
139
|
-
);
|
|
140
|
-
expect(snapshot[`providers/datadog/${resource}/index.ts`]).toContain(
|
|
141
|
-
`return new cdktn.ImportableResource(scope, importToId, { terraformResourceType: "${terraformResourceType}", importId: importFromId, provider });`,
|
|
142
|
-
);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
}, 600_000);
|
|
146
|
-
|
|
147
|
-
it("has name in constraint that does not match resolved name in fqpn", async () => {
|
|
148
|
-
const constraint = new TerraformProviderConstraint({
|
|
149
|
-
name: "dockerr",
|
|
150
|
-
source: "registry.terraform.io/kreuzwerker/docker",
|
|
151
|
-
version: "3.9.0",
|
|
152
|
-
});
|
|
153
|
-
return await mkdtemp(async (workdir) => {
|
|
154
|
-
const jsiiPath = path.join(workdir, ".jsii");
|
|
155
|
-
const maker = new ConstructsMaker(
|
|
156
|
-
{
|
|
157
|
-
codeMakerOutput: workdir,
|
|
158
|
-
outputJsii: jsiiPath,
|
|
159
|
-
targetLanguage: Language.TYPESCRIPT,
|
|
160
|
-
},
|
|
161
|
-
process.env.CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH,
|
|
162
|
-
);
|
|
163
|
-
await maker.generate([constraint]);
|
|
164
|
-
const snapshot = stubRegistryHosts(directorySnapshot(workdir));
|
|
165
|
-
|
|
166
|
-
const terraformResourceTypesPresent: string[] =
|
|
167
|
-
resourceTypesPresentInSnapshot(snapshot, "dockerr");
|
|
168
|
-
|
|
169
|
-
terraformResourceTypesPresent.forEach((resource) => {
|
|
170
|
-
expect(
|
|
171
|
-
snapshot[`providers/dockerr/${resource}/index.ts`],
|
|
172
|
-
).toBeDefined();
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
}, 600_000);
|
|
176
|
-
|
|
177
|
-
it("generates constructs for two providers with same name", async () => {
|
|
178
|
-
const constraint = new TerraformProviderConstraint({
|
|
179
|
-
name: "bitbucket",
|
|
180
|
-
namespace: "DrFaust92",
|
|
181
|
-
version: "2.51.0",
|
|
182
|
-
source: "DrFaust92/bitbucket",
|
|
183
|
-
});
|
|
184
|
-
// andsafe-AG/bitbucket is Terraform-registry only; zahiar/bitbucket is
|
|
185
|
-
// mirrored on both, so this runs under either CLI.
|
|
186
|
-
const constraint2 = new TerraformProviderConstraint({
|
|
187
|
-
name: "abitbucket",
|
|
188
|
-
namespace: "zahiar",
|
|
189
|
-
version: "0.3.0",
|
|
190
|
-
source: "zahiar/bitbucket",
|
|
191
|
-
});
|
|
192
|
-
return await mkdtemp(async (workdir) => {
|
|
193
|
-
const jsiiPath = path.join(workdir, ".jsii");
|
|
194
|
-
const maker = new ConstructsMaker(
|
|
195
|
-
{
|
|
196
|
-
codeMakerOutput: workdir,
|
|
197
|
-
outputJsii: jsiiPath,
|
|
198
|
-
targetLanguage: Language.TYPESCRIPT,
|
|
199
|
-
},
|
|
200
|
-
process.env.CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH,
|
|
201
|
-
);
|
|
202
|
-
await maker.generate([constraint, constraint2]);
|
|
203
|
-
console.log("workdir", workdir);
|
|
204
|
-
const snapshot = stubRegistryHosts(directorySnapshot(workdir));
|
|
205
|
-
expect(snapshot).toMatchSnapshot();
|
|
206
|
-
});
|
|
207
|
-
}, 600_000);
|
|
208
|
-
});
|