@cdktn/hcl2cdk 0.24.0-pre.5 → 0.24.0-pre.51

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.
Files changed (83) hide show
  1. package/.spec.swcrc +22 -0
  2. package/LICENSE +355 -0
  3. package/README.md +1 -1
  4. package/build/__tests__/jsii-rosetta-workarounds.test.js +2 -2
  5. package/build/expressions.js +3 -4
  6. package/build/function-bindings/functions.generated.js +2 -2
  7. package/build/generation.js +2 -2
  8. package/build/index.d.ts +20 -20
  9. package/build/index.js +4 -4
  10. package/build/references.js +2 -3
  11. package/build/schema.d.ts +60 -60
  12. package/build/utils.d.ts +1 -1
  13. package/build/utils.js +3 -3
  14. package/jest.config.js +18 -11
  15. package/package.json +37 -25
  16. package/package.sh +1 -1
  17. package/src/__tests__/coerceType.test.ts +207 -0
  18. package/src/__tests__/expressionToTs.test.ts +1167 -0
  19. package/src/__tests__/expressions.test.ts +541 -0
  20. package/src/__tests__/findExpressionType.test.ts +112 -0
  21. package/src/__tests__/functions.test.ts +768 -0
  22. package/src/__tests__/generation.test.ts +72 -0
  23. package/src/__tests__/jsii-rosetta-workarounds.test.ts +145 -0
  24. package/src/__tests__/partialCode.test.ts +432 -0
  25. package/src/__tests__/terraformSchema.test.ts +107 -0
  26. package/src/__tests__/testHelpers.ts +11 -0
  27. package/src/coerceType.ts +261 -0
  28. package/src/dynamic-blocks.ts +61 -0
  29. package/src/expressions.ts +968 -0
  30. package/src/function-bindings/functions.generated.ts +1139 -0
  31. package/src/function-bindings/functions.ts +104 -0
  32. package/src/generation.ts +1189 -0
  33. package/src/index.ts +584 -0
  34. package/src/iteration.ts +156 -0
  35. package/src/jsii-rosetta-workarounds.ts +145 -0
  36. package/src/partialCode.ts +132 -0
  37. package/src/provider.ts +60 -0
  38. package/src/references.ts +193 -0
  39. package/src/schema.ts +74 -0
  40. package/src/terraformSchema.ts +182 -0
  41. package/src/types.ts +58 -0
  42. package/src/utils.ts +19 -0
  43. package/src/variables.ts +214 -0
  44. package/test/__snapshots__/backends.test.ts.snap +70 -0
  45. package/test/__snapshots__/externals.test.ts.snap +37 -0
  46. package/test/__snapshots__/granular-imports.test.ts.snap +180 -0
  47. package/test/__snapshots__/imports.test.ts.snap +159 -0
  48. package/test/__snapshots__/iteration.test.ts.snap +532 -0
  49. package/test/__snapshots__/jsiiLanguage.test.ts.snap +347 -0
  50. package/test/__snapshots__/locals.test.ts.snap +55 -0
  51. package/test/__snapshots__/modules.test.ts.snap +127 -0
  52. package/test/__snapshots__/outputs.test.ts.snap +77 -0
  53. package/test/__snapshots__/partialCode.test.ts.snap +120 -0
  54. package/test/__snapshots__/provider.test.ts.snap +128 -0
  55. package/test/__snapshots__/references.test.ts.snap +376 -0
  56. package/test/__snapshots__/resource-meta-properties.test.ts.snap +342 -0
  57. package/test/__snapshots__/resources.test.ts.snap +613 -0
  58. package/test/__snapshots__/tfExpressions.test.ts.snap +537 -0
  59. package/test/__snapshots__/typeCoercion.test.ts.snap +253 -0
  60. package/test/__snapshots__/variables.test.ts.snap +150 -0
  61. package/test/backends.test.ts +75 -0
  62. package/test/convertProject.test.ts +257 -0
  63. package/test/externals.test.ts +35 -0
  64. package/test/globalSetup.ts +224 -0
  65. package/test/globalTeardown.ts +11 -0
  66. package/test/granular-imports.test.ts +161 -0
  67. package/test/hcl2cdk.test.ts +88 -0
  68. package/test/helpers/convert.ts +543 -0
  69. package/test/helpers/tmp.ts +25 -0
  70. package/test/imports.test.ts +141 -0
  71. package/test/iteration.test.ts +342 -0
  72. package/test/jsiiLanguage.test.ts +73 -0
  73. package/test/locals.test.ts +47 -0
  74. package/test/modules.test.ts +143 -0
  75. package/test/outputs.test.ts +69 -0
  76. package/test/partialCode.test.ts +25 -0
  77. package/test/provider.test.ts +106 -0
  78. package/test/references.test.ts +287 -0
  79. package/test/resource-meta-properties.test.ts +288 -0
  80. package/test/resources.test.ts +551 -0
  81. package/test/tfExpressions.test.ts +300 -0
  82. package/test/typeCoercion.test.ts +154 -0
  83. package/test/variables.test.ts +96 -0
