@cdktn/hcl2cdk 0.25.0-pre.9 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +12 -0
  2. package/build/coerceType.js +21 -11
  3. package/build/dynamic-blocks.js +3 -3
  4. package/build/expressions.js +24 -17
  5. package/build/generation.js +34 -24
  6. package/build/index.js +27 -17
  7. package/build/iteration.js +6 -7
  8. package/build/jsii-rosetta-workarounds.js +5 -6
  9. package/build/partialCode.js +20 -11
  10. package/build/provider.js +3 -4
  11. package/build/references.js +5 -6
  12. package/build/schema.js +18 -8
  13. package/build/terraformSchema.js +4 -4
  14. package/build/utils.js +3 -3
  15. package/build/variables.js +21 -12
  16. package/package.json +18 -17
  17. package/.spec.swcrc +0 -22
  18. package/build/__tests__/coerceType.test.d.ts +0 -2
  19. package/build/__tests__/coerceType.test.js +0 -165
  20. package/build/__tests__/expressionToTs.test.d.ts +0 -6
  21. package/build/__tests__/expressionToTs.test.js +0 -693
  22. package/build/__tests__/expressions.test.d.ts +0 -4
  23. package/build/__tests__/expressions.test.js +0 -415
  24. package/build/__tests__/findExpressionType.test.d.ts +0 -6
  25. package/build/__tests__/findExpressionType.test.js +0 -105
  26. package/build/__tests__/functions.test.d.ts +0 -6
  27. package/build/__tests__/functions.test.js +0 -605
  28. package/build/__tests__/generation.test.d.ts +0 -6
  29. package/build/__tests__/generation.test.js +0 -45
  30. package/build/__tests__/jsii-rosetta-workarounds.test.d.ts +0 -2
  31. package/build/__tests__/jsii-rosetta-workarounds.test.js +0 -86
  32. package/build/__tests__/partialCode.test.d.ts +0 -6
  33. package/build/__tests__/partialCode.test.js +0 -390
  34. package/build/__tests__/terraformSchema.test.d.ts +0 -6
  35. package/build/__tests__/terraformSchema.test.js +0 -105
  36. package/build/__tests__/testHelpers.d.ts +0 -7
  37. package/build/__tests__/testHelpers.js +0 -16
  38. package/jest.config.js +0 -25
  39. package/package.sh +0 -9
  40. package/src/__tests__/coerceType.test.ts +0 -207
  41. package/src/__tests__/expressionToTs.test.ts +0 -1167
  42. package/src/__tests__/expressions.test.ts +0 -541
  43. package/src/__tests__/findExpressionType.test.ts +0 -112
  44. package/src/__tests__/functions.test.ts +0 -768
  45. package/src/__tests__/generation.test.ts +0 -72
  46. package/src/__tests__/jsii-rosetta-workarounds.test.ts +0 -145
  47. package/src/__tests__/partialCode.test.ts +0 -432
  48. package/src/__tests__/terraformSchema.test.ts +0 -107
  49. package/src/__tests__/testHelpers.ts +0 -11
  50. package/src/coerceType.ts +0 -261
  51. package/src/dynamic-blocks.ts +0 -61
  52. package/src/expressions.ts +0 -968
  53. package/src/function-bindings/functions.generated.ts +0 -1211
  54. package/src/function-bindings/functions.ts +0 -104
  55. package/src/generation.ts +0 -1189
  56. package/src/index.ts +0 -584
  57. package/src/iteration.ts +0 -156
  58. package/src/jsii-rosetta-workarounds.ts +0 -145
  59. package/src/partialCode.ts +0 -132
  60. package/src/provider.ts +0 -60
  61. package/src/references.ts +0 -193
  62. package/src/schema.ts +0 -74
  63. package/src/terraformSchema.ts +0 -182
  64. package/src/types.ts +0 -58
  65. package/src/utils.ts +0 -19
  66. package/src/variables.ts +0 -214
  67. package/test/__snapshots__/backends.test.ts.snap +0 -70
  68. package/test/__snapshots__/externals.test.ts.snap +0 -37
  69. package/test/__snapshots__/granular-imports.test.ts.snap +0 -180
  70. package/test/__snapshots__/imports.test.ts.snap +0 -159
  71. package/test/__snapshots__/iteration.test.ts.snap +0 -532
  72. package/test/__snapshots__/jsiiLanguage.test.ts.snap +0 -347
  73. package/test/__snapshots__/locals.test.ts.snap +0 -55
  74. package/test/__snapshots__/modules.test.ts.snap +0 -127
  75. package/test/__snapshots__/outputs.test.ts.snap +0 -77
  76. package/test/__snapshots__/partialCode.test.ts.snap +0 -120
  77. package/test/__snapshots__/provider.test.ts.snap +0 -128
  78. package/test/__snapshots__/references.test.ts.snap +0 -376
  79. package/test/__snapshots__/resource-meta-properties.test.ts.snap +0 -342
  80. package/test/__snapshots__/resources.test.ts.snap +0 -613
  81. package/test/__snapshots__/tfExpressions.test.ts.snap +0 -537
  82. package/test/__snapshots__/typeCoercion.test.ts.snap +0 -253
  83. package/test/__snapshots__/variables.test.ts.snap +0 -150
  84. package/test/backends.test.ts +0 -75
  85. package/test/convertProject.test.ts +0 -257
  86. package/test/externals.test.ts +0 -35
  87. package/test/globalSetup.ts +0 -224
  88. package/test/globalTeardown.ts +0 -11
  89. package/test/granular-imports.test.ts +0 -161
  90. package/test/hcl2cdk.test.ts +0 -88
  91. package/test/helpers/convert.ts +0 -544
  92. package/test/helpers/tmp.ts +0 -40
  93. package/test/imports.test.ts +0 -141
  94. package/test/iteration.test.ts +0 -342
  95. package/test/jsiiLanguage.test.ts +0 -73
  96. package/test/locals.test.ts +0 -47
  97. package/test/modules.test.ts +0 -143
  98. package/test/outputs.test.ts +0 -69
  99. package/test/partialCode.test.ts +0 -25
  100. package/test/provider.test.ts +0 -106
  101. package/test/references.test.ts +0 -287
  102. package/test/resource-meta-properties.test.ts +0 -288
  103. package/test/resources.test.ts +0 -551
  104. package/test/tfExpressions.test.ts +0 -300
  105. package/test/typeCoercion.test.ts +0 -154
  106. package/test/variables.test.ts +0 -96
  107. package/tsconfig.json +0 -43
@@ -1,551 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { testCase, Synth, binding, Snapshot } from "./helpers/convert";
7
-
8
- describe("resources", () => {
9
- testCase.test(
10
- "simple resource",
11
- `
12
- provider "aws" {
13
- region = "us-east-1"
14
- }
15
- resource "aws_vpc" "example" {
16
- cidr_block = "10.0.0.0/16"
17
- }`,
18
- [binding.aws],
19
- Snapshot.yes,
20
- Synth.yes,
21
- {
22
- resources: ["aws_vpc"],
23
- },
24
- );
25
-
26
- testCase.test(
27
- "complex resource",
28
- `
29
- provider "aws" {
30
- region = "us-east-1"
31
- }
32
- resource "aws_cloudfront_distribution" "s3_distribution" {
33
- origin {
34
- domain_name = "aws_s3_bucket.b.bucket_regional_domain_name"
35
- origin_id = "local_s3_origin_id"
36
-
37
- s3_origin_config {
38
- origin_access_identity = "origin-access-identity/cloudfront/ABCDEFG1234567"
39
- }
40
- }
41
-
42
- enabled = true
43
- is_ipv6_enabled = true
44
- comment = "Some comment"
45
- default_root_object = "index.html"
46
-
47
- logging_config {
48
- include_cookies = false
49
- bucket = "mylogs.s3.amazonaws.com"
50
- prefix = "myprefix"
51
- }
52
-
53
- aliases = ["mysite.example.com", "yoursite.example.com"]
54
-
55
- default_cache_behavior {
56
- allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
57
- cached_methods = ["GET", "HEAD"]
58
- target_origin_id = "local_s3_origin_id"
59
-
60
- forwarded_values {
61
- query_string = false
62
-
63
- cookies {
64
- forward = "none"
65
- }
66
- }
67
-
68
- viewer_protocol_policy = "allow-all"
69
- min_ttl = 0
70
- default_ttl = 3600
71
- max_ttl = 86400
72
- }
73
-
74
- # Cache behavior with precedence 0
75
- ordered_cache_behavior {
76
- path_pattern = "/content/immutable/*"
77
- allowed_methods = ["GET", "HEAD", "OPTIONS"]
78
- cached_methods = ["GET", "HEAD", "OPTIONS"]
79
- target_origin_id = "local_s3_origin_id"
80
-
81
- forwarded_values {
82
- query_string = false
83
- headers = ["Origin"]
84
-
85
- cookies {
86
- forward = "none"
87
- }
88
- }
89
-
90
- min_ttl = 0
91
- default_ttl = 86400
92
- max_ttl = 31536000
93
- compress = true
94
- viewer_protocol_policy = "redirect-to-https"
95
- }
96
-
97
- # Cache behavior with precedence 1
98
- ordered_cache_behavior {
99
- path_pattern = "/content/*"
100
- allowed_methods = ["GET", "HEAD", "OPTIONS"]
101
- cached_methods = ["GET", "HEAD"]
102
- target_origin_id = "local_s3_origin_id"
103
-
104
- forwarded_values {
105
- query_string = false
106
-
107
- cookies {
108
- forward = "none"
109
- }
110
- }
111
-
112
- min_ttl = 0
113
- default_ttl = 3600
114
- max_ttl = 86400
115
- compress = true
116
- viewer_protocol_policy = "redirect-to-https"
117
- }
118
-
119
- price_class = "PriceClass_200"
120
-
121
- restrictions {
122
- geo_restriction {
123
- restriction_type = "whitelist"
124
- locations = ["US", "CA", "GB", "DE"]
125
- }
126
- }
127
-
128
- tags = {
129
- Environment = "production"
130
- }
131
-
132
- viewer_certificate {
133
- cloudfront_default_certificate = true
134
- }
135
- }`,
136
- [binding.aws],
137
- Snapshot.yes,
138
- Synth.yes,
139
- {
140
- resources: ["aws_cloudfront_distribution"],
141
- },
142
- );
143
-
144
- testCase.test(
145
- "simple data source",
146
- `
147
- provider "aws" {
148
- region = "us-east-1"
149
- }
150
- data "aws_subnet" "selected" {
151
- vpc_id = "subnet_id"
152
- }`,
153
- [binding.aws],
154
- Snapshot.yes,
155
- Synth.yes,
156
- {
157
- dataSources: ["aws_subnet"],
158
- },
159
- );
160
-
161
- testCase.test(
162
- "multiple blocks",
163
- `
164
- provider "aws" {
165
- region = "us-east-1"
166
- }
167
- resource "aws_security_group" "allow_tls" {
168
- name = "allow_tls"
169
- description = "Allow TLS inbound traffic"
170
-
171
- ingress {
172
- description = "TLS from VPC"
173
- from_port = 443
174
- to_port = 443
175
- protocol = "tcp"
176
- }
177
-
178
- ingress {
179
- description = "TLS from VPC"
180
- from_port = 80
181
- to_port = 80
182
- protocol = "tcp"
183
- }
184
-
185
- ingress {
186
- from_port = 8080
187
- to_port = 8080
188
- protocol = "tcp"
189
- }
190
-
191
- egress {
192
- from_port = 0
193
- to_port = 0
194
- protocol = "-1"
195
- cidr_blocks = ["0.0.0.0/0"]
196
- ipv6_cidr_blocks = ["::/0"]
197
- }
198
-
199
- tags = {
200
- Name = "allow_tls"
201
- }
202
- }`,
203
- [binding.aws],
204
- Snapshot.yes,
205
- Synth.yes,
206
- {
207
- resources: ["aws_security_group"],
208
- },
209
- );
210
-
211
- testCase.test(
212
- "blocks should be arrays",
213
- `
214
- provider "google" {
215
- project = "my-project"
216
- region = "us-central1"
217
- }
218
- resource "google_compute_autoscaler" "example" {
219
- name = "example-autoscaler"
220
- zone = "us-east1-b"
221
- target = "target-for-example-autoscaler"
222
-
223
- autoscaling_policy = {
224
- max_replicas = 8
225
- min_replicas = 2
226
- cooldown_period = 60
227
-
228
- cpu_utilization = {
229
- target = 0.5
230
- }
231
- }
232
- }
233
- `,
234
- [binding.google],
235
- Snapshot.yes,
236
- Synth.yes,
237
- {
238
- resources: ["google_compute_autoscaler"],
239
- },
240
- );
241
-
242
- testCase.test(
243
- "maps are not arrays",
244
- `
245
- provider "kubernetes" {
246
- config_path = "~/.kube/config"
247
- config_context = "my-context"
248
- }
249
-
250
- resource "kubernetes_secret" "secrets-xxx" {
251
- metadata {
252
- name = "secrets-xxx"
253
- }
254
- data = {
255
- "xxx" : "yyy"
256
- }
257
- }
258
- `,
259
- [binding.kubernetes],
260
- Snapshot.yes,
261
- Synth.yes,
262
- {
263
- resources: ["kubernetes_secret"],
264
- },
265
- );
266
-
267
- testCase.test(
268
- "maps dont get camel case keys",
269
- `
270
- provider "kubernetes" {
271
- config_path = "~/.kube/config"
272
- config_context = "my-context"
273
- }
274
-
275
- resource "kubernetes_secret" "secrets-xxx" {
276
- metadata {
277
- name = "secrets-xxx"
278
- }
279
- data = {
280
- "camel_cased_key": "yes"
281
- }
282
- }
283
- `,
284
- [binding.kubernetes],
285
- Snapshot.yes,
286
- Synth.yes,
287
- {
288
- resources: ["kubernetes_secret"],
289
- },
290
- );
291
-
292
- testCase.test(
293
- "same name local, var, out",
294
- `
295
- variable "test" {
296
- type = string
297
- }
298
- locals {
299
- test = "\${var.test} + 1"
300
- }
301
- output "test" {
302
- value = "\${local.test}"
303
- }
304
- `,
305
- [],
306
- Snapshot.yes,
307
- Synth.yes,
308
- );
309
-
310
- testCase.test(
311
- "property level renamings",
312
- `
313
- provider "aws" {
314
- region = "us-east-1"
315
- }
316
- resource "aws_guardduty_filter" "MyFilter" {
317
- name = "MyFilter"
318
- action = "ARCHIVE"
319
- detector_id = "id"
320
- rank = 1
321
-
322
- finding_criteria {
323
- criterion {
324
- field = "region"
325
- equals = ["eu-west-1"]
326
- }
327
-
328
- criterion {
329
- field = "service.additionalInfo.threatListName"
330
- not_equals = ["some-threat", "another-threat"]
331
- }
332
-
333
- criterion {
334
- field = "updatedAt"
335
- greater_than = "2020-01-01T00:00:00Z"
336
- less_than = "2020-02-01T00:00:00Z"
337
- }
338
-
339
- criterion {
340
- field = "severity"
341
- greater_than_or_equal = "4"
342
- }
343
- }
344
- }
345
- `,
346
- [binding.aws],
347
- Snapshot.yes,
348
- Synth.yes,
349
- {
350
- resources: ["aws_guardduty_filter"],
351
- },
352
- );
353
-
354
- testCase.test(
355
- "tricky to parse items",
356
- `
357
- provider "aws" {
358
- region = "us-east-1"
359
- }
360
- variable "tags" {
361
- type = map
362
- }
363
-
364
-
365
- resource "aws_instance" "play" {
366
- ami = join("-", [var.tags.app, var.tags.env])
367
- instance_type = "t3.small"
368
- key_name = aws_key_pair.master_key.id
369
- vpc_security_group_ids = [aws_security_group.ssh.id]
370
- subnet_id = aws_subnet.main.id
371
- associate_public_ip_address = true
372
-
373
- connection {
374
- type = "ssh"
375
- user = "ubuntu"
376
- private_key = file("./terraform_key")
377
- host = self.public_ip
378
- }
379
- }
380
- `,
381
- [binding.aws],
382
- Snapshot.yes,
383
- Synth.never,
384
- {
385
- resources: ["aws_instance"],
386
- },
387
- );
388
-
389
- /**
390
- * Test for https://github.com/hashicorp/terraform-cdk/issues/2139
391
- *
392
- * This one currently fails because the convertion result looks like this:
393
- * new scaleway.object.ObjectResource(this, "some_file", { ...
394
- *
395
- * Which should be:
396
- * new scaleway.objectResource.ObjectResource(this, "some_file", { ...
397
- *
398
- * So it does already work for the class name but not for the namespace.
399
- */
400
- testCase.test(
401
- "handle special resource names",
402
- `
403
- provider "scaleway" {
404
- zone = "fr-par-1"
405
- region = "fr-par"
406
- }
407
-
408
- resource "scaleway_object_bucket" "some_bucket" {
409
- name = "some-unique-name"
410
- }
411
-
412
- resource scaleway_object "some_file" {
413
- bucket = scaleway_object_bucket.some_bucket.name
414
- key = "object_path"
415
-
416
- file = "myfile"
417
- hash = filemd5("myfile")
418
- }
419
- `,
420
- [binding.scaleway],
421
- Snapshot.yes,
422
- Synth.yes,
423
- {
424
- resources: ["scaleway_object", "scaleway_object_bucket"],
425
- },
426
- );
427
-
428
- testCase.test(
429
- "handles special resource names without schema",
430
- `
431
- provider "scaleway" {
432
- zone = "fr-par-1"
433
- region = "fr-par"
434
- }
435
-
436
- resource "scaleway_object_bucket" "some_bucket" {
437
- name = "some-unique-name"
438
- }
439
-
440
- resource scaleway_object "some_file" {
441
- bucket = scaleway_object_bucket.some_bucket.name
442
- key = "object_path"
443
-
444
- file = "myfile"
445
- hash = filemd5("myfile")
446
- }
447
- `,
448
- [],
449
- Snapshot.yes,
450
- Synth.never,
451
- );
452
-
453
- testCase.test(
454
- "access use fqn for data source",
455
- `
456
- provider "aws" {
457
- region = "us-east-1"
458
- }
459
- data "aws_availability_zones" "changeme_az_list_ebs_snapshot" {
460
- state = "available"
461
- }
462
- resource "aws_ebs_volume" "changeme_ebs_volume_snapshot" {
463
- availability_zone = data.aws_availability_zones.changeme_az_list_ebs_snapshot.names[0]
464
- size = 10
465
- type = "standard"
466
- encrypted = false
467
- tags = {
468
- Name = "changeme_ebs_volume_tag"
469
- }
470
- }
471
- `,
472
- [binding.aws],
473
- Snapshot.yes,
474
- Synth.yes,
475
- {
476
- resources: ["aws_ebs_volume"],
477
- dataSources: ["aws_availability_zones"],
478
- },
479
- );
480
-
481
- testCase.test(
482
- "handles JSON encoded blocks",
483
- `
484
- provider "aws" {
485
- region = "us-east-1"
486
- }
487
- resource "aws_ecs_task_definition" "client" {
488
- family = "client"
489
- requires_compatibilities = ["FARGATE"]
490
- # required for Fargate launch type
491
- memory = 512
492
- cpu = 256
493
- network_mode = "awsvpc"
494
-
495
- container_definitions = jsonencode([
496
- {
497
- name = "client"
498
- image = "crccheck/hello-world"
499
- cpu = 0 # take up proportional cpu
500
- essential = true
501
-
502
- portMappings = [
503
- {
504
- containerPort = 8000
505
- hostPort = 8000 # though, access to the ephemeral port range is needed to connect on EC2, the exact port is required on Fargate from a security group standpoint.
506
- protocol = "tcp"
507
- }
508
- ]
509
-
510
- # Fake Service settings are set via Environment variables
511
- environment = [
512
- {
513
- name = "NAME"
514
- value = "client"
515
- },
516
- {
517
- name = "MESSAGE"
518
- value = "Hello from the client!"
519
- }
520
- ]
521
- }
522
- ])
523
- }
524
- `,
525
- [binding.aws],
526
- Snapshot.yes,
527
- Synth.no_missing_type_coercion,
528
- {
529
- resources: ["aws_ecs_task_definition"],
530
- },
531
- );
532
-
533
- testCase.test(
534
- "built-in data resource",
535
- `
536
- variable "revision" {
537
- default = 1
538
- }
539
-
540
- resource "terraform_data" "replacement" {
541
- input = var.revision
542
- }
543
- `,
544
- [],
545
- Snapshot.yes,
546
- Synth.yes,
547
- {
548
- resources: ["terraform_data"],
549
- },
550
- );
551
- });