@cdktn/provider-generator 0.24.0-pre.5 → 0.24.0-pre.50
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/.spec.swcrc +22 -0
- package/LICENSE +355 -0
- package/README.md +1 -1
- package/build/__tests__/edge-provider-schema/cli.js +8 -3
- package/build/get/__tests__/generator/import-style.test.d.ts +2 -0
- package/build/get/__tests__/generator/import-style.test.js +101 -0
- package/build/get/__tests__/generator/module-generator.test.js +12 -12
- package/build/get/constructs-maker.d.ts +5 -1
- package/build/get/constructs-maker.js +14 -6
- package/build/get/generator/emitter/struct-emitter.d.ts +2 -1
- package/build/get/generator/emitter/struct-emitter.js +14 -11
- package/build/get/generator/module-generator.js +3 -3
- package/build/get/generator/provider-generator.d.ts +9 -1
- package/build/get/generator/provider-generator.js +9 -6
- package/jest.config.js +16 -9
- package/package.json +24 -23
- package/package.sh +1 -1
- package/src/__tests__/__snapshots__/edge-provider-schema.test.ts.snap +8 -8
- package/src/__tests__/__snapshots__/provider.test.ts.snap +2951 -2951
- package/src/__tests__/edge-provider-schema/builder.ts +185 -0
- package/src/__tests__/edge-provider-schema/cli.ts +51 -0
- package/src/__tests__/edge-provider-schema/index.ts +161 -0
- package/src/__tests__/edge-provider-schema.test.ts +24 -0
- package/src/__tests__/provider.test.ts +180 -0
- package/src/get/__tests__/constructs-maker.test.ts +118 -0
- package/src/get/__tests__/generator/__snapshots__/complex-computed-types.test.ts.snap +5 -5
- package/src/get/__tests__/generator/__snapshots__/export-sharding.test.ts.snap +3310 -3310
- package/src/get/__tests__/generator/__snapshots__/module-generator.test.ts.snap +355 -355
- package/src/get/__tests__/generator/__snapshots__/nested-types.test.ts.snap +8 -8
- package/src/get/__tests__/generator/__snapshots__/provider.test.ts.snap +8 -8
- package/src/get/__tests__/generator/__snapshots__/resource-types.test.ts.snap +126 -126
- package/src/get/__tests__/generator/__snapshots__/skipped-attributes.test.ts.snap +17 -17
- package/src/get/__tests__/generator/__snapshots__/types.test.ts.snap +65 -65
- package/src/get/__tests__/generator/complex-computed-types.test.ts +28 -0
- package/src/get/__tests__/generator/deep-nested-attributes.test.ts +56 -0
- package/src/get/__tests__/generator/description-escaping.test.ts +84 -0
- package/src/get/__tests__/generator/empty-provider-resources.test.ts +26 -0
- package/src/get/__tests__/generator/export-sharding.test.ts +169 -0
- package/src/get/__tests__/generator/import-style.test.ts +129 -0
- package/src/get/__tests__/generator/module-generator.test.ts +528 -0
- package/src/get/__tests__/generator/nested-types.test.ts +54 -0
- package/src/get/__tests__/generator/provider.test.ts +51 -0
- package/src/get/__tests__/generator/resource-types.test.ts +118 -0
- package/src/get/__tests__/generator/skipped-attributes.test.ts +72 -0
- package/src/get/__tests__/generator/types.test.ts +611 -0
- package/src/get/__tests__/generator/versions-file.test.ts +72 -0
- package/src/get/__tests__/util.ts +75 -0
- package/src/get/constructs-maker.ts +822 -0
- package/src/get/generator/custom-defaults.ts +493 -0
- package/src/get/generator/emitter/attributes-emitter.ts +225 -0
- package/src/get/generator/emitter/index.ts +5 -0
- package/src/get/generator/emitter/resource-emitter.ts +226 -0
- package/src/get/generator/emitter/struct-emitter.ts +683 -0
- package/src/get/generator/loop-detection.ts +81 -0
- package/src/get/generator/models/attribute-model.ts +216 -0
- package/src/get/generator/models/attribute-type-model.ts +448 -0
- package/src/get/generator/models/index.ts +7 -0
- package/src/get/generator/models/resource-model.ts +161 -0
- package/src/get/generator/models/scope.ts +54 -0
- package/src/get/generator/models/struct.ts +116 -0
- package/src/get/generator/module-generator.ts +234 -0
- package/src/get/generator/provider-generator.ts +355 -0
- package/src/get/generator/resource-parser.ts +762 -0
- package/src/get/generator/sanitized-comments.ts +49 -0
- package/src/get/generator/skipped-attributes.ts +27 -0
- package/src/index.ts +40 -0
- package/src/util.ts +26 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// Copyright (c) HashiCorp, Inc
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
import { CodeMaker } from "codemaker";
|
|
4
|
+
import { AttributeModel } from "../models";
|
|
5
|
+
import { CUSTOM_DEFAULTS } from "../custom-defaults";
|
|
6
|
+
|
|
7
|
+
function titleCase(value: string) {
|
|
8
|
+
return value[0].toUpperCase() + value.slice(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class AttributesEmitter {
|
|
12
|
+
constructor(private code: CodeMaker) {}
|
|
13
|
+
|
|
14
|
+
public emit(att: AttributeModel, escapeReset: boolean, escapeInput: boolean) {
|
|
15
|
+
this.code.line();
|
|
16
|
+
this.code.line(
|
|
17
|
+
`// ${att.terraformName} - computed: ${att.computed}, optional: ${att.isOptional}, required: ${att.isRequired}`,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const isStored = att.isStored;
|
|
21
|
+
const hasResetMethod =
|
|
22
|
+
isStored && !att.isRequired && att.setterType._type !== "none";
|
|
23
|
+
const hasInputMethod = isStored && att.setterType._type !== "none";
|
|
24
|
+
|
|
25
|
+
const getterType = att.getterType;
|
|
26
|
+
|
|
27
|
+
if (getterType._type === "stored_class") {
|
|
28
|
+
this.code.line(
|
|
29
|
+
`private ${att.storageName} = ${this.storedClassInit(att)};`,
|
|
30
|
+
);
|
|
31
|
+
} else if (isStored) {
|
|
32
|
+
this.code.line(
|
|
33
|
+
`private ${att.storageName}?: ${att.type.inputTypeDefinition}; `,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
switch (getterType._type) {
|
|
38
|
+
case "plain":
|
|
39
|
+
this.code.openBlock(`public get ${att.name}()`);
|
|
40
|
+
this.code.line(`return ${this.determineGetAttCall(att)};`);
|
|
41
|
+
this.code.closeBlock();
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case "args":
|
|
45
|
+
this.code.openBlock(
|
|
46
|
+
`public ${att.name}(${getterType.args})${
|
|
47
|
+
getterType.returnType ? ": " + getterType.returnType : ""
|
|
48
|
+
}`,
|
|
49
|
+
);
|
|
50
|
+
this.code.line(`return ${getterType.returnStatement};`);
|
|
51
|
+
this.code.closeBlock();
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
case "stored_class":
|
|
55
|
+
this.code.openBlock(`public get ${att.name}()`);
|
|
56
|
+
this.code.line(`return this.${att.storageName};`);
|
|
57
|
+
this.code.closeBlock();
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const setterType = att.setterType;
|
|
62
|
+
|
|
63
|
+
switch (setterType._type) {
|
|
64
|
+
case "set":
|
|
65
|
+
this.code.openBlock(
|
|
66
|
+
`public set ${att.name}(value: ${setterType.type})`,
|
|
67
|
+
);
|
|
68
|
+
this.code.line(`this.${att.storageName} = value;`);
|
|
69
|
+
this.code.closeBlock();
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case "put":
|
|
73
|
+
this.code.openBlock(
|
|
74
|
+
`public put${titleCase(att.name)}(value: ${setterType.type})`,
|
|
75
|
+
);
|
|
76
|
+
this.code.line(`this.${att.storageName} = value;`);
|
|
77
|
+
this.code.closeBlock();
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case "stored_class":
|
|
81
|
+
this.code.openBlock(
|
|
82
|
+
`public put${titleCase(att.name)}(value: ${setterType.type})`,
|
|
83
|
+
);
|
|
84
|
+
this.code.line(`this.${att.storageName}.internalValue = value;`);
|
|
85
|
+
this.code.closeBlock();
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (hasResetMethod) {
|
|
90
|
+
this.code.openBlock(
|
|
91
|
+
`public ${this.getResetName(att.name, escapeReset)}()`,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (setterType._type === "stored_class") {
|
|
95
|
+
this.code.line(`this.${att.storageName}.internalValue = undefined;`);
|
|
96
|
+
} else {
|
|
97
|
+
this.code.line(`this.${att.storageName} = undefined;`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this.code.closeBlock();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (hasInputMethod) {
|
|
104
|
+
this.code.line(`// Temporarily expose input value. Use with caution.`);
|
|
105
|
+
this.code.openBlock(
|
|
106
|
+
`public get ${this.getInputName(att, escapeInput)}()`,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (setterType._type === "stored_class") {
|
|
110
|
+
this.code.line(`return this.${att.storageName}.internalValue;`);
|
|
111
|
+
} else {
|
|
112
|
+
this.code.line(`return this.${att.storageName};`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.code.closeBlock();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// returns an invocation of a stored class, e.g. 'new DeplotmentMetadataOutputReference(this, "metadata")'
|
|
120
|
+
private storedClassInit(att: AttributeModel) {
|
|
121
|
+
return att.type.getStoredClassInitializer(att.terraformName);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public determineGetAttCall(att: AttributeModel): string {
|
|
125
|
+
if (att.isProvider) {
|
|
126
|
+
return `this.${att.storageName}`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return att.type.getAttributeAccessFunction(att.terraformName);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public needsInputEscape(
|
|
133
|
+
att: AttributeModel,
|
|
134
|
+
attributes: AttributeModel[],
|
|
135
|
+
): boolean {
|
|
136
|
+
return (
|
|
137
|
+
attributes.find((a) =>
|
|
138
|
+
a.terraformName.match(`^${att.terraformName}_input$`),
|
|
139
|
+
) instanceof AttributeModel
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public getInputName(att: AttributeModel, escape: boolean) {
|
|
144
|
+
if (escape) {
|
|
145
|
+
return `${att.name}TfInput`;
|
|
146
|
+
} else {
|
|
147
|
+
return `${att.name}Input`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public needsResetEscape(
|
|
152
|
+
att: AttributeModel,
|
|
153
|
+
attributes: AttributeModel[],
|
|
154
|
+
): boolean {
|
|
155
|
+
return (
|
|
156
|
+
attributes.find((a) =>
|
|
157
|
+
a.terraformName.match(`^reset_${att.terraformName}$`),
|
|
158
|
+
) instanceof AttributeModel
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public getResetName(name: string, escape: boolean) {
|
|
163
|
+
if (!name) return name;
|
|
164
|
+
if (escape) {
|
|
165
|
+
return `resetTf${titleCase(name)}`;
|
|
166
|
+
} else {
|
|
167
|
+
return `reset${titleCase(name)}`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public emitToHclTerraform(att: AttributeModel, isStruct: boolean) {
|
|
172
|
+
const type = att.type;
|
|
173
|
+
const context = isStruct ? "struct!" : "this";
|
|
174
|
+
const name = isStruct ? att.name : att.storageName;
|
|
175
|
+
const customDefault = CUSTOM_DEFAULTS[att.terraformFullName];
|
|
176
|
+
|
|
177
|
+
const varReference = `${context}.${name}${
|
|
178
|
+
!isStruct &&
|
|
179
|
+
type.isComplex &&
|
|
180
|
+
!att.isProvider &&
|
|
181
|
+
(type.struct?.isClass || att.getterType._type === "stored_class")
|
|
182
|
+
? ".internalValue"
|
|
183
|
+
: ""
|
|
184
|
+
}`;
|
|
185
|
+
const defaultCheck =
|
|
186
|
+
customDefault !== undefined
|
|
187
|
+
? `${varReference} === undefined ? ${customDefault} : `
|
|
188
|
+
: "";
|
|
189
|
+
|
|
190
|
+
const value = `${defaultCheck}${type.toHclTerraformFunction}(${varReference})`;
|
|
191
|
+
const isBlock = att.type.isComplex;
|
|
192
|
+
const tt = att.type.typeModelType;
|
|
193
|
+
|
|
194
|
+
this.code.open(`${att.terraformName}: {`);
|
|
195
|
+
this.code.line(`value: ${value},`);
|
|
196
|
+
this.code.line(`isBlock: ${isBlock},`);
|
|
197
|
+
this.code.line(`type: "${tt}",`);
|
|
198
|
+
this.code.line(`storageClassType: "${att.type.storedClassType}",`);
|
|
199
|
+
this.code.close("},");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public emitToTerraform(att: AttributeModel, isStruct: boolean) {
|
|
203
|
+
const type = att.type;
|
|
204
|
+
const context = isStruct ? "struct!" : "this";
|
|
205
|
+
const name = isStruct ? att.name : att.storageName;
|
|
206
|
+
const customDefault = CUSTOM_DEFAULTS[att.terraformFullName];
|
|
207
|
+
|
|
208
|
+
const varReference = `${context}.${name}${
|
|
209
|
+
!isStruct &&
|
|
210
|
+
type.isComplex &&
|
|
211
|
+
!att.isProvider &&
|
|
212
|
+
(type.struct?.isClass || att.getterType._type === "stored_class")
|
|
213
|
+
? ".internalValue"
|
|
214
|
+
: ""
|
|
215
|
+
}`;
|
|
216
|
+
const defaultCheck =
|
|
217
|
+
customDefault !== undefined
|
|
218
|
+
? `${varReference} === undefined ? ${customDefault} : `
|
|
219
|
+
: "";
|
|
220
|
+
|
|
221
|
+
this.code.line(
|
|
222
|
+
`${att.terraformName}: ${defaultCheck}${type.toTerraformFunction}(${varReference}),`,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// Copyright (c) HashiCorp, Inc
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
import { CodeMaker } from "codemaker";
|
|
4
|
+
import { ResourceModel } from "../models";
|
|
5
|
+
import { AttributesEmitter } from "./attributes-emitter";
|
|
6
|
+
import { sanitizedComment } from "../sanitized-comments";
|
|
7
|
+
|
|
8
|
+
export class ResourceEmitter {
|
|
9
|
+
attributesEmitter: AttributesEmitter;
|
|
10
|
+
|
|
11
|
+
constructor(private readonly code: CodeMaker) {
|
|
12
|
+
this.attributesEmitter = new AttributesEmitter(this.code);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public emit(resource: ResourceModel) {
|
|
16
|
+
this.code.line();
|
|
17
|
+
const comment = sanitizedComment(this.code);
|
|
18
|
+
comment.line(
|
|
19
|
+
`Represents a {@link ${resource.linkToDocs} ${resource.terraformResourceType}}`,
|
|
20
|
+
);
|
|
21
|
+
comment.end();
|
|
22
|
+
this.code.openBlock(
|
|
23
|
+
`export class ${resource.className} extends cdktn.${resource.parentClassName}`,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
this.emitHeader("STATIC PROPERTIES");
|
|
27
|
+
this.emitStaticProperties(resource);
|
|
28
|
+
|
|
29
|
+
this.emitHeader("STATIC Methods");
|
|
30
|
+
this.emitStaticMethods(resource);
|
|
31
|
+
|
|
32
|
+
this.emitHeader("INITIALIZER");
|
|
33
|
+
this.emitInitializer(resource);
|
|
34
|
+
|
|
35
|
+
this.emitHeader("ATTRIBUTES");
|
|
36
|
+
this.emitResourceAttributes(resource);
|
|
37
|
+
|
|
38
|
+
// synthesis
|
|
39
|
+
this.emitHeader("SYNTHESIS");
|
|
40
|
+
this.emitResourceSynthesis(resource);
|
|
41
|
+
this.emitHclResourceSynthesis(resource);
|
|
42
|
+
|
|
43
|
+
this.code.closeBlock(); // construct
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private emitHeader(title: string) {
|
|
47
|
+
this.code.line();
|
|
48
|
+
this.code.line("// " + "=".repeat(title.length));
|
|
49
|
+
this.code.line(`// ${title}`);
|
|
50
|
+
this.code.line("// " + "=".repeat(title.length));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private emitStaticProperties(resource: ResourceModel) {
|
|
54
|
+
this.code.line(
|
|
55
|
+
`public static readonly tfResourceType = "${resource.terraformResourceType}";`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private emitStaticMethods(resource: ResourceModel) {
|
|
60
|
+
const comment = sanitizedComment(this.code);
|
|
61
|
+
comment.line(
|
|
62
|
+
`Generates CDKTN code for importing a ${resource.className} resource upon running "cdktn plan <stack-name>"`,
|
|
63
|
+
);
|
|
64
|
+
comment.line(`@param scope The scope in which to define this construct`);
|
|
65
|
+
comment.line(
|
|
66
|
+
`@param importToId The construct id used in the generated config for the ${resource.className} to import`,
|
|
67
|
+
);
|
|
68
|
+
comment.line(
|
|
69
|
+
`@param importFromId The id of the existing ${resource.className} that should be imported. Refer to the {@link ${resource.linkToDocs}#import import section} in the documentation of this resource for the id to use`,
|
|
70
|
+
);
|
|
71
|
+
comment.line(
|
|
72
|
+
`@param provider? Optional instance of the provider where the ${resource.className} to import is found`,
|
|
73
|
+
);
|
|
74
|
+
comment.end();
|
|
75
|
+
this.code.line(
|
|
76
|
+
`public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktn.TerraformProvider) {
|
|
77
|
+
return new cdktn.ImportableResource(scope, importToId, { terraformResourceType: "${resource.terraformResourceType}", importId: importFromId, provider });
|
|
78
|
+
}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private emitHclResourceSynthesis(resource: ResourceModel) {
|
|
83
|
+
this.code.line();
|
|
84
|
+
this.code.openBlock(
|
|
85
|
+
`protected synthesizeHclAttributes(): { [name: string]: any }`,
|
|
86
|
+
);
|
|
87
|
+
this.code.open(`const attrs = {`);
|
|
88
|
+
|
|
89
|
+
for (const att of resource.synthesizableAttributes) {
|
|
90
|
+
this.attributesEmitter.emitToHclTerraform(att, false);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.code.close(`};`);
|
|
94
|
+
|
|
95
|
+
if (resource.synthesizableAttributes.length > 0) {
|
|
96
|
+
this.code.line();
|
|
97
|
+
this.code.line(`// remove undefined attributes`);
|
|
98
|
+
this.code.line(
|
|
99
|
+
`return Object.fromEntries(Object.entries(attrs).filter(([_, value]) => value !== undefined && value.value !== undefined ))`,
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
this.code.line(`return attrs;`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.code.closeBlock();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private emitResourceSynthesis(resource: ResourceModel) {
|
|
109
|
+
this.code.line();
|
|
110
|
+
this.code.openBlock(
|
|
111
|
+
`protected synthesizeAttributes(): { [name: string]: any }`,
|
|
112
|
+
);
|
|
113
|
+
this.code.open(`return {`);
|
|
114
|
+
|
|
115
|
+
for (const att of resource.synthesizableAttributes) {
|
|
116
|
+
this.attributesEmitter.emitToTerraform(att, false);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.code.close(`};`);
|
|
120
|
+
this.code.closeBlock();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private emitResourceAttributes(resource: ResourceModel) {
|
|
124
|
+
for (const att of resource.attributes) {
|
|
125
|
+
this.attributesEmitter.emit(
|
|
126
|
+
att,
|
|
127
|
+
this.attributesEmitter.needsResetEscape(att, resource.attributes),
|
|
128
|
+
this.attributesEmitter.needsInputEscape(att, resource.attributes),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private emitInitializer(resource: ResourceModel) {
|
|
134
|
+
this.code.line();
|
|
135
|
+
const comment = sanitizedComment(this.code);
|
|
136
|
+
comment.line(
|
|
137
|
+
`Create a new {@link ${resource.linkToDocs} ${
|
|
138
|
+
resource.terraformResourceType
|
|
139
|
+
}} ${resource.isDataSource ? "Data Source" : "Resource"}`,
|
|
140
|
+
);
|
|
141
|
+
comment.line(``);
|
|
142
|
+
comment.line(`@param scope The scope in which to define this construct`);
|
|
143
|
+
comment.line(
|
|
144
|
+
`@param id The scoped construct ID. Must be unique amongst siblings in the same scope`,
|
|
145
|
+
);
|
|
146
|
+
comment.line(`@param options ${resource.configStruct.attributeType}`);
|
|
147
|
+
comment.end();
|
|
148
|
+
this.code.openBlock(
|
|
149
|
+
`public constructor(scope: Construct, id: string, config: ${resource.configStruct.attributeType})`,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (resource.isProvider) {
|
|
153
|
+
this.emitProviderSuper(resource);
|
|
154
|
+
} else {
|
|
155
|
+
this.emitResourceSuper(resource);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// initialize config properties
|
|
159
|
+
for (const att of resource.configStruct.assignableAttributes) {
|
|
160
|
+
if (att.setterType._type === "stored_class") {
|
|
161
|
+
this.code.line(
|
|
162
|
+
`this.${att.storageName}.internalValue = config.${att.name};`,
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
this.code.line(`this.${att.storageName} = config.${att.name};`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.code.closeBlock();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private emitResourceSuper(resource: ResourceModel) {
|
|
173
|
+
this.code.open(`super(scope, id, {`);
|
|
174
|
+
this.code.line(
|
|
175
|
+
`terraformResourceType: '${resource.terraformResourceType}',`,
|
|
176
|
+
);
|
|
177
|
+
this.emitTerraformGeneratorMetadata(resource);
|
|
178
|
+
this.code.line(`provider: config.provider,`);
|
|
179
|
+
this.code.line(`dependsOn: config.dependsOn,`);
|
|
180
|
+
this.code.line(`count: config.count,`);
|
|
181
|
+
this.code.line(`lifecycle: config.lifecycle,`);
|
|
182
|
+
this.code.line(`provisioners: config.provisioners,`);
|
|
183
|
+
this.code.line(`connection: config.connection,`);
|
|
184
|
+
this.code.line(`forEach: config.forEach`);
|
|
185
|
+
this.code.close(`});`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private emitProviderSuper(resource: ResourceModel) {
|
|
189
|
+
this.code.open(`super(scope, id, {`);
|
|
190
|
+
this.code.line(
|
|
191
|
+
`terraformResourceType: '${resource.terraformResourceType}',`,
|
|
192
|
+
);
|
|
193
|
+
this.emitTerraformGeneratorMetadata(resource);
|
|
194
|
+
this.code.line(
|
|
195
|
+
`terraformProviderSource: '${resource.terraformProviderSource}'`,
|
|
196
|
+
);
|
|
197
|
+
this.code.close(`});`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private emitTerraformGeneratorMetadata(resource: ResourceModel) {
|
|
201
|
+
this.code.open(`terraformGeneratorMetadata: {`);
|
|
202
|
+
this.code.line(
|
|
203
|
+
`providerName: '${resource.provider}'${
|
|
204
|
+
resource.providerVersion || resource.providerVersionConstraint
|
|
205
|
+
? ","
|
|
206
|
+
: ""
|
|
207
|
+
}`,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (resource.providerVersion) {
|
|
211
|
+
this.code.line(
|
|
212
|
+
`providerVersion: '${resource.providerVersion}'${
|
|
213
|
+
resource.providerVersionConstraint ? "," : ""
|
|
214
|
+
}`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (resource.providerVersionConstraint) {
|
|
219
|
+
this.code.line(
|
|
220
|
+
`providerVersionConstraint: '${resource.providerVersionConstraint}'`,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this.code.close(`},`);
|
|
225
|
+
}
|
|
226
|
+
}
|