@@ -0,0 +1,342 @@
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
+
3
+ exports[`meta-properties depends_on depends on snapshot typescript 1`] = `
4
+ "import { Construct } from "constructs";
5
+ import { Fn, Token, TerraformStack } from "cdktn";
6
+ /*
7
+ * Provider bindings are generated by running \`cdktn get\`.
8
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
9
+ */
10
+ import { IamRolePolicy } from "./.gen/providers/aws/iam-role-policy";
11
+ import { Instance } from "./.gen/providers/aws/instance";
12
+ import { AwsProvider } from "./.gen/providers/aws/provider";
13
+ class MyConvertedCode extends TerraformStack {
14
+ constructor(scope: Construct, name: string) {
15
+ super(scope, name);
16
+ new AwsProvider(this, "aws", {
17
+ region: "us-east-1",
18
+ });
19
+ const example = new IamRolePolicy(this, "example", {
20
+ name: "example",
21
+ policy: Token.asString(
22
+ Fn.jsonencode({
23
+ Statement: [
24
+ {
25
+ Action: "s3:*",
26
+ Effect: "Allow",
27
+ },
28
+ ],
29
+ })
30
+ ),
31
+ role: "role",
32
+ });
33
+ const awsInstanceExample = new Instance(this, "example_2", {
34
+ ami: "ami-a1b2c3d4",
35
+ dependsOn: [example],
36
+ iamInstanceProfile: "aws_iam_instance_profile",
37
+ instanceType: "t2.micro",
38
+ });
39
+ /*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
40
+ awsInstanceExample.overrideLogicalId("example");
41
+ }
42
+ }
43
+ "
44
+ `;
45
+
46
+ exports[`meta-properties lifecycle all lifecycle properties snapshot typescript 1`] = `
47
+ "import { Construct } from "constructs";
48
+ import { Fn, Token, TerraformStack } from "cdktn";
49
+ /*
50
+ * Provider bindings are generated by running \`cdktn get\`.
51
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
52
+ */
53
+ import { IamRolePolicy } from "./.gen/providers/aws/iam-role-policy";
54
+ import { Instance } from "./.gen/providers/aws/instance";
55
+ import { AwsProvider } from "./.gen/providers/aws/provider";
56
+ class MyConvertedCode extends TerraformStack {
57
+ constructor(scope: Construct, name: string) {
58
+ super(scope, name);
59
+ new AwsProvider(this, "aws", {
60
+ region: "us-east-1",
61
+ });
62
+ const example = new IamRolePolicy(this, "example", {
63
+ name: "example",
64
+ policy: Token.asString(
65
+ Fn.jsonencode({
66
+ Statement: [
67
+ {
68
+ Action: "s3:*",
69
+ Effect: "Allow",
70
+ },
71
+ ],
72
+ })
73
+ ),
74
+ role: "role",
75
+ });
76
+ const awsInstanceExample = new Instance(this, "example_2", {
77
+ ami: "ami-a1b2c3d4",
78
+ iamInstanceProfile: "aws_iam_instance_profile",
79
+ instanceType: "t2.micro",
80
+ lifecycle: {
81
+ createBeforeDestroy: true,
82
+ ignoreChanges: ["ami", "instance_type"],
83
+ preventDestroy: true,
84
+ replaceTriggeredBy: [example.id],
85
+ },
86
+ });
87
+ /*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
88
+ awsInstanceExample.overrideLogicalId("example");
89
+ }
90
+ }
91
+ "
92
+ `;
93
+
94
+ exports[`meta-properties lifecycle preconditions and postconditions snapshot typescript 1`] = `
95
+ "import { Construct } from "constructs";
96
+ import { TerraformSelf, Op, TerraformStack } from "cdktn";
97
+ /*
98
+ * Provider bindings are generated by running \`cdktn get\`.
99
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
100
+ */
101
+ import { Instance } from "./.gen/providers/aws/instance";
102
+ import { AwsProvider } from "./.gen/providers/aws/provider";
103
+ class MyConvertedCode extends TerraformStack {
104
+ constructor(scope: Construct, name: string) {
105
+ super(scope, name);
106
+ new AwsProvider(this, "aws", {
107
+ region: "us-east-1",
108
+ });
109
+ new Instance(this, "example", {
110
+ ami: "ami-a1b2c3d4",
111
+ iamInstanceProfile: "aws_iam_instance_profile",
112
+ instanceType: "t2.micro",
113
+ lifecycle: {
114
+ postcondition: [
115
+ {
116
+ condition: Op.neq(TerraformSelf.getAny("public_dns"), ""),
117
+ errorMessage:
118
+ "EC2 instance must be in a VPC that has public DNS hostnames enabled.",
119
+ },
120
+ ],
121
+ precondition: [
122
+ {
123
+ condition: Op.eq(
124
+ TerraformSelf.getAny('tags["Component"]'),
125
+ "nomad-server"
126
+ ),
127
+ errorMessage: "Please add the nomad-server tag to this instance.",
128
+ },
129
+ ],
130
+ },
131
+ });
132
+ }
133
+ }
134
+ "
135
+ `;
136
+
137
+ exports[`meta-properties provider passing providers snapshot typescript 1`] = `
138
+ "import { Construct } from "constructs";
139
+ import { TerraformStack } from "cdktn";
140
+ /*
141
+ * Provider bindings are generated by running \`cdktn get\`.
142
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
143
+ */
144
+ import { ComputeInstance } from "./.gen/providers/google/compute-instance";
145
+ import { GoogleProvider } from "./.gen/providers/google/provider";
146
+ class MyConvertedCode extends TerraformStack {
147
+ constructor(scope: Construct, name: string) {
148
+ super(scope, name);
149
+ new GoogleProvider(this, "google", {
150
+ region: "us-central1",
151
+ });
152
+ const europe = new GoogleProvider(this, "google_1", {
153
+ alias: "europe",
154
+ region: "europe-west1",
155
+ });
156
+ new ComputeInstance(this, "default", {
157
+ bootDisk: {
158
+ initializeParams: {
159
+ image: "debian-cloud/debian-11",
160
+ labels: {
161
+ my_label: "value",
162
+ },
163
+ },
164
+ },
165
+ machineType: "e2-medium",
166
+ metadata: {
167
+ foo: "bar",
168
+ },
169
+ metadataStartupScript: "echo hi > /test.txt",
170
+ name: "test",
171
+ networkInterface: [
172
+ {
173
+ accessConfig: [{}],
174
+ network: "default",
175
+ },
176
+ ],
177
+ provider: europe,
178
+ scratchDisk: [
179
+ {
180
+ interface: "SCSI",
181
+ },
182
+ ],
183
+ tags: ["foo", "bar"],
184
+ zone: "us-central1-a",
185
+ });
186
+ }
187
+ }
188
+ "
189
+ `;
190
+
191
+ exports[`meta-properties provisioner file snapshot typescript 1`] = `
192
+ "import { Construct } from "constructs";
193
+ import { TerraformSelf, Token, TerraformStack } from "cdktn";
194
+ /*
195
+ * Provider bindings are generated by running \`cdktn get\`.
196
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
197
+ */
198
+ import { Instance } from "./.gen/providers/aws/instance";
199
+ import { AwsProvider } from "./.gen/providers/aws/provider";
200
+ class MyConvertedCode extends TerraformStack {
201
+ constructor(scope: Construct, name: string) {
202
+ super(scope, name);
203
+ new AwsProvider(this, "aws", {
204
+ region: "us-east-1",
205
+ });
206
+ new Instance(this, "example", {
207
+ ami: "ami-a1b2c3d4",
208
+ iamInstanceProfile: "aws_iam_instance_profile",
209
+ instanceType: "t2.micro",
210
+ provisioners: [
211
+ {
212
+ type: "file",
213
+ destination: "/etc/myapp.conf",
214
+ source: "conf/myapp.conf",
215
+ },
216
+ {
217
+ type: "file",
218
+ content: "ami used: " + Token.asString(TerraformSelf.getAny("ami")),
219
+ destination: "/tmp/file.log",
220
+ },
221
+ ],
222
+ });
223
+ }
224
+ }
225
+ "
226
+ `;
227
+
228
+ exports[`meta-properties provisioner local-exec snapshot typescript 1`] = `
229
+ "import { Construct } from "constructs";
230
+ import { TerraformSelf, Token, TerraformStack } from "cdktn";
231
+ /*
232
+ * Provider bindings are generated by running \`cdktn get\`.
233
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
234
+ */
235
+ import { Instance } from "./.gen/providers/aws/instance";
236
+ import { AwsProvider } from "./.gen/providers/aws/provider";
237
+ class MyConvertedCode extends TerraformStack {
238
+ constructor(scope: Construct, name: string) {
239
+ super(scope, name);
240
+ new AwsProvider(this, "aws", {
241
+ region: "us-east-1",
242
+ });
243
+ new Instance(this, "example", {
244
+ ami: "ami-a1b2c3d4",
245
+ iamInstanceProfile: "aws_iam_instance_profile",
246
+ instanceType: "t2.micro",
247
+ provisioners: [
248
+ {
249
+ type: "local-exec",
250
+ command:
251
+ "echo " +
252
+ Token.asString(TerraformSelf.getAny("private_ip")) +
253
+ " >> private_ips.txt",
254
+ },
255
+ ],
256
+ });
257
+ }
258
+ }
259
+ "
260
+ `;
261
+
262
+ exports[`meta-properties provisioner remote-exec with connection block snapshot typescript 1`] = `
263
+ "import { Construct } from "constructs";
264
+ import { TerraformSelf, TerraformStack } from "cdktn";
265
+ /*
266
+ * Provider bindings are generated by running \`cdktn get\`.
267
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
268
+ */
269
+ import { Instance } from "./.gen/providers/aws/instance";
270
+ import { AwsProvider } from "./.gen/providers/aws/provider";
271
+ class MyConvertedCode extends TerraformStack {
272
+ constructor(scope: Construct, name: string) {
273
+ super(scope, name);
274
+ new AwsProvider(this, "aws", {
275
+ region: "us-east-1",
276
+ });
277
+ const web = new Instance(this, "web", {
278
+ ami: "ami-a1b2c3d4",
279
+ instanceType: "t2.micro",
280
+ });
281
+ new Instance(this, "example", {
282
+ ami: "ami-a1b2c3d4",
283
+ iamInstanceProfile: "aws_iam_instance_profile",
284
+ instanceType: "t2.micro",
285
+ provisioners: [
286
+ {
287
+ type: "remote-exec",
288
+ connection: {
289
+ host: TerraformSelf.getAny("public_ip"),
290
+ password: "password",
291
+ type: "ssh",
292
+ user: "root",
293
+ },
294
+ inline: ["puppet apply", "consul join \${" + web.privateIp + "}"],
295
+ },
296
+ ],
297
+ });
298
+ }
299
+ }
300
+ "
301
+ `;
302
+
303
+ exports[`meta-properties provisioner remote-exec with global connection block snapshot typescript 1`] = `
304
+ "import { Construct } from "constructs";
305
+ import { TerraformSelf, TerraformStack } from "cdktn";
306
+ /*
307
+ * Provider bindings are generated by running \`cdktn get\`.
308
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
309
+ */
310
+ import { Instance } from "./.gen/providers/aws/instance";
311
+ import { AwsProvider } from "./.gen/providers/aws/provider";
312
+ class MyConvertedCode extends TerraformStack {
313
+ constructor(scope: Construct, name: string) {
314
+ super(scope, name);
315
+ new AwsProvider(this, "aws", {
316
+ region: "us-east-1",
317
+ });
318
+ const web = new Instance(this, "web", {
319
+ ami: "ami-a1b2c3d4",
320
+ instanceType: "t2.micro",
321
+ });
322
+ new Instance(this, "example", {
323
+ ami: "ami-a1b2c3d4",
324
+ connection: {
325
+ host: TerraformSelf.getAny("public_ip"),
326
+ password: "password",
327
+ type: "ssh",
328
+ user: "root",
329
+ },
330
+ iamInstanceProfile: "aws_iam_instance_profile",
331
+ instanceType: "t2.micro",
332
+ provisioners: [
333
+ {
334
+ type: "remote-exec",
335
+ inline: ["puppet apply", "consul join \${" + web.privateIp + "}"],
336
+ },
337
+ ],
338
+ });
339
+ }
340
+ }
341
+ "
342
+ `;