@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,143 +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("modules", () => {
9
- testCase.test(
10
- "modules",
11
- `
12
- module "vpc" {
13
- source = "terraform-aws-modules/vpc/aws"
14
-
15
- name = "my-vpc"
16
- cidr = "10.0.0.0/16"
17
-
18
- azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
19
- private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
20
- public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
21
-
22
- enable_nat_gateway = true
23
- enable_vpn_gateway = true
24
-
25
- tags = {
26
- Terraform = "true"
27
- Environment = "dev"
28
- }
29
- }`,
30
- [binding.awsVpc],
31
- Snapshot.yes,
32
- Synth.yes,
33
- );
34
-
35
- testCase.test(
36
- "duplicate modules",
37
- `
38
- module "vpca" {
39
- source = "terraform-aws-modules/vpc/aws"
40
-
41
- name = "my-vpc-a"
42
- }
43
-
44
- module "vpcb" {
45
- source = "terraform-aws-modules/vpc/aws"
46
-
47
- name = "my-vpc-b"
48
- }`,
49
- [binding.awsVpc],
50
- Snapshot.yes,
51
- Synth.yes,
52
- );
53
-
54
- testCase.test(
55
- "referenced modules",
56
- `
57
- module "vpc" {
58
- source = "terraform-aws-modules/vpc/aws"
59
-
60
- name = "my-vpc"
61
- cidr = "10.0.0.0/16"
62
-
63
- azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
64
- private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
65
- public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
66
-
67
- enable_nat_gateway = true
68
- enable_vpn_gateway = true
69
-
70
- tags = {
71
- Terraform = "true"
72
- Environment = "dev"
73
- }
74
- }
75
-
76
- output "subnet_ids" {
77
- value = module.vpc.public_subnets
78
- }`,
79
- [binding.awsVpc],
80
- Snapshot.yes,
81
- Synth.yes,
82
- );
83
-
84
- testCase.test(
85
- "local module",
86
- `
87
- module "aws_vpc" {
88
- source = "./aws_vpc"
89
- }
90
- `,
91
- [],
92
- Snapshot.yes,
93
- Synth.never,
94
- );
95
-
96
- testCase.test(
97
- "terraform workspace",
98
- `
99
- module "example" {
100
- source = "./my-module"
101
- name_prefix = "app-\${terraform.workspace}"
102
- }
103
- `,
104
- [],
105
- Snapshot.yes,
106
- Synth.never,
107
- );
108
-
109
- testCase.test(
110
- "all module types",
111
- `
112
- module "consul" {
113
- source = "./consul"
114
- }
115
- module "consul-registry" {
116
- source = "hashicorp/consul/aws"
117
- version = "0.1.0"
118
- }
119
- module "consul-hosted-registry" {
120
- source = "app.terraform.io/example-corp/k8s-cluster/azurerm"
121
- version = "1.1.0"
122
- }
123
- module "consul-github" {
124
- source = "github.com/hashicorp/example"
125
- }
126
- module "consul-git" {
127
- source = "git@github.com:hashicorp/example.git"
128
- }
129
- module "consul-butbucket" {
130
- source = "bitbucket.org/hashicorp/terraform-consul-aws"
131
- }
132
- module "vpc" {
133
- source = "git::https://example.com/vpc.git"
134
- }
135
- module "storage" {
136
- source = "git::ssh://username@example.com/storage.git"
137
- }
138
- `,
139
- [],
140
- Snapshot.yes,
141
- Synth.never,
142
- );
143
- });
@@ -1,69 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { testCase, Synth, Snapshot } from "./helpers/convert";
7
-
8
- describe("outputs", () => {
9
- testCase.test(
10
- "output",
11
- `
12
- output "cidr_out" {
13
- value = "test"
14
- }`,
15
- [],
16
- Snapshot.yes,
17
- Synth.yes,
18
- );
19
- testCase.test(
20
- "sensitive output",
21
- `
22
- output "cidr_out" {
23
- value = "test"
24
- sensitive = true
25
- }`,
26
-
27
- [],
28
- Snapshot.yes,
29
- Synth.yes,
30
- );
31
- testCase.test(
32
- "output withdescription",
33
- `
34
- output "cidr_out" {
35
- value = "test"
36
- sensitive = true
37
- description = "Best output"
38
- }`,
39
- [],
40
- Snapshot.yes,
41
- Synth.yes,
42
- );
43
-
44
- testCase.test(
45
- "multiple outputs",
46
- `
47
- output "first_cidr_out" {
48
- value = "first"
49
- }
50
- output "second_cidr_out" {
51
- value = "second"
52
- }`,
53
- [],
54
- Snapshot.yes,
55
- Synth.yes,
56
- );
57
-
58
- testCase.test(
59
- "number output",
60
- `
61
- output "test" {
62
- value = 42
63
- }
64
- `,
65
- [],
66
- Snapshot.yes,
67
- Synth.yes,
68
- );
69
- });
@@ -1,25 +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("Partial code (missing properties)", () => {
9
- testCase.test(
10
- "missing top-level required property",
11
- `
12
- resource "docker_config" "service_config" {
13
- name = "my-config"
14
- # other required properties are missing:
15
- # data = base64encode(...)
16
- }
17
- `,
18
- [binding.docker],
19
- Snapshot.yes_all_languages,
20
- Synth.never,
21
- {
22
- resources: ["docker_config"],
23
- },
24
- );
25
- });
@@ -1,106 +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("provider", () => {
9
- testCase.test(
10
- "empty provider",
11
- `provider "docker" {}`,
12
- [binding.docker],
13
- Snapshot.yes,
14
- Synth.yes,
15
- );
16
- testCase.test(
17
- "null provider",
18
- `provider "null" {}
19
- resource "null_resource" "test" {}
20
- `,
21
- [binding.null],
22
- Snapshot.yes,
23
- Synth.yes,
24
- );
25
-
26
- testCase.test(
27
- "provider with complex config",
28
- `
29
- provider "aws" {
30
- access_key = "mock_access_key"
31
- region = "us-east-1"
32
- secret_key = "mock_secret_key"
33
- skip_credentials_validation = true
34
- skip_requesting_account_id = true
35
-
36
- endpoints {
37
- dynamodb = "http://localhost:8000"
38
- }
39
- }
40
- `,
41
- [binding.aws],
42
- Snapshot.yes,
43
- Synth.yes,
44
- {},
45
- );
46
-
47
- testCase.test(
48
- "provider alias",
49
- `
50
- provider "aws" {
51
- region = "us-east-1"
52
- }
53
-
54
- provider "aws" {
55
- alias = "west"
56
- region = "us-west-2"
57
- }
58
-
59
- resource "aws_instance" "foo" {
60
- provider = aws.west
61
-
62
- foo = "bar"
63
- }
64
-
65
- module "vpc" {
66
- source = "terraform-aws-modules/vpc/aws"
67
- providers = {
68
- aws = aws.west
69
- }
70
- }
71
- `,
72
- [binding.aws, binding.awsVpc],
73
- Snapshot.yes,
74
- Synth.never,
75
- {
76
- resources: ["aws_instance"],
77
- },
78
- );
79
-
80
- testCase.test(
81
- "required namespaced provider",
82
- `
83
- variable "domain" {
84
- description = "A domain"
85
- }
86
- provider "auth0" {
87
- domain = var.domain
88
- client_id = "42"
89
- client_secret = "secret"
90
- }
91
-
92
- terraform {
93
- required_providers {
94
- auth0 = {
95
- source = "alexkappa/auth0"
96
- version = "0.19.0"
97
- }
98
- }
99
- }
100
- `,
101
- [binding.auth0],
102
- Snapshot.yes,
103
- Synth.yes,
104
- {},
105
- );
106
- });
@@ -1,287 +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("references", () => {
6
- testCase.test(
7
- "resource references",
8
- `
9
- provider "aws" {
10
- region = "us-east-1"
11
- }
12
- resource "aws_kms_key" "examplekms" {
13
- description = "KMS key 1"
14
- deletion_window_in_days = 7
15
- }
16
-
17
- resource "aws_s3_bucket" "examplebucket" {
18
- bucket = "examplebuckettftest"
19
- acl = "private"
20
- }
21
-
22
- resource "aws_s3_bucket_object" "examplebucket_object" {
23
- key = "someobject"
24
- bucket = aws_s3_bucket.examplebucket.id
25
- source = "index.html"
26
- kms_key_id = aws_kms_key.examplekms.arn
27
- }`,
28
- [binding.aws],
29
- Snapshot.yes,
30
- Synth.yes,
31
- {
32
- resources: ["aws_s3_bucket", "aws_s3_bucket_object", "aws_kms_key"],
33
- },
34
- );
35
-
36
- testCase.test(
37
- "locals references",
38
- `
39
- provider "aws" {
40
- region = "us-east-1"
41
- }
42
-
43
- locals {
44
- bucket_name = "foo"
45
- }
46
-
47
- resource "aws_s3_bucket" "examplebucket" {
48
- bucket = local.bucket_name
49
- acl = "private"
50
- }`,
51
- [binding.aws],
52
- Snapshot.yes,
53
- Synth.yes,
54
- {
55
- resources: ["aws_s3_bucket"],
56
- },
57
- );
58
-
59
- testCase.test(
60
- "variable references",
61
- `
62
- provider "aws" {
63
- region = "us-east-1"
64
- }
65
- variable "bucket_name" {
66
- type = string
67
- default = "demo"
68
- }
69
-
70
- resource "aws_s3_bucket" "examplebucket" {
71
- bucket = var.bucket_name
72
- acl = "private"
73
- }`,
74
- [binding.aws],
75
- Snapshot.yes,
76
- Synth.yes,
77
- {
78
- resources: ["aws_s3_bucket"],
79
- },
80
- );
81
-
82
- testCase.test(
83
- "data references",
84
- `
85
- provider "aws" {
86
- region = "us-east-1"
87
- }
88
- variable "bucket_name" {
89
- type = string
90
- default = "demo"
91
- }
92
-
93
- data "aws_s3_bucket" "examplebucket" {
94
- bucket = var.bucket_name
95
- }
96
-
97
- resource "aws_s3_bucket_object" "examplebucket_object" {
98
- key = "someobject"
99
- bucket = data.aws_s3_bucket.examplebucket.arn
100
- source = "index.html"
101
- }`,
102
- [binding.aws],
103
- Snapshot.yes,
104
- Synth.yes,
105
- {
106
- resources: ["aws_s3_bucket", "aws_s3_bucket_object"],
107
- },
108
- );
109
-
110
- testCase.test(
111
- "double references",
112
- `
113
- provider "aws" {
114
- region = "us-east-1"
115
- }
116
- variable "bucket_name" {
117
- type = string
118
- default = "demo"
119
- }
120
-
121
- resource "aws_s3_bucket" "examplebucket" {
122
- bucket = var.bucket_name
123
- acl = "private"
124
- tags = {
125
- tag-key = var.bucket_name
126
- }
127
- }`,
128
- [binding.aws],
129
- Snapshot.yes,
130
- Synth.yes,
131
- {
132
- resources: ["aws_s3_bucket"],
133
- },
134
- );
135
-
136
- testCase.test(
137
- "resource references with HCL functions",
138
- `
139
- provider "aws" {
140
- region = "us-east-1"
141
- }
142
- resource "aws_kms_key" "examplekms" {
143
- description = "KMS key 1"
144
- deletion_window_in_days = 7
145
- }
146
-
147
- resource "aws_s3_bucket" "examplebucket" {
148
- count = 2
149
- bucket = "examplebuckettftest-\${count.index}"
150
- acl = "private"
151
- }
152
-
153
- resource "aws_s3_bucket_object" "examplebucket_object" {
154
- key = "someobject"
155
- bucket = element(aws_s3_bucket.examplebucket, 0).id
156
- source = "index.html"
157
- kms_key_id = aws_kms_key.examplekms.arn
158
- }`,
159
- [binding.aws],
160
- Snapshot.yes,
161
- Synth.no_cant_resolve_construct,
162
- {
163
- resources: ["aws_s3_bucket", "aws_s3_bucket_object", "aws_kms_key"],
164
- },
165
- );
166
-
167
- testCase.test(
168
- "provider with var reference",
169
- `
170
- variable "domain" {
171
- description = "A domain"
172
- }
173
- provider "auth0" {
174
- domain = var.domain
175
- client_id = "client_id"
176
- client_secret = "client_secret"
177
- }
178
- `,
179
- [binding.auth0],
180
- Snapshot.yes,
181
- Synth.yes,
182
- { resources: [] },
183
- );
184
-
185
- testCase.test(
186
- "data local_file",
187
- `
188
- provider "local" {}
189
- data "local_file" "_01_please_verify" {
190
- filename = "./email_templates/01_please_verify/template.html"
191
- }
192
- `,
193
- [binding.local],
194
- Snapshot.yes,
195
- Synth.yes,
196
- {
197
- dataSources: ["local_file"],
198
- },
199
- );
200
-
201
- testCase.test(
202
- "aliased duplicate provider with var reference",
203
- `
204
- variable "domain" {
205
- description = "A domain"
206
- }
207
- variable "client_id" {
208
- description = "A client_id"
209
- }
210
- variable "client_secret" {
211
- description = "A client_secret"
212
- }
213
- provider "auth0" {
214
- domain = var.domain
215
- client_id = var.client_id
216
- client_secret = var.client_secret
217
- }
218
- provider "auth0" {
219
- alias = "private_auth0"
220
- domain = var.domain
221
- client_id = var.client_id
222
- client_secret = var.client_secret
223
- debug = true
224
- }
225
- `,
226
- [binding.auth0],
227
- Snapshot.yes,
228
- Synth.yes,
229
- { resources: [] },
230
- );
231
-
232
- testCase.test(
233
- "variables with maps need to use accessor syntax",
234
- `
235
- provider "aws" {
236
- region = "us-east-1"
237
- }
238
-
239
- variable "default_tags" {
240
- type = map(string)
241
- description = "Map of default tags to apply to resources"
242
- default = {
243
- project = "Learning Live with AWS & HashiCorp"
244
- }
245
- }
246
-
247
- resource "aws_eip" "nat" {
248
- vpc = true
249
- tags = {
250
- "Name" = "\${var.default_tags.project}-nat-eip"
251
- }
252
- }
253
- `,
254
- [binding.aws],
255
- Snapshot.yes,
256
- Synth.yes,
257
- { resources: ["aws_eip"] },
258
- );
259
-
260
- testCase.test(
261
- "resources with splat expressions should work",
262
- `
263
- variable "key_value_pairs" {
264
- type = list(object({
265
- foo = string
266
- bar = string
267
- }))
268
- description = "List of key value pairs"
269
- default = [{
270
- foo = "foo"
271
- bar = "not food",
272
- }, {
273
- foo = "bar"
274
- bar = "not beer",
275
- }]
276
- }
277
-
278
- output "values" {
279
- value = var.key_value_pairs[*].bar
280
- }
281
- `,
282
- [],
283
- Snapshot.yes,
284
- Synth.yes,
285
- { resources: ["aws_eip"] },
286
- );
287
- });