@cdktn/hcl2cdk 0.24.0-pre.43 → 0.24.0-pre.47
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/LICENSE +355 -0
- package/README.md +1 -1
- package/build/__tests__/expressions.test.js +10 -19
- package/build/__tests__/functions.test.js +8 -18
- package/build/__tests__/testHelpers.js +3 -2
- package/build/coerceType.js +11 -21
- package/build/dynamic-blocks.js +3 -3
- package/build/expressions.js +13 -22
- package/build/function-bindings/functions.generated.js +2 -2
- package/build/generation.js +24 -34
- package/build/index.js +15 -25
- package/build/iteration.js +7 -6
- package/build/jsii-rosetta-workarounds.js +6 -5
- package/build/partialCode.js +11 -20
- package/build/provider.js +4 -3
- package/build/references.js +6 -5
- package/build/schema.js +8 -18
- package/build/terraformSchema.js +4 -4
- package/build/utils.js +3 -3
- package/build/variables.js +12 -21
- package/package.json +20 -17
- 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,532 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
|
2
|
+
|
|
3
|
+
exports[`iteration complex for each loops snapshot typescript 1`] = `
|
|
4
|
+
"import { Construct } from "constructs";
|
|
5
|
+
import { Token, TerraformIterator, Fn, 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 { AcmCertificate } from "./.gen/providers/aws/acm-certificate";
|
|
11
|
+
import { AcmCertificateValidation } from "./.gen/providers/aws/acm-certificate-validation";
|
|
12
|
+
import { DataAwsRoute53Zone } from "./.gen/providers/aws/data-aws-route53-zone";
|
|
13
|
+
import { LbListener } from "./.gen/providers/aws/lb-listener";
|
|
14
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
15
|
+
import { Route53Record } from "./.gen/providers/aws/route53-record";
|
|
16
|
+
class MyConvertedCode extends TerraformStack {
|
|
17
|
+
constructor(scope: Construct, name: string) {
|
|
18
|
+
super(scope, name);
|
|
19
|
+
new AwsProvider(this, "aws", {
|
|
20
|
+
region: "us-east-1",
|
|
21
|
+
});
|
|
22
|
+
const example = new AcmCertificate(this, "example", {
|
|
23
|
+
domainName: "example.com",
|
|
24
|
+
validationMethod: "DNS",
|
|
25
|
+
});
|
|
26
|
+
const dataAwsRoute53ZoneExample = new DataAwsRoute53Zone(
|
|
27
|
+
this,
|
|
28
|
+
"example_2",
|
|
29
|
+
{
|
|
30
|
+
name: "example.com",
|
|
31
|
+
privateZone: false,
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
|
|
35
|
+
dataAwsRoute53ZoneExample.overrideLogicalId("example");
|
|
36
|
+
/*In most cases loops should be handled in the programming language context and
|
|
37
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
38
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
39
|
+
you need to keep this like it is.*/
|
|
40
|
+
const exampleForEachIterator = TerraformIterator.fromList(
|
|
41
|
+
Token.asAny(
|
|
42
|
+
"\${{ for dvo in \${" +
|
|
43
|
+
example.domainValidationOptions +
|
|
44
|
+
"} : dvo.domain_name => {\\n name = dvo.resource_record_name\\n record = dvo.resource_record_value\\n type = dvo.resource_record_type\\n }}}"
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
const awsRoute53RecordExample = new Route53Record(this, "example_3", {
|
|
48
|
+
allowOverwrite: true,
|
|
49
|
+
name: Token.asString(
|
|
50
|
+
Fn.lookupNested(exampleForEachIterator.value, ["name"])
|
|
51
|
+
),
|
|
52
|
+
records: [
|
|
53
|
+
Token.asString(
|
|
54
|
+
Fn.lookupNested(exampleForEachIterator.value, ["record"])
|
|
55
|
+
),
|
|
56
|
+
],
|
|
57
|
+
ttl: 60,
|
|
58
|
+
type: Token.asString(
|
|
59
|
+
Fn.lookupNested(exampleForEachIterator.value, ["type"])
|
|
60
|
+
),
|
|
61
|
+
zoneId: Token.asString(dataAwsRoute53ZoneExample.zoneId),
|
|
62
|
+
forEach: exampleForEachIterator,
|
|
63
|
+
});
|
|
64
|
+
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
|
|
65
|
+
awsRoute53RecordExample.overrideLogicalId("example");
|
|
66
|
+
const awsAcmCertificateValidationExample = new AcmCertificateValidation(
|
|
67
|
+
this,
|
|
68
|
+
"example_4",
|
|
69
|
+
{
|
|
70
|
+
certificateArn: example.arn,
|
|
71
|
+
validationRecordFqdns: Token.asList(
|
|
72
|
+
"\${[ for record in \${" +
|
|
73
|
+
awsRoute53RecordExample.fqn +
|
|
74
|
+
"} : record.fqdn]}"
|
|
75
|
+
),
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
|
|
79
|
+
awsAcmCertificateValidationExample.overrideLogicalId("example");
|
|
80
|
+
const awsLbListenerExample = new LbListener(this, "example_5", {
|
|
81
|
+
certificateArn: Token.asString(
|
|
82
|
+
awsAcmCertificateValidationExample.certificateArn
|
|
83
|
+
),
|
|
84
|
+
defaultAction: [
|
|
85
|
+
{
|
|
86
|
+
targetGroupArn: "best-target",
|
|
87
|
+
type: "forward",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
loadBalancerArn: "best-lb-arn",
|
|
91
|
+
});
|
|
92
|
+
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
|
|
93
|
+
awsLbListenerExample.overrideLogicalId("example");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
"
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
exports[`iteration count loops snapshot typescript 1`] = `
|
|
100
|
+
"import { Construct } from "constructs";
|
|
101
|
+
import {
|
|
102
|
+
VariableType,
|
|
103
|
+
TerraformVariable,
|
|
104
|
+
Fn,
|
|
105
|
+
Token,
|
|
106
|
+
TerraformCount,
|
|
107
|
+
TerraformStack,
|
|
108
|
+
} from "cdktn";
|
|
109
|
+
/*
|
|
110
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
111
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
112
|
+
*/
|
|
113
|
+
import { IamUser } from "./.gen/providers/aws/iam-user";
|
|
114
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
115
|
+
class MyConvertedCode extends TerraformStack {
|
|
116
|
+
constructor(scope: Construct, name: string) {
|
|
117
|
+
super(scope, name);
|
|
118
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
119
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
120
|
+
new AwsProvider(this, "aws", {
|
|
121
|
+
region: "us-east-1",
|
|
122
|
+
});
|
|
123
|
+
const users = new TerraformVariable(this, "users", {
|
|
124
|
+
type: VariableType.set(VariableType.STRING),
|
|
125
|
+
});
|
|
126
|
+
/*In most cases loops should be handled in the programming language context and
|
|
127
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
128
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
129
|
+
you need to keep this like it is.*/
|
|
130
|
+
const lbCount = TerraformCount.of(Token.asNumber(Fn.lengthOf(users.value)));
|
|
131
|
+
new IamUser(this, "lb", {
|
|
132
|
+
name: Token.asString(
|
|
133
|
+
Fn.element(users.value, Token.asNumber(lbCount.index))
|
|
134
|
+
),
|
|
135
|
+
path: "/system/",
|
|
136
|
+
tags: {
|
|
137
|
+
"tag-key": "tag-value",
|
|
138
|
+
},
|
|
139
|
+
count: lbCount,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
"
|
|
144
|
+
`;
|
|
145
|
+
|
|
146
|
+
exports[`iteration dynamic blocks snapshot typescript 1`] = `
|
|
147
|
+
"import { Construct } from "constructs";
|
|
148
|
+
import {
|
|
149
|
+
VariableType,
|
|
150
|
+
TerraformVariable,
|
|
151
|
+
Token,
|
|
152
|
+
TerraformIterator,
|
|
153
|
+
Fn,
|
|
154
|
+
TerraformStack,
|
|
155
|
+
} from "cdktn";
|
|
156
|
+
/*
|
|
157
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
158
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
159
|
+
*/
|
|
160
|
+
import { ElasticBeanstalkEnvironment } from "./.gen/providers/aws/elastic-beanstalk-environment";
|
|
161
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
162
|
+
class MyConvertedCode extends TerraformStack {
|
|
163
|
+
constructor(scope: Construct, name: string) {
|
|
164
|
+
super(scope, name);
|
|
165
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
166
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
167
|
+
new AwsProvider(this, "aws", {
|
|
168
|
+
region: "us-east-1",
|
|
169
|
+
});
|
|
170
|
+
const namespace = new TerraformVariable(this, "namespace", {
|
|
171
|
+
type: VariableType.STRING,
|
|
172
|
+
});
|
|
173
|
+
const settings = new TerraformVariable(this, "settings", {
|
|
174
|
+
type: VariableType.list(VariableType.map(VariableType.STRING)),
|
|
175
|
+
});
|
|
176
|
+
/*In most cases loops should be handled in the programming language context and
|
|
177
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
178
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
179
|
+
you need to keep this like it is.*/
|
|
180
|
+
const tfenvtestDynamicIterator0 = TerraformIterator.fromList(
|
|
181
|
+
Token.asAny(settings.value)
|
|
182
|
+
);
|
|
183
|
+
new ElasticBeanstalkEnvironment(this, "tfenvtest", {
|
|
184
|
+
application: "best-app",
|
|
185
|
+
name: "tf-test-name",
|
|
186
|
+
solutionStackName: "64bit Amazon Linux 2018.03 v2.11.4 running Go 1.12.6",
|
|
187
|
+
setting: tfenvtestDynamicIterator0.dynamic({
|
|
188
|
+
name: Fn.lookupNested(tfenvtestDynamicIterator0.value, ['["name"]']),
|
|
189
|
+
namespace: namespace.value,
|
|
190
|
+
value: Fn.lookupNested(tfenvtestDynamicIterator0.value, ['["value"]']),
|
|
191
|
+
}),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
"
|
|
196
|
+
`;
|
|
197
|
+
|
|
198
|
+
exports[`iteration ensure availability zone is not ignored snapshot typescript 1`] = `
|
|
199
|
+
"import { Construct } from "constructs";
|
|
200
|
+
import {
|
|
201
|
+
VariableType,
|
|
202
|
+
TerraformVariable,
|
|
203
|
+
TerraformCount,
|
|
204
|
+
Fn,
|
|
205
|
+
Token,
|
|
206
|
+
TerraformStack,
|
|
207
|
+
} from "cdktn";
|
|
208
|
+
/*
|
|
209
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
210
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
211
|
+
*/
|
|
212
|
+
import { DataAwsAvailabilityZones } from "./.gen/providers/aws/data-aws-availability-zones";
|
|
213
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
214
|
+
import { Subnet } from "./.gen/providers/aws/subnet";
|
|
215
|
+
class MyConvertedCode extends TerraformStack {
|
|
216
|
+
constructor(scope: Construct, name: string) {
|
|
217
|
+
super(scope, name);
|
|
218
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
219
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
220
|
+
new AwsProvider(this, "aws", {
|
|
221
|
+
region: "us-east-1",
|
|
222
|
+
});
|
|
223
|
+
const publicSubnetCount = new TerraformVariable(
|
|
224
|
+
this,
|
|
225
|
+
"public_subnet_count",
|
|
226
|
+
{
|
|
227
|
+
default: 2,
|
|
228
|
+
description: "Number of public subnets to create",
|
|
229
|
+
type: VariableType.NUMBER,
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
const available = new DataAwsAvailabilityZones(this, "available", {
|
|
233
|
+
state: "available",
|
|
234
|
+
});
|
|
235
|
+
/*In most cases loops should be handled in the programming language context and
|
|
236
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
237
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
238
|
+
you need to keep this like it is.*/
|
|
239
|
+
const publicCount = TerraformCount.of(publicSubnetCount.numberValue);
|
|
240
|
+
new Subnet(this, "public", {
|
|
241
|
+
availabilityZone: Token.asString(
|
|
242
|
+
Fn.lookupNested(available.names, [publicCount.index])
|
|
243
|
+
),
|
|
244
|
+
cidrBlock: "10.0.1.0/24",
|
|
245
|
+
vpcId: "10123",
|
|
246
|
+
count: publicCount,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
"
|
|
251
|
+
`;
|
|
252
|
+
|
|
253
|
+
exports[`iteration for each on list using splat snapshot typescript 1`] = `
|
|
254
|
+
"import { Construct } from "constructs";
|
|
255
|
+
import {
|
|
256
|
+
VariableType,
|
|
257
|
+
TerraformVariable,
|
|
258
|
+
Fn,
|
|
259
|
+
Token,
|
|
260
|
+
TerraformIterator,
|
|
261
|
+
TerraformStack,
|
|
262
|
+
} from "cdktn";
|
|
263
|
+
/*
|
|
264
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
265
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
266
|
+
*/
|
|
267
|
+
import { KmsKey } from "./.gen/providers/aws/kms-key";
|
|
268
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
269
|
+
import { S3Bucket } from "./.gen/providers/aws/s3-bucket";
|
|
270
|
+
import { S3BucketObject } from "./.gen/providers/aws/s3-bucket-object";
|
|
271
|
+
class MyConvertedCode extends TerraformStack {
|
|
272
|
+
constructor(scope: Construct, name: string) {
|
|
273
|
+
super(scope, name);
|
|
274
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
275
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
276
|
+
new AwsProvider(this, "aws", {
|
|
277
|
+
region: "us-east-1",
|
|
278
|
+
});
|
|
279
|
+
const buckets = new TerraformVariable(this, "buckets", {
|
|
280
|
+
type: VariableType.list(VariableType.STRING),
|
|
281
|
+
});
|
|
282
|
+
const examplekms = new KmsKey(this, "examplekms", {
|
|
283
|
+
deletionWindowInDays: 7,
|
|
284
|
+
description: "KMS key 1",
|
|
285
|
+
});
|
|
286
|
+
/*In most cases loops should be handled in the programming language context and
|
|
287
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
288
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
289
|
+
you need to keep this like it is.*/
|
|
290
|
+
const examplebucketForEachIterator = TerraformIterator.fromList(
|
|
291
|
+
Token.asAny(Fn.toset(Fn.lookupNested(buckets.value, ["*"])))
|
|
292
|
+
);
|
|
293
|
+
const examplebucket = new S3Bucket(this, "examplebucket", {
|
|
294
|
+
acl: "private",
|
|
295
|
+
bucket: Token.asString(examplebucketForEachIterator.key),
|
|
296
|
+
forEach: examplebucketForEachIterator,
|
|
297
|
+
});
|
|
298
|
+
/*In most cases loops should be handled in the programming language context and
|
|
299
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
300
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
301
|
+
you need to keep this like it is.*/
|
|
302
|
+
const examplebucketObjectForEachIterator = TerraformIterator.fromList(
|
|
303
|
+
Token.asAny(Fn.toset(Fn.lookupNested(examplebucket, ["*"])))
|
|
304
|
+
);
|
|
305
|
+
new S3BucketObject(this, "examplebucket_object", {
|
|
306
|
+
bucket: examplebucketObjectForEachIterator.key,
|
|
307
|
+
key: "someobject",
|
|
308
|
+
kmsKeyId: examplekms.arn,
|
|
309
|
+
source: "index.html",
|
|
310
|
+
forEach: examplebucketObjectForEachIterator,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
"
|
|
315
|
+
`;
|
|
316
|
+
|
|
317
|
+
exports[`iteration for_each loops snapshot typescript 1`] = `
|
|
318
|
+
"import { Construct } from "constructs";
|
|
319
|
+
import {
|
|
320
|
+
VariableType,
|
|
321
|
+
TerraformVariable,
|
|
322
|
+
Token,
|
|
323
|
+
TerraformIterator,
|
|
324
|
+
TerraformStack,
|
|
325
|
+
} from "cdktn";
|
|
326
|
+
/*
|
|
327
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
328
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
329
|
+
*/
|
|
330
|
+
import { IamUser } from "./.gen/providers/aws/iam-user";
|
|
331
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
332
|
+
class MyConvertedCode extends TerraformStack {
|
|
333
|
+
constructor(scope: Construct, name: string) {
|
|
334
|
+
super(scope, name);
|
|
335
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
336
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
337
|
+
new AwsProvider(this, "aws", {
|
|
338
|
+
region: "us-east-1",
|
|
339
|
+
});
|
|
340
|
+
const users = new TerraformVariable(this, "users", {
|
|
341
|
+
type: VariableType.set(VariableType.STRING),
|
|
342
|
+
});
|
|
343
|
+
/*In most cases loops should be handled in the programming language context and
|
|
344
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
345
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
346
|
+
you need to keep this like it is.*/
|
|
347
|
+
const lbForEachIterator = TerraformIterator.fromList(
|
|
348
|
+
Token.asAny(users.value)
|
|
349
|
+
);
|
|
350
|
+
new IamUser(this, "lb", {
|
|
351
|
+
name: Token.asString(lbForEachIterator.key),
|
|
352
|
+
path: "/system/",
|
|
353
|
+
tags: {
|
|
354
|
+
"tag-key": "tag-value",
|
|
355
|
+
},
|
|
356
|
+
forEach: lbForEachIterator,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
"
|
|
361
|
+
`;
|
|
362
|
+
|
|
363
|
+
exports[`iteration for_each with var usage snapshot typescript 1`] = `
|
|
364
|
+
"import { Construct } from "constructs";
|
|
365
|
+
import {
|
|
366
|
+
TerraformVariable,
|
|
367
|
+
Fn,
|
|
368
|
+
Token,
|
|
369
|
+
TerraformIterator,
|
|
370
|
+
TerraformStack,
|
|
371
|
+
} from "cdktn";
|
|
372
|
+
/*
|
|
373
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
374
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
375
|
+
*/
|
|
376
|
+
import { AzureadProvider } from "./.gen/providers/azuread/provider";
|
|
377
|
+
import { User } from "./.gen/providers/azuread/user";
|
|
378
|
+
class MyConvertedCode extends TerraformStack {
|
|
379
|
+
constructor(scope: Construct, name: string) {
|
|
380
|
+
super(scope, name);
|
|
381
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
382
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
383
|
+
new AzureadProvider(this, "azuread", {
|
|
384
|
+
tenantId: "00000000-0000-0000-0000-000000000000",
|
|
385
|
+
});
|
|
386
|
+
const azureAdDomainName = new TerraformVariable(
|
|
387
|
+
this,
|
|
388
|
+
"azure_ad_domain_name",
|
|
389
|
+
{
|
|
390
|
+
description: "domain",
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
const oneSetOfUsers = new TerraformVariable(this, "one_set_of_users", {
|
|
394
|
+
description: "users",
|
|
395
|
+
});
|
|
396
|
+
const otherSetOfUsers = new TerraformVariable(this, "other_set_of_users", {
|
|
397
|
+
description: "users",
|
|
398
|
+
});
|
|
399
|
+
/*In most cases loops should be handled in the programming language context and
|
|
400
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
401
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
402
|
+
you need to keep this like it is.*/
|
|
403
|
+
const azureUsersForEachIterator = TerraformIterator.fromList(
|
|
404
|
+
Token.asAny(Fn.merge([oneSetOfUsers.value, otherSetOfUsers.value]))
|
|
405
|
+
);
|
|
406
|
+
new User(this, "azure_users", {
|
|
407
|
+
displayName: Token.asString(azureUsersForEachIterator.key),
|
|
408
|
+
userPrincipalName:
|
|
409
|
+
"\${" +
|
|
410
|
+
azureUsersForEachIterator.value +
|
|
411
|
+
"\${" +
|
|
412
|
+
azureAdDomainName.value +
|
|
413
|
+
"}",
|
|
414
|
+
forEach: azureUsersForEachIterator,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
"
|
|
419
|
+
`;
|
|
420
|
+
|
|
421
|
+
exports[`iteration nested dynamic blocks snapshot typescript 1`] = `
|
|
422
|
+
"import { Construct } from "constructs";
|
|
423
|
+
import { VariableType, TerraformVariable, Token, TerraformStack } from "cdktn";
|
|
424
|
+
/*
|
|
425
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
426
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
427
|
+
*/
|
|
428
|
+
import { Application } from "./.gen/providers/azuread/application";
|
|
429
|
+
import { AzureadProvider } from "./.gen/providers/azuread/provider";
|
|
430
|
+
class MyConvertedCode extends TerraformStack {
|
|
431
|
+
constructor(scope: Construct, name: string) {
|
|
432
|
+
super(scope, name);
|
|
433
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
434
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
435
|
+
new AzureadProvider(this, "azuread", {
|
|
436
|
+
tenantId: "00000000-0000-0000-0000-000000000000",
|
|
437
|
+
});
|
|
438
|
+
const requiredResourceAccess = new TerraformVariable(
|
|
439
|
+
this,
|
|
440
|
+
"required_resource_access",
|
|
441
|
+
{
|
|
442
|
+
default: [
|
|
443
|
+
{
|
|
444
|
+
resource_access: [
|
|
445
|
+
{
|
|
446
|
+
id: "7ab1d382-f21e-4acd-a863-ba3e13f7da61",
|
|
447
|
+
type: "Role",
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
resource_app_id: "00000003-0000-0000-c000-000000000000",
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
type: VariableType.list(
|
|
454
|
+
VariableType.object({
|
|
455
|
+
resource_access: VariableType.ANY,
|
|
456
|
+
resource_app_id: VariableType.STRING,
|
|
457
|
+
})
|
|
458
|
+
),
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
const bootstrap = new Application(this, "bootstrap", {
|
|
462
|
+
displayName: "test",
|
|
463
|
+
requiredResourceAccess: [],
|
|
464
|
+
groupMembershipClaims: Token.asList("All"),
|
|
465
|
+
});
|
|
466
|
+
/*In most cases loops should be handled in the programming language context and
|
|
467
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
468
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
469
|
+
you need to keep this like it is.*/
|
|
470
|
+
bootstrap.addOverride("dynamic.required_resource_access", {
|
|
471
|
+
for_each: requiredResourceAccess.value,
|
|
472
|
+
content: [
|
|
473
|
+
{
|
|
474
|
+
resource_access: [],
|
|
475
|
+
resource_app_id:
|
|
476
|
+
'\${required_resource_access.value["resource_app_id"]}',
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
});
|
|
480
|
+
/*In most cases loops should be handled in the programming language context and
|
|
481
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
482
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
483
|
+
you need to keep this like it is.*/
|
|
484
|
+
bootstrap.addOverride(
|
|
485
|
+
"dynamic.required_resource_access.0.content.0.dynamic.resource_access",
|
|
486
|
+
{
|
|
487
|
+
for_each: '\${required_resource_access.value["resource_access"]}',
|
|
488
|
+
content: [
|
|
489
|
+
{
|
|
490
|
+
id: '\${resource_access.value["id"]}',
|
|
491
|
+
type: '\${resource_access.value["type"]}',
|
|
492
|
+
},
|
|
493
|
+
],
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
"
|
|
499
|
+
`;
|
|
500
|
+
|
|
501
|
+
exports[`iteration simple count snapshot typescript 1`] = `
|
|
502
|
+
"import { Construct } from "constructs";
|
|
503
|
+
import { Token, TerraformCount, TerraformStack } from "cdktn";
|
|
504
|
+
/*
|
|
505
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
506
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
507
|
+
*/
|
|
508
|
+
import { Instance } from "./.gen/providers/aws/instance";
|
|
509
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
510
|
+
class MyConvertedCode extends TerraformStack {
|
|
511
|
+
constructor(scope: Construct, name: string) {
|
|
512
|
+
super(scope, name);
|
|
513
|
+
new AwsProvider(this, "aws", {
|
|
514
|
+
region: "us-east-1",
|
|
515
|
+
});
|
|
516
|
+
/*In most cases loops should be handled in the programming language context and
|
|
517
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
518
|
+
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
|
|
519
|
+
you need to keep this like it is.*/
|
|
520
|
+
const multipleServersCount = TerraformCount.of(Token.asNumber("4"));
|
|
521
|
+
new Instance(this, "multiple_servers", {
|
|
522
|
+
ami: "ami-0c2b8ca1dad447f8a",
|
|
523
|
+
instanceType: "t2.micro",
|
|
524
|
+
tags: {
|
|
525
|
+
Name: "Server \${" + multipleServersCount.index + "}",
|
|
526
|
+
},
|
|
527
|
+
count: multipleServersCount,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
"
|
|
532
|
+
`;
|