@cdktn/hcl2cdk 0.25.0 → 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 (94) hide show
  1. package/build/expressions.js +3 -5
  2. package/build/index.js +3 -3
  3. package/package.json +8 -7
  4. package/.spec.swcrc +0 -22
  5. package/build/__tests__/coerceType.test.d.ts +0 -2
  6. package/build/__tests__/coerceType.test.js +0 -165
  7. package/build/__tests__/expressionToTs.test.d.ts +0 -6
  8. package/build/__tests__/expressionToTs.test.js +0 -693
  9. package/build/__tests__/expressions.test.d.ts +0 -4
  10. package/build/__tests__/expressions.test.js +0 -424
  11. package/build/__tests__/findExpressionType.test.d.ts +0 -6
  12. package/build/__tests__/findExpressionType.test.js +0 -105
  13. package/build/__tests__/functions.test.d.ts +0 -6
  14. package/build/__tests__/functions.test.js +0 -615
  15. package/build/__tests__/generation.test.d.ts +0 -6
  16. package/build/__tests__/generation.test.js +0 -45
  17. package/build/__tests__/jsii-rosetta-workarounds.test.d.ts +0 -2
  18. package/build/__tests__/jsii-rosetta-workarounds.test.js +0 -86
  19. package/build/__tests__/partialCode.test.d.ts +0 -6
  20. package/build/__tests__/partialCode.test.js +0 -390
  21. package/build/__tests__/terraformSchema.test.d.ts +0 -6
  22. package/build/__tests__/terraformSchema.test.js +0 -105
  23. package/build/__tests__/testHelpers.d.ts +0 -7
  24. package/build/__tests__/testHelpers.js +0 -15
  25. package/jest.config.js +0 -25
  26. package/package.sh +0 -9
  27. package/src/__tests__/coerceType.test.ts +0 -207
  28. package/src/__tests__/expressionToTs.test.ts +0 -1167
  29. package/src/__tests__/expressions.test.ts +0 -541
  30. package/src/__tests__/findExpressionType.test.ts +0 -112
  31. package/src/__tests__/functions.test.ts +0 -764
  32. package/src/__tests__/generation.test.ts +0 -72
  33. package/src/__tests__/jsii-rosetta-workarounds.test.ts +0 -145
  34. package/src/__tests__/partialCode.test.ts +0 -432
  35. package/src/__tests__/terraformSchema.test.ts +0 -107
  36. package/src/__tests__/testHelpers.ts +0 -11
  37. package/src/coerceType.ts +0 -261
  38. package/src/dynamic-blocks.ts +0 -61
  39. package/src/expressions.ts +0 -968
  40. package/src/function-bindings/functions.generated.ts +0 -1211
  41. package/src/function-bindings/functions.ts +0 -104
  42. package/src/generation.ts +0 -1189
  43. package/src/index.ts +0 -584
  44. package/src/iteration.ts +0 -156
  45. package/src/jsii-rosetta-workarounds.ts +0 -145
  46. package/src/partialCode.ts +0 -132
  47. package/src/provider.ts +0 -60
  48. package/src/references.ts +0 -193
  49. package/src/schema.ts +0 -74
  50. package/src/terraformSchema.ts +0 -182
  51. package/src/types.ts +0 -58
  52. package/src/utils.ts +0 -19
  53. package/src/variables.ts +0 -214
  54. package/test/__snapshots__/backends.test.ts.snap +0 -70
  55. package/test/__snapshots__/externals.test.ts.snap +0 -37
  56. package/test/__snapshots__/granular-imports.test.ts.snap +0 -180
  57. package/test/__snapshots__/imports.test.ts.snap +0 -159
  58. package/test/__snapshots__/iteration.test.ts.snap +0 -532
  59. package/test/__snapshots__/jsiiLanguage.test.ts.snap +0 -347
  60. package/test/__snapshots__/locals.test.ts.snap +0 -55
  61. package/test/__snapshots__/modules.test.ts.snap +0 -127
  62. package/test/__snapshots__/outputs.test.ts.snap +0 -77
  63. package/test/__snapshots__/partialCode.test.ts.snap +0 -120
  64. package/test/__snapshots__/provider.test.ts.snap +0 -128
  65. package/test/__snapshots__/references.test.ts.snap +0 -376
  66. package/test/__snapshots__/resource-meta-properties.test.ts.snap +0 -342
  67. package/test/__snapshots__/resources.test.ts.snap +0 -613
  68. package/test/__snapshots__/tfExpressions.test.ts.snap +0 -537
  69. package/test/__snapshots__/typeCoercion.test.ts.snap +0 -253
  70. package/test/__snapshots__/variables.test.ts.snap +0 -150
  71. package/test/backends.test.ts +0 -75
  72. package/test/convertProject.test.ts +0 -262
  73. package/test/externals.test.ts +0 -35
  74. package/test/globalSetup.ts +0 -224
  75. package/test/globalTeardown.ts +0 -11
  76. package/test/granular-imports.test.ts +0 -161
  77. package/test/hcl2cdk.test.ts +0 -88
  78. package/test/helpers/convert.ts +0 -544
  79. package/test/helpers/tmp.ts +0 -40
  80. package/test/imports.test.ts +0 -141
  81. package/test/iteration.test.ts +0 -342
  82. package/test/jsiiLanguage.test.ts +0 -73
  83. package/test/locals.test.ts +0 -47
  84. package/test/modules.test.ts +0 -143
  85. package/test/outputs.test.ts +0 -69
  86. package/test/partialCode.test.ts +0 -25
  87. package/test/provider.test.ts +0 -106
  88. package/test/references.test.ts +0 -287
  89. package/test/resource-meta-properties.test.ts +0 -288
  90. package/test/resources.test.ts +0 -551
  91. package/test/tfExpressions.test.ts +0 -300
  92. package/test/typeCoercion.test.ts +0 -154
  93. package/test/variables.test.ts +0 -96
  94. package/tsconfig.json +0 -47
@@ -1,300 +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("tfExpressions", () => {
9
- testCase.test(
10
- "arithmetics",
11
- `
12
- variable "members" {
13
- type = number
14
- }
15
- variable "admins" {
16
- type = number
17
- }
18
-
19
- output "arithmetics" {
20
- value = var.members + var.admins
21
- }`,
22
- [],
23
- Snapshot.yes,
24
- Synth.yes,
25
- );
26
-
27
- testCase.test(
28
- "conditionals",
29
- `
30
- provider "aws" {
31
- region = "us-east-1"
32
- }
33
- resource "aws_kms_key" "examplekms" {
34
- description = "KMS key 1"
35
- deletion_window_in_days = 7
36
- }
37
-
38
- resource "aws_s3_bucket" "examplebucket" {
39
- bucket = "examplebuckettftest"
40
- acl = "private"
41
- }
42
-
43
- resource "aws_s3_bucket_object" "examplebucket_object" {
44
- key = "someobject"
45
- bucket = aws_kms_key.examplekms.deletion_window_in_days > 3 ? aws_s3_bucket.examplebucket.id : []
46
- source = "index.html"
47
- kms_key_id = aws_kms_key.examplekms.arn
48
- }`,
49
- [binding.aws],
50
- Snapshot.yes,
51
- Synth.yes,
52
- {
53
- resources: ["aws_s3_bucket", "aws_kms_key", "aws_s3_bucket_object"],
54
- },
55
- );
56
-
57
- testCase.test(
58
- "for expression 1",
59
- `
60
- variable "users" {
61
- type = map(object({
62
- is_admin = boolean
63
- }))
64
- }
65
-
66
- locals {
67
- admin_users = {
68
- for name, user in var.users : name => user
69
- if user.is_admin
70
- }
71
- regular_users = {
72
- for name, user in var.users : name => user
73
- if !user.is_admin
74
- }
75
- }
76
-
77
- output "combined-so-it-does-not-get-removed" {
78
- value = "\${local.admin_users},\${local.regular_users}"
79
- }
80
- `,
81
- [],
82
- Snapshot.yes,
83
- Synth.yes,
84
- );
85
-
86
- testCase.test(
87
- "for expression 2",
88
- `
89
- variable "users" {
90
- type = map(object({
91
- role = string
92
- }))
93
- }
94
-
95
- locals {
96
- users_by_role = {
97
- for name, user in var.users : user.role => name...
98
- }
99
- }
100
-
101
- output "so-it-does-not-get-removed" {
102
- value = local.users_by_role
103
- }`,
104
- [],
105
- Snapshot.yes,
106
- Synth.yes,
107
- );
108
-
109
- testCase.test(
110
- "for expression 3",
111
- `
112
- provider "datadog" {
113
- api_key = "api_key"
114
- app_key = "app_key"
115
- }
116
-
117
- variable "users" {
118
- type = list(object({
119
- id = string
120
- }))
121
- }
122
-
123
- resource "datadog_monitor" "hard_query" {
124
- name = "queries are hard"
125
- message = "here we go"
126
- query = join(" && ", [for o in var.users : "!(!\${o.id})"])
127
- type = "metric alert"
128
- }`,
129
- [binding.datadog],
130
- Snapshot.yes,
131
- Synth.yes,
132
- {
133
- resources: ["datadog_monitor"],
134
- },
135
- );
136
-
137
- testCase.test(
138
- "property access through square brackets",
139
- `
140
- provider "aws" {
141
- region = "us-east-1"
142
- }
143
- variable "settings" {
144
- type = map(string)
145
- }
146
-
147
- resource "aws_s3_bucket" "examplebucket" {
148
- bucket = var.settings["bucket_name"]
149
- acl = "private"
150
- }
151
- `,
152
- [binding.aws],
153
- Snapshot.yes,
154
- Synth.yes,
155
- {
156
- resources: ["aws_s3_bucket"],
157
- },
158
- );
159
-
160
- testCase.test(
161
- "list access through square brackets",
162
- `
163
- provider "aws" {
164
- region = "us-east-1"
165
- }
166
- variable "settings" {
167
- type = list(map(string))
168
- }
169
-
170
- resource "aws_s3_bucket" "examplebucket" {
171
- bucket = var.settings[0]["bucket_name"]
172
- acl = "private"
173
- }
174
- `,
175
- [binding.aws],
176
- Snapshot.yes,
177
- Synth.yes,
178
- {
179
- resources: ["aws_s3_bucket"],
180
- },
181
- );
182
-
183
- testCase.test(
184
- "numeric property access",
185
- `
186
- provider "google" {
187
- project = "my-project"
188
- region = "us-central1"
189
- }
190
- resource "google_compute_instance" "example" {
191
- name = "example"
192
- machine_type = "f1-micro"
193
- zone = "us-east1-b"
194
-
195
- boot_disk {
196
- initialize_params {
197
- image = "debian-cloud/debian-9"
198
- }
199
- }
200
-
201
- network_interface {
202
- network = "default"
203
-
204
- access_config {
205
- // Ephemeral IP
206
- }
207
- }
208
- }
209
-
210
- output "public_ip" {
211
- value = "\${google_compute_instance.example.network_interface.0.access_config.0.assigned_nat_ip}"
212
- }
213
- `,
214
- [binding.google],
215
- Snapshot.yes,
216
- Synth.yes,
217
- {
218
- resources: ["google_compute_instance"],
219
- },
220
- );
221
-
222
- testCase.test(
223
- "multi-line strings are supported",
224
- `
225
- output "hash" {
226
- value = <<ITEM
227
- {
228
- "example_hash_key": {"S": "something"},
229
- "example_attribute": {"N": "11111"}
230
- }
231
- ITEM
232
- }
233
- `,
234
- [],
235
- Snapshot.yes,
236
- Synth.yes,
237
- {
238
- resources: [],
239
- },
240
- );
241
-
242
- testCase.test(
243
- "escaping dollar-curly in template strings works",
244
- `
245
- resource "aws_ssoadmin_instance_access_control_attributes" "example" {
246
- attribute {
247
- value {
248
- source = ["$\${path:name.givenName}"]
249
- }
250
- }
251
- }
252
- `,
253
- [binding.aws],
254
- Snapshot.yes,
255
- Synth.yes_but_only_typescript_right_now_because_it_breaks,
256
- {
257
- resources: [],
258
- },
259
- );
260
-
261
- testCase.test(
262
- "property access in maps works",
263
- `
264
- variable "default_tags" {
265
- type = map(string)
266
- description = "Map of default tags to apply to resources"
267
- default = {
268
- project = "Learning Live with AWS & HashiCorp"
269
- }
270
- }
271
-
272
- resource "aws_eip" "nat" {
273
- vpc = true
274
- tags = {
275
- "Name" = "\${var.default_tags.project}-nat-eip"
276
- }
277
- }
278
- `,
279
- [binding.aws],
280
- Snapshot.yes_all_languages,
281
- Synth.yes_but_only_typescript_right_now_because_it_breaks,
282
- {
283
- resources: [],
284
- },
285
- );
286
-
287
- testCase.test(
288
- "strings containing single outer quotes are supported",
289
- `
290
- output "hash" {
291
- value = "'static'"
292
- }`,
293
- [],
294
- Snapshot.yes,
295
- Synth.yes,
296
- {
297
- resources: [],
298
- },
299
- );
300
- });
@@ -1,154 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
- import { testCase, Synth, binding, Snapshot } from "./helpers/convert";
4
-
5
- describe("type coercion", () => {
6
- testCase.test(
7
- "variables used in resources need to use stringValue",
8
- `
9
- provider "aws" {
10
- region = "us-east-1"
11
- }
12
- variable "zone_id" {
13
- type = string
14
- }
15
- resource "aws_route53_record" "example_aws_route53_simple_record" {
16
- zone_id = var.zone_id
17
- name = "example.com"
18
- type = "TXT"
19
- ttl = "300"
20
- records = ["example"]
21
- }
22
- `,
23
- [binding.aws],
24
- Snapshot.yes,
25
- Synth.yes,
26
- { resources: ["aws_route53_record"] },
27
- );
28
-
29
- testCase.test(
30
- "function arguments get coerced to the correct type",
31
- `
32
- provider "aws" {
33
- region = "us-east-1"
34
- }
35
- variable "zone_id" {
36
- type = string
37
- }
38
- resource "aws_route53_record" "example_aws_route53_simple_record" {
39
- zone_id = textencodebase64(var.zone_id, "UTF-16LE")
40
- name = "example.com"
41
- type = "TXT"
42
- ttl = "300"
43
- records = ["example"]
44
- }
45
- `,
46
- [binding.aws],
47
- Snapshot.yes,
48
- Synth.yes,
49
- { resources: ["aws_route53_record"] },
50
- );
51
-
52
- testCase.test(
53
- "references used in resources need to use Token.asString",
54
- `
55
- provider "aws" {
56
- region = "us-east-1"
57
- }
58
- resource "aws_route53_zone" "example_aws_route53_simple_zone" {
59
- name = "example.com"
60
- }
61
- resource "aws_route53_record" "example_aws_route53_simple_record" {
62
- zone_id = aws_route53_zone.example_aws_route53_simple_zone.zone_id
63
- name = "example.com"
64
- type = "TXT"
65
- ttl = "300"
66
- records = ["example"]
67
- }
68
- `,
69
- [binding.aws],
70
- Snapshot.yes,
71
- Synth.yes,
72
- { resources: ["aws_route53_zone", "aws_route53_record"] },
73
- );
74
-
75
- testCase.test(
76
- "references used in resource for_eachs need to understand how the value is used",
77
- `
78
- provider "aws" {
79
- region = "us-east-1"
80
- }
81
- variable "iam_groups_users" {
82
- type = map(object({
83
- groups = list(string)
84
- }))
85
- }
86
- resource "aws_iam_user_group_membership" "iam_user_group_membership_user_groups" {
87
- for_each = var.iam_groups_users
88
- user = each.key
89
- groups = each.value["groups"]
90
- }
91
- `,
92
- [binding.aws],
93
- Snapshot.yes,
94
- Synth.yes,
95
- { resources: ["aws_iam_user_group_membership"] },
96
- );
97
-
98
- testCase.test(
99
- "expressions need to be coerced to required type",
100
- `
101
- provider "aws" {
102
- region = "us-east-1"
103
- }
104
- variable "example_spot_and_fargate_name" {
105
- type = string
106
- }
107
- variable "role_arn" {
108
- type = string
109
- }
110
- variable "private_subnets" {
111
- type = list(object({ id = string }))
112
- }
113
- variable "public_subnets" {
114
- type = list(object({ id = string }))
115
- }
116
- resource "aws_eks_cluster" "example_spot_and_fargate_eks_cluster" {
117
- name = "$\{var.example_spot_and_fargate_name}"
118
- role_arn = var.role_arn
119
-
120
- vpc_config {
121
- subnet_ids = concat(var.private_subnets.*.id, var.public_subnets.*.id)
122
- }
123
- }
124
- `,
125
- [binding.aws],
126
- Snapshot.yes,
127
- Synth.yes,
128
- { resources: ["aws_eks_cluster"] },
129
- );
130
-
131
- testCase.test(
132
- "coerces string literal to number",
133
- `
134
- provider "aws" {
135
- region = "us-east-1"
136
- }
137
-
138
- resource "aws_security_group_rule" "client_alb_allow_outbound" {
139
- security_group_id = "sg-1234567890"
140
- type = "egress"
141
- protocol = -1
142
- from_port = 0
143
- to_port = 0
144
- cidr_blocks = ["0.0.0.0/0"]
145
- ipv6_cidr_blocks = ["::/0"]
146
- description = "Allow any outbound traffic."
147
- }
148
- `,
149
- [binding.aws],
150
- Snapshot.yes,
151
- Synth.yes,
152
- { resources: ["aws_security_group_rule"] },
153
- );
154
- });
@@ -1,96 +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("variables", () => {
9
- testCase.test(
10
- "basic",
11
- `
12
- provider "local" {}
13
- variable "image_id" {
14
- type = string
15
- }
16
- data "local_file" "foo" {
17
- filename = "./\${var.image_id}.img"
18
- }
19
- `,
20
- [binding.local],
21
- Snapshot.yes,
22
- Synth.yes,
23
- );
24
-
25
- testCase.test(
26
- "complex type and default",
27
- `
28
- provider "local" {}
29
- variable "docker_ports" {
30
- type = list(object({
31
- internal = number
32
- external = number
33
- protocol = string
34
- }))
35
- default = [
36
- {
37
- internal = 8300
38
- external = 8300
39
- protocol = "tcp"
40
- }
41
- ]
42
- }
43
-
44
- data "local_file" "foo" {
45
- filename = "./\${var.docker_ports[0].protocol}.img"
46
- }`,
47
- [binding.local],
48
- Snapshot.yes,
49
- Synth.yes,
50
- );
51
-
52
- testCase.test(
53
- "sensitive and required",
54
- `
55
- provider "local" {}
56
- variable "user_information" {
57
- type = object({
58
- name = string
59
- address = string
60
- })
61
- sensitive = true
62
- nullable = false
63
- }
64
-
65
- data "local_file" "foo" {
66
- filename = "./\${var.user_information.name}.img"
67
- }
68
- `,
69
- [binding.local],
70
- Snapshot.yes,
71
- Synth.yes,
72
- );
73
-
74
- testCase.test(
75
- "validations",
76
- `
77
- provider "local" {}
78
- variable "image_id" {
79
- type = string
80
- description = "The id of the machine image (AMI) to use for the server."
81
-
82
- validation {
83
- condition = length(var.image_id) > 4 && substr(var.image_id, 0, 4) == "ami-"
84
- error_message = "The image_id value must be a valid AMI id, starting with ami-."
85
- }
86
- }
87
-
88
- data "local_file" "foo" {
89
- filename = "./\${var.image_id}.img"
90
- }
91
- `,
92
- [binding.local],
93
- Snapshot.yes,
94
- Synth.yes,
95
- );
96
- });
package/tsconfig.json DELETED
@@ -1,47 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "alwaysStrict": true,
4
- "declaration": true,
5
- "declarationMap": true,
6
- "experimentalDecorators": true,
7
- "inlineSourceMap": true,
8
- "inlineSources": true,
9
- "lib": [
10
- "ES2020"
11
- ],
12
- "module": "CommonJS",
13
- "noEmitOnError": false,
14
- "noFallthroughCasesInSwitch": true,
15
- "noImplicitAny": true,
16
- "noImplicitReturns": true,
17
- "noImplicitThis": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "resolveJsonModule": true,
21
- "strict": true,
22
- "strictNullChecks": true,
23
- "strictPropertyInitialization": true,
24
- "stripInternal": true,
25
- "skipLibCheck": true,
26
- "target": "ES2018",
27
- "types": [
28
- "node",
29
- "jest"
30
- ],
31
- "incremental": true,
32
- "esModuleInterop": true,
33
- "rootDir": "./src",
34
- "outDir": "./build"
35
- },
36
- "files": [
37
- "ambient.d.ts"
38
- ],
39
- "include": [
40
- "src/**/*.ts",
41
- ],
42
- "exclude": [
43
- "node_modules",
44
- "cdktf-convert-test*/**/*",
45
- "**/*.d.ts",
46
- ],
47
- }