@cdktn/hcl2cdk 0.24.0-pre.45 → 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,180 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
|
2
|
+
|
|
3
|
+
exports[`granular-imports nested sub-structs snapshot typescript 1`] = `
|
|
4
|
+
"import { Construct } from "constructs";
|
|
5
|
+
import { Token, 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 { Deployment } from "./.gen/providers/kubernetes/deployment";
|
|
11
|
+
import { KubernetesProvider } from "./.gen/providers/kubernetes/provider";
|
|
12
|
+
class MyConvertedCode extends TerraformStack {
|
|
13
|
+
constructor(scope: Construct, name: string) {
|
|
14
|
+
super(scope, name);
|
|
15
|
+
new KubernetesProvider(this, "kubernetes", {});
|
|
16
|
+
new Deployment(this, "example", {
|
|
17
|
+
metadata: {
|
|
18
|
+
labels: {
|
|
19
|
+
test: "MyExampleApp",
|
|
20
|
+
},
|
|
21
|
+
name: "terraform-example",
|
|
22
|
+
},
|
|
23
|
+
spec: {
|
|
24
|
+
replicas: Token.asString(3),
|
|
25
|
+
selector: {
|
|
26
|
+
matchLabels: {
|
|
27
|
+
test: "MyExampleApp",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
template: {
|
|
31
|
+
metadata: {
|
|
32
|
+
labels: {
|
|
33
|
+
test: "MyExampleApp",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
spec: {
|
|
37
|
+
container: [
|
|
38
|
+
{
|
|
39
|
+
image: "nginx:1.21.6",
|
|
40
|
+
livenessProbe: {
|
|
41
|
+
httpGet: {
|
|
42
|
+
httpHeader: [
|
|
43
|
+
{
|
|
44
|
+
name: "X-Custom-Header",
|
|
45
|
+
value: "Awesome",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
path: "/",
|
|
49
|
+
port: Token.asString(80),
|
|
50
|
+
},
|
|
51
|
+
initialDelaySeconds: 3,
|
|
52
|
+
periodSeconds: 3,
|
|
53
|
+
},
|
|
54
|
+
name: "example",
|
|
55
|
+
resources: {
|
|
56
|
+
limits: {
|
|
57
|
+
cpu: "0.5",
|
|
58
|
+
memory: "512Mi",
|
|
59
|
+
},
|
|
60
|
+
requests: {
|
|
61
|
+
cpu: "250m",
|
|
62
|
+
memory: "50Mi",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
"
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
exports[`granular-imports should handle most cdktf and provider constructs for granular imports snapshot typescript 1`] = `
|
|
77
|
+
"import { Construct } from "constructs";
|
|
78
|
+
import {
|
|
79
|
+
VariableType,
|
|
80
|
+
TerraformVariable,
|
|
81
|
+
TerraformOutput,
|
|
82
|
+
Token,
|
|
83
|
+
TerraformCount,
|
|
84
|
+
Op,
|
|
85
|
+
RemoteBackend,
|
|
86
|
+
TerraformStack,
|
|
87
|
+
} from "cdktn";
|
|
88
|
+
/*
|
|
89
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
90
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
91
|
+
*/
|
|
92
|
+
import { ComputeAutoscaler } from "./.gen/providers/google/compute-autoscaler";
|
|
93
|
+
import { ComputeInstanceGroupManager } from "./.gen/providers/google/compute-instance-group-manager";
|
|
94
|
+
import { GoogleProvider } from "./.gen/providers/google/provider";
|
|
95
|
+
import { DataLocalFile } from "./.gen/providers/local/data-local-file";
|
|
96
|
+
import { LocalProvider } from "./.gen/providers/local/provider";
|
|
97
|
+
class MyConvertedCode extends TerraformStack {
|
|
98
|
+
constructor(scope: Construct, name: string) {
|
|
99
|
+
super(scope, name);
|
|
100
|
+
new RemoteBackend(this, {
|
|
101
|
+
organization: "example_corp",
|
|
102
|
+
workspaces: [
|
|
103
|
+
{
|
|
104
|
+
name: "my-app-prod",
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
|
|
109
|
+
You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
|
|
110
|
+
new GoogleProvider(this, "google", {
|
|
111
|
+
project: "my-project",
|
|
112
|
+
region: "us-central1",
|
|
113
|
+
});
|
|
114
|
+
new LocalProvider(this, "local", {});
|
|
115
|
+
const imageId = new TerraformVariable(this, "image_id", {
|
|
116
|
+
type: VariableType.STRING,
|
|
117
|
+
});
|
|
118
|
+
const cdktnTerraformOutputImageId = new TerraformOutput(
|
|
119
|
+
this,
|
|
120
|
+
"image_id_3",
|
|
121
|
+
{
|
|
122
|
+
value: imageId.value,
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
|
|
126
|
+
cdktnTerraformOutputImageId.overrideLogicalId("image_id");
|
|
127
|
+
/*In most cases loops should be handled in the programming language context and
|
|
128
|
+
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
|
|
129
|
+
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
|
|
130
|
+
you need to keep this like it is.*/
|
|
131
|
+
const exampleCount = TerraformCount.of(Token.asNumber("2"));
|
|
132
|
+
new ComputeAutoscaler(this, "example", {
|
|
133
|
+
autoscalingPolicy: {
|
|
134
|
+
cooldownPeriod: 60,
|
|
135
|
+
cpuUtilization: {
|
|
136
|
+
target: 0.5,
|
|
137
|
+
},
|
|
138
|
+
maxReplicas: 8,
|
|
139
|
+
minReplicas: 2,
|
|
140
|
+
},
|
|
141
|
+
name: "example-autoscaler",
|
|
142
|
+
target: "target-for-example-autoscaler",
|
|
143
|
+
zone: "us-east1-b",
|
|
144
|
+
count: exampleCount,
|
|
145
|
+
});
|
|
146
|
+
const defaultVar = new ComputeInstanceGroupManager(this, "default", {
|
|
147
|
+
baseInstanceName: "autoscaler-sample",
|
|
148
|
+
name: "my-igm",
|
|
149
|
+
targetPools: [],
|
|
150
|
+
version: [
|
|
151
|
+
{
|
|
152
|
+
instanceTemplate: Token.asString(1),
|
|
153
|
+
name: "primary",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
zone: "us-central1-f",
|
|
157
|
+
});
|
|
158
|
+
new DataLocalFile(this, "foo", {
|
|
159
|
+
filename: "./\${" + imageId.value + "}.img",
|
|
160
|
+
});
|
|
161
|
+
const googleComputeAutoscalerDefault = new ComputeAutoscaler(
|
|
162
|
+
this,
|
|
163
|
+
"default_7",
|
|
164
|
+
{
|
|
165
|
+
autoscalingPolicy: {
|
|
166
|
+
cooldownPeriod: 60,
|
|
167
|
+
maxReplicas: Token.asNumber(Op.add(5, 2)),
|
|
168
|
+
minReplicas: 1,
|
|
169
|
+
},
|
|
170
|
+
name: "my-autoscaler",
|
|
171
|
+
target: defaultVar.id,
|
|
172
|
+
zone: "us-central1-f",
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
|
|
176
|
+
googleComputeAutoscalerDefault.overrideLogicalId("default");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
"
|
|
180
|
+
`;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
|
2
|
+
|
|
3
|
+
exports[`imports Not supported import into expansion (for_each or count) snapshot typescript 1`] = `
|
|
4
|
+
"import { Construct } from "constructs";
|
|
5
|
+
import { 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 { AwsProvider } from "./.gen/providers/aws/provider";
|
|
11
|
+
class MyConvertedCode extends TerraformStack {
|
|
12
|
+
constructor(scope: Construct, name: string) {
|
|
13
|
+
super(scope, name);
|
|
14
|
+
new AwsProvider(this, "aws", {
|
|
15
|
+
region: "us-east-1",
|
|
16
|
+
});
|
|
17
|
+
/*CDKTN does not support imports into resources with count or for_each yet, please remove the import block importing i-abcd123457 into aws_instance.example[0] from your configuration*/
|
|
18
|
+
/*CDKTN does not support imports into resources with count or for_each yet, please remove the import block importing i-abcd1234 into aws_instance.example["foo"] from your configuration*/
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
"
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`imports Not supported import into module snapshot typescript 1`] = `
|
|
25
|
+
"import { Construct } from "constructs";
|
|
26
|
+
import { TerraformStack } from "cdktn";
|
|
27
|
+
/*
|
|
28
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
29
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
30
|
+
*/
|
|
31
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
32
|
+
class MyConvertedCode extends TerraformStack {
|
|
33
|
+
constructor(scope: Construct, name: string) {
|
|
34
|
+
super(scope, name);
|
|
35
|
+
new AwsProvider(this, "aws", {
|
|
36
|
+
region: "us-east-1",
|
|
37
|
+
});
|
|
38
|
+
/*CDKTN does not support imports into modules yet, please remove the import block importing i-abcd1234 into module.instances.aws_instance.example from your configuration*/
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
"
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
exports[`imports import with config and provider snapshot typescript 1`] = `
|
|
45
|
+
"import { Construct } from "constructs";
|
|
46
|
+
import { TerraformStack } from "cdktn";
|
|
47
|
+
/*
|
|
48
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
49
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
50
|
+
*/
|
|
51
|
+
import { Instance } from "./.gen/providers/aws/instance";
|
|
52
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
53
|
+
class MyConvertedCode extends TerraformStack {
|
|
54
|
+
constructor(scope: Construct, name: string) {
|
|
55
|
+
super(scope, name);
|
|
56
|
+
new AwsProvider(this, "aws", {
|
|
57
|
+
alias: "us",
|
|
58
|
+
region: "us-east-1",
|
|
59
|
+
});
|
|
60
|
+
const example = new Instance(this, "example", {
|
|
61
|
+
ami: "some-ami",
|
|
62
|
+
instanceType: "t3.micro",
|
|
63
|
+
});
|
|
64
|
+
/*This import was configured with a provider. CDKTN does support this, but the cdktn convert command does not yet. Please add the provider reference manually. See https://cdktn.io/docs/concepts/resources#importing-resources for more information.*/
|
|
65
|
+
example.importFrom("i-abcd1234");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
"
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
exports[`imports import with config snapshot typescript 1`] = `
|
|
72
|
+
"import { Construct } from "constructs";
|
|
73
|
+
import { TerraformStack } from "cdktn";
|
|
74
|
+
/*
|
|
75
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
76
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
77
|
+
*/
|
|
78
|
+
import { Instance } from "./.gen/providers/aws/instance";
|
|
79
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
80
|
+
class MyConvertedCode extends TerraformStack {
|
|
81
|
+
constructor(scope: Construct, name: string) {
|
|
82
|
+
super(scope, name);
|
|
83
|
+
new AwsProvider(this, "aws", {
|
|
84
|
+
region: "us-east-1",
|
|
85
|
+
});
|
|
86
|
+
const example = new Instance(this, "example", {
|
|
87
|
+
ami: "some-ami",
|
|
88
|
+
instanceType: "t3.micro",
|
|
89
|
+
});
|
|
90
|
+
example.importFrom("i-abcd1234");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
"
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
exports[`imports multiple imports snapshot typescript 1`] = `
|
|
97
|
+
"import { Construct } from "constructs";
|
|
98
|
+
import { TerraformStack } from "cdktn";
|
|
99
|
+
/*
|
|
100
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
101
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
102
|
+
*/
|
|
103
|
+
import { Instance } from "./.gen/providers/aws/instance";
|
|
104
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
105
|
+
class MyConvertedCode extends TerraformStack {
|
|
106
|
+
constructor(scope: Construct, name: string) {
|
|
107
|
+
super(scope, name);
|
|
108
|
+
new AwsProvider(this, "aws", {
|
|
109
|
+
region: "us-east-1",
|
|
110
|
+
});
|
|
111
|
+
Instance.generateConfigForImport(this, "example", "i-abcd1234");
|
|
112
|
+
Instance.generateConfigForImport(this, "toBeImported", "i-abcd1234567");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
"
|
|
116
|
+
`;
|
|
117
|
+
|
|
118
|
+
exports[`imports single import snapshot typescript 1`] = `
|
|
119
|
+
"import { Construct } from "constructs";
|
|
120
|
+
import { TerraformStack } from "cdktn";
|
|
121
|
+
/*
|
|
122
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
123
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
124
|
+
*/
|
|
125
|
+
import { Instance } from "./.gen/providers/aws/instance";
|
|
126
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
127
|
+
class MyConvertedCode extends TerraformStack {
|
|
128
|
+
constructor(scope: Construct, name: string) {
|
|
129
|
+
super(scope, name);
|
|
130
|
+
new AwsProvider(this, "aws", {
|
|
131
|
+
region: "us-east-1",
|
|
132
|
+
});
|
|
133
|
+
Instance.generateConfigForImport(this, "example", "i-abcd1234");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
"
|
|
137
|
+
`;
|
|
138
|
+
|
|
139
|
+
exports[`imports single import with provider snapshot typescript 1`] = `
|
|
140
|
+
"import { Construct } from "constructs";
|
|
141
|
+
import { TerraformStack } from "cdktn";
|
|
142
|
+
/*
|
|
143
|
+
* Provider bindings are generated by running \`cdktn get\`.
|
|
144
|
+
* See https://cdktn.io/docs/concepts/providers#import-providers for more details.
|
|
145
|
+
*/
|
|
146
|
+
import { Instance } from "./.gen/providers/aws/instance";
|
|
147
|
+
import { AwsProvider } from "./.gen/providers/aws/provider";
|
|
148
|
+
class MyConvertedCode extends TerraformStack {
|
|
149
|
+
constructor(scope: Construct, name: string) {
|
|
150
|
+
super(scope, name);
|
|
151
|
+
new AwsProvider(this, "aws", {
|
|
152
|
+
alias: "europe",
|
|
153
|
+
region: "eu-west-1",
|
|
154
|
+
});
|
|
155
|
+
Instance.generateConfigForImport(this, "example", "i-abcd1234");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
"
|
|
159
|
+
`;
|