@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.
- package/.spec.swcrc +22 -0
- package/LICENSE +355 -0
- package/README.md +1 -1
- package/build/__tests__/jsii-rosetta-workarounds.test.js +2 -2
- package/build/expressions.js +3 -4
- package/build/function-bindings/functions.generated.js +2 -2
- package/build/generation.js +2 -2
- package/build/index.d.ts +20 -20
- package/build/index.js +4 -4
- package/build/references.js +2 -3
- package/build/schema.d.ts +60 -60
- package/build/utils.d.ts +1 -1
- package/build/utils.js +3 -3
- package/jest.config.js +18 -11
- package/package.json +37 -25
- package/package.sh +1 -1
- package/src/__tests__/coerceType.test.ts +207 -0
- package/src/__tests__/expressionToTs.test.ts +1167 -0
- package/src/__tests__/expressions.test.ts +541 -0
- package/src/__tests__/findExpressionType.test.ts +112 -0
- package/src/__tests__/functions.test.ts +768 -0
- package/src/__tests__/generation.test.ts +72 -0
- package/src/__tests__/jsii-rosetta-workarounds.test.ts +145 -0
- package/src/__tests__/partialCode.test.ts +432 -0
- package/src/__tests__/terraformSchema.test.ts +107 -0
- package/src/__tests__/testHelpers.ts +11 -0
- package/src/coerceType.ts +261 -0
- package/src/dynamic-blocks.ts +61 -0
- package/src/expressions.ts +968 -0
- package/src/function-bindings/functions.generated.ts +1139 -0
- package/src/function-bindings/functions.ts +104 -0
- package/src/generation.ts +1189 -0
- package/src/index.ts +584 -0
- package/src/iteration.ts +156 -0
- package/src/jsii-rosetta-workarounds.ts +145 -0
- package/src/partialCode.ts +132 -0
- package/src/provider.ts +60 -0
- package/src/references.ts +193 -0
- package/src/schema.ts +74 -0
- package/src/terraformSchema.ts +182 -0
- package/src/types.ts +58 -0
- package/src/utils.ts +19 -0
- package/src/variables.ts +214 -0
- package/test/__snapshots__/backends.test.ts.snap +70 -0
- package/test/__snapshots__/externals.test.ts.snap +37 -0
- package/test/__snapshots__/granular-imports.test.ts.snap +180 -0
- package/test/__snapshots__/imports.test.ts.snap +159 -0
- package/test/__snapshots__/iteration.test.ts.snap +532 -0
- package/test/__snapshots__/jsiiLanguage.test.ts.snap +347 -0
- package/test/__snapshots__/locals.test.ts.snap +55 -0
- package/test/__snapshots__/modules.test.ts.snap +127 -0
- package/test/__snapshots__/outputs.test.ts.snap +77 -0
- package/test/__snapshots__/partialCode.test.ts.snap +120 -0
- package/test/__snapshots__/provider.test.ts.snap +128 -0
- package/test/__snapshots__/references.test.ts.snap +376 -0
- package/test/__snapshots__/resource-meta-properties.test.ts.snap +342 -0
- package/test/__snapshots__/resources.test.ts.snap +613 -0
- package/test/__snapshots__/tfExpressions.test.ts.snap +537 -0
- package/test/__snapshots__/typeCoercion.test.ts.snap +253 -0
- package/test/__snapshots__/variables.test.ts.snap +150 -0
- package/test/backends.test.ts +75 -0
- package/test/convertProject.test.ts +257 -0
- package/test/externals.test.ts +35 -0
- package/test/globalSetup.ts +224 -0
- package/test/globalTeardown.ts +11 -0
- package/test/granular-imports.test.ts +161 -0
- package/test/hcl2cdk.test.ts +88 -0
- package/test/helpers/convert.ts +543 -0
- package/test/helpers/tmp.ts +25 -0
- package/test/imports.test.ts +141 -0
- package/test/iteration.test.ts +342 -0
- package/test/jsiiLanguage.test.ts +73 -0
- package/test/locals.test.ts +47 -0
- package/test/modules.test.ts +143 -0
- package/test/outputs.test.ts +69 -0
- package/test/partialCode.test.ts +25 -0
- package/test/provider.test.ts +106 -0
- package/test/references.test.ts +287 -0
- package/test/resource-meta-properties.test.ts +288 -0
- package/test/resources.test.ts +551 -0
- package/test/tfExpressions.test.ts +300 -0
- package/test/typeCoercion.test.ts +154 -0
- package/test/variables.test.ts +96 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// Copyright (c) HashiCorp, Inc
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
import { testCase, Synth, binding, Snapshot } from "./helpers/convert";
|
|
4
|
+
|
|
5
|
+
describe("meta-properties", () => {
|
|
6
|
+
describe("depends_on", () => {
|
|
7
|
+
testCase.test(
|
|
8
|
+
"depends on",
|
|
9
|
+
`
|
|
10
|
+
provider "aws" {
|
|
11
|
+
region = "us-east-1"
|
|
12
|
+
}
|
|
13
|
+
resource "aws_iam_role_policy" "example" {
|
|
14
|
+
name = "example"
|
|
15
|
+
role = "role"
|
|
16
|
+
policy = jsonencode({
|
|
17
|
+
"Statement" = [{
|
|
18
|
+
"Action" = "s3:*",
|
|
19
|
+
"Effect" = "Allow",
|
|
20
|
+
}],
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
resource "aws_instance" "example" {
|
|
25
|
+
ami = "ami-a1b2c3d4"
|
|
26
|
+
instance_type = "t2.micro"
|
|
27
|
+
iam_instance_profile = "aws_iam_instance_profile"
|
|
28
|
+
depends_on = [
|
|
29
|
+
aws_iam_role_policy.example
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
[binding.aws],
|
|
34
|
+
Snapshot.yes,
|
|
35
|
+
Synth.yes,
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("provider", () => {
|
|
40
|
+
testCase.test(
|
|
41
|
+
"passing providers",
|
|
42
|
+
`
|
|
43
|
+
provider "google" {
|
|
44
|
+
region = "us-central1"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# alternate configuration, whose alias is "europe"
|
|
48
|
+
provider "google" {
|
|
49
|
+
alias = "europe"
|
|
50
|
+
region = "europe-west1"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
resource "google_compute_instance" "default" {
|
|
54
|
+
provider = google.europe
|
|
55
|
+
|
|
56
|
+
name = "test"
|
|
57
|
+
machine_type = "e2-medium"
|
|
58
|
+
zone = "us-central1-a"
|
|
59
|
+
|
|
60
|
+
tags = ["foo", "bar"]
|
|
61
|
+
|
|
62
|
+
boot_disk {
|
|
63
|
+
initialize_params {
|
|
64
|
+
image = "debian-cloud/debian-11"
|
|
65
|
+
labels = {
|
|
66
|
+
my_label = "value"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
scratch_disk {
|
|
72
|
+
interface = "SCSI"
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
network_interface {
|
|
76
|
+
network = "default"
|
|
77
|
+
|
|
78
|
+
access_config {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
metadata = {
|
|
83
|
+
foo = "bar"
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
metadata_startup_script = "echo hi > /test.txt"
|
|
87
|
+
}
|
|
88
|
+
`,
|
|
89
|
+
[binding.google],
|
|
90
|
+
Snapshot.yes,
|
|
91
|
+
Synth.yes,
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("lifecycle", () => {
|
|
96
|
+
testCase.test(
|
|
97
|
+
"all lifecycle properties",
|
|
98
|
+
`
|
|
99
|
+
provider "aws" {
|
|
100
|
+
region = "us-east-1"
|
|
101
|
+
}
|
|
102
|
+
resource "aws_iam_role_policy" "example" {
|
|
103
|
+
name = "example"
|
|
104
|
+
role = "role"
|
|
105
|
+
policy = jsonencode({
|
|
106
|
+
"Statement" = [{
|
|
107
|
+
"Action" = "s3:*",
|
|
108
|
+
"Effect" = "Allow",
|
|
109
|
+
}],
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
resource "aws_instance" "example" {
|
|
114
|
+
ami = "ami-a1b2c3d4"
|
|
115
|
+
instance_type = "t2.micro"
|
|
116
|
+
iam_instance_profile = "aws_iam_instance_profile"
|
|
117
|
+
lifecycle {
|
|
118
|
+
create_before_destroy = true
|
|
119
|
+
prevent_destroy = true
|
|
120
|
+
ignore_changes = [
|
|
121
|
+
"ami",
|
|
122
|
+
"instance_type"
|
|
123
|
+
]
|
|
124
|
+
replace_triggered_by = [
|
|
125
|
+
aws_iam_role_policy.example.id
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
`,
|
|
130
|
+
[binding.aws],
|
|
131
|
+
Snapshot.yes,
|
|
132
|
+
Synth.yes,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
testCase.test(
|
|
136
|
+
"preconditions and postconditions",
|
|
137
|
+
`
|
|
138
|
+
provider "aws" {
|
|
139
|
+
region = "us-east-1"
|
|
140
|
+
}
|
|
141
|
+
resource "aws_instance" "example" {
|
|
142
|
+
ami = "ami-a1b2c3d4"
|
|
143
|
+
instance_type = "t2.micro"
|
|
144
|
+
iam_instance_profile = "aws_iam_instance_profile"
|
|
145
|
+
lifecycle {
|
|
146
|
+
precondition {
|
|
147
|
+
condition = self.tags["Component"] == "nomad-server"
|
|
148
|
+
error_message = "Please add the nomad-server tag to this instance."
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
postcondition {
|
|
152
|
+
condition = self.public_dns != ""
|
|
153
|
+
error_message = "EC2 instance must be in a VPC that has public DNS hostnames enabled."
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
`,
|
|
158
|
+
[binding.aws],
|
|
159
|
+
Snapshot.yes,
|
|
160
|
+
Synth.yes,
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe("provisioner", () => {
|
|
165
|
+
testCase.test(
|
|
166
|
+
"file",
|
|
167
|
+
`
|
|
168
|
+
provider "aws" {
|
|
169
|
+
region = "us-east-1"
|
|
170
|
+
}
|
|
171
|
+
resource "aws_instance" "example" {
|
|
172
|
+
ami = "ami-a1b2c3d4"
|
|
173
|
+
instance_type = "t2.micro"
|
|
174
|
+
iam_instance_profile = "aws_iam_instance_profile"
|
|
175
|
+
|
|
176
|
+
provisioner "file" {
|
|
177
|
+
source = "conf/myapp.conf"
|
|
178
|
+
destination = "/etc/myapp.conf"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
provisioner "file" {
|
|
182
|
+
content = "ami used: \${self.ami}"
|
|
183
|
+
destination = "/tmp/file.log"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
`,
|
|
187
|
+
[binding.aws],
|
|
188
|
+
Snapshot.yes,
|
|
189
|
+
Synth.yes,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
testCase.test(
|
|
193
|
+
"local-exec",
|
|
194
|
+
`
|
|
195
|
+
provider "aws" {
|
|
196
|
+
region = "us-east-1"
|
|
197
|
+
}
|
|
198
|
+
resource "aws_instance" "example" {
|
|
199
|
+
ami = "ami-a1b2c3d4"
|
|
200
|
+
instance_type = "t2.micro"
|
|
201
|
+
iam_instance_profile = "aws_iam_instance_profile"
|
|
202
|
+
|
|
203
|
+
provisioner "local-exec" {
|
|
204
|
+
command = "echo \${self.private_ip} >> private_ips.txt"
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
`,
|
|
208
|
+
[binding.aws],
|
|
209
|
+
Snapshot.yes,
|
|
210
|
+
Synth.yes,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
testCase.test(
|
|
214
|
+
"remote-exec with global connection block",
|
|
215
|
+
`
|
|
216
|
+
provider "aws" {
|
|
217
|
+
region = "us-east-1"
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
resource "aws_instance" "web" {
|
|
221
|
+
ami = "ami-a1b2c3d4"
|
|
222
|
+
instance_type = "t2.micro"
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
resource "aws_instance" "example" {
|
|
226
|
+
ami = "ami-a1b2c3d4"
|
|
227
|
+
instance_type = "t2.micro"
|
|
228
|
+
iam_instance_profile = "aws_iam_instance_profile"
|
|
229
|
+
|
|
230
|
+
connection {
|
|
231
|
+
type = "ssh"
|
|
232
|
+
user = "root"
|
|
233
|
+
password = "password"
|
|
234
|
+
host = self.public_ip
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
provisioner "remote-exec" {
|
|
238
|
+
inline = [
|
|
239
|
+
"puppet apply",
|
|
240
|
+
"consul join \${aws_instance.web.private_ip}",
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
`,
|
|
245
|
+
[binding.aws],
|
|
246
|
+
Snapshot.yes,
|
|
247
|
+
Synth.yes,
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
testCase.test(
|
|
251
|
+
"remote-exec with connection block",
|
|
252
|
+
`
|
|
253
|
+
provider "aws" {
|
|
254
|
+
region = "us-east-1"
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
resource "aws_instance" "web" {
|
|
258
|
+
ami = "ami-a1b2c3d4"
|
|
259
|
+
instance_type = "t2.micro"
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
resource "aws_instance" "example" {
|
|
263
|
+
ami = "ami-a1b2c3d4"
|
|
264
|
+
instance_type = "t2.micro"
|
|
265
|
+
iam_instance_profile = "aws_iam_instance_profile"
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
provisioner "remote-exec" {
|
|
269
|
+
inline = [
|
|
270
|
+
"puppet apply",
|
|
271
|
+
"consul join \${aws_instance.web.private_ip}",
|
|
272
|
+
]
|
|
273
|
+
|
|
274
|
+
connection {
|
|
275
|
+
type = "ssh"
|
|
276
|
+
user = "root"
|
|
277
|
+
password = "password"
|
|
278
|
+
host = self.public_ip
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
`,
|
|
283
|
+
[binding.aws],
|
|
284
|
+
Snapshot.yes,
|
|
285
|
+
Synth.yes,
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
});
|