@cdktn/hcl2cdk 0.26.0-pre.20 → 0.26.0-pre.21

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 (92) hide show
  1. package/package.json +8 -7
  2. package/.spec.swcrc +0 -22
  3. package/build/__tests__/coerceType.test.d.ts +0 -2
  4. package/build/__tests__/coerceType.test.js +0 -165
  5. package/build/__tests__/expressionToTs.test.d.ts +0 -6
  6. package/build/__tests__/expressionToTs.test.js +0 -693
  7. package/build/__tests__/expressions.test.d.ts +0 -4
  8. package/build/__tests__/expressions.test.js +0 -424
  9. package/build/__tests__/findExpressionType.test.d.ts +0 -6
  10. package/build/__tests__/findExpressionType.test.js +0 -105
  11. package/build/__tests__/functions.test.d.ts +0 -6
  12. package/build/__tests__/functions.test.js +0 -615
  13. package/build/__tests__/generation.test.d.ts +0 -6
  14. package/build/__tests__/generation.test.js +0 -45
  15. package/build/__tests__/jsii-rosetta-workarounds.test.d.ts +0 -2
  16. package/build/__tests__/jsii-rosetta-workarounds.test.js +0 -86
  17. package/build/__tests__/partialCode.test.d.ts +0 -6
  18. package/build/__tests__/partialCode.test.js +0 -390
  19. package/build/__tests__/terraformSchema.test.d.ts +0 -6
  20. package/build/__tests__/terraformSchema.test.js +0 -105
  21. package/build/__tests__/testHelpers.d.ts +0 -7
  22. package/build/__tests__/testHelpers.js +0 -15
  23. package/jest.config.js +0 -25
  24. package/package.sh +0 -9
  25. package/src/__tests__/coerceType.test.ts +0 -207
  26. package/src/__tests__/expressionToTs.test.ts +0 -1167
  27. package/src/__tests__/expressions.test.ts +0 -541
  28. package/src/__tests__/findExpressionType.test.ts +0 -112
  29. package/src/__tests__/functions.test.ts +0 -764
  30. package/src/__tests__/generation.test.ts +0 -72
  31. package/src/__tests__/jsii-rosetta-workarounds.test.ts +0 -145
  32. package/src/__tests__/partialCode.test.ts +0 -432
  33. package/src/__tests__/terraformSchema.test.ts +0 -107
  34. package/src/__tests__/testHelpers.ts +0 -11
  35. package/src/coerceType.ts +0 -261
  36. package/src/dynamic-blocks.ts +0 -61
  37. package/src/expressions.ts +0 -968
  38. package/src/function-bindings/functions.generated.ts +0 -1211
  39. package/src/function-bindings/functions.ts +0 -104
  40. package/src/generation.ts +0 -1189
  41. package/src/index.ts +0 -584
  42. package/src/iteration.ts +0 -156
  43. package/src/jsii-rosetta-workarounds.ts +0 -145
  44. package/src/partialCode.ts +0 -132
  45. package/src/provider.ts +0 -60
  46. package/src/references.ts +0 -193
  47. package/src/schema.ts +0 -74
  48. package/src/terraformSchema.ts +0 -182
  49. package/src/types.ts +0 -58
  50. package/src/utils.ts +0 -19
  51. package/src/variables.ts +0 -214
  52. package/test/__snapshots__/backends.test.ts.snap +0 -70
  53. package/test/__snapshots__/externals.test.ts.snap +0 -37
  54. package/test/__snapshots__/granular-imports.test.ts.snap +0 -180
  55. package/test/__snapshots__/imports.test.ts.snap +0 -159
  56. package/test/__snapshots__/iteration.test.ts.snap +0 -532
  57. package/test/__snapshots__/jsiiLanguage.test.ts.snap +0 -347
  58. package/test/__snapshots__/locals.test.ts.snap +0 -55
  59. package/test/__snapshots__/modules.test.ts.snap +0 -127
  60. package/test/__snapshots__/outputs.test.ts.snap +0 -77
  61. package/test/__snapshots__/partialCode.test.ts.snap +0 -120
  62. package/test/__snapshots__/provider.test.ts.snap +0 -128
  63. package/test/__snapshots__/references.test.ts.snap +0 -376
  64. package/test/__snapshots__/resource-meta-properties.test.ts.snap +0 -342
  65. package/test/__snapshots__/resources.test.ts.snap +0 -613
  66. package/test/__snapshots__/tfExpressions.test.ts.snap +0 -537
  67. package/test/__snapshots__/typeCoercion.test.ts.snap +0 -253
  68. package/test/__snapshots__/variables.test.ts.snap +0 -150
  69. package/test/backends.test.ts +0 -75
  70. package/test/convertProject.test.ts +0 -256
  71. package/test/externals.test.ts +0 -35
  72. package/test/globalSetup.ts +0 -224
  73. package/test/globalTeardown.ts +0 -11
  74. package/test/granular-imports.test.ts +0 -161
  75. package/test/hcl2cdk.test.ts +0 -88
  76. package/test/helpers/convert.ts +0 -544
  77. package/test/helpers/tmp.ts +0 -40
  78. package/test/imports.test.ts +0 -141
  79. package/test/iteration.test.ts +0 -342
  80. package/test/jsiiLanguage.test.ts +0 -73
  81. package/test/locals.test.ts +0 -47
  82. package/test/modules.test.ts +0 -143
  83. package/test/outputs.test.ts +0 -69
  84. package/test/partialCode.test.ts +0 -25
  85. package/test/provider.test.ts +0 -106
  86. package/test/references.test.ts +0 -287
  87. package/test/resource-meta-properties.test.ts +0 -288
  88. package/test/resources.test.ts +0 -551
  89. package/test/tfExpressions.test.ts +0 -300
  90. package/test/typeCoercion.test.ts +0 -154
  91. package/test/variables.test.ts +0 -96
  92. package/tsconfig.json +0 -47
@@ -1,253 +0,0 @@
1
- // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
-
3
- exports[`type coercion coerces string literal to number snapshot typescript 1`] = `
4
- "import { Construct } from "constructs";
5
- import { Op, 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 { AwsProvider } from "./.gen/providers/aws/provider";
11
- import { SecurityGroupRule } from "./.gen/providers/aws/security-group-rule";
12
- class MyConvertedCode extends TerraformStack {
13
- constructor(scope: Construct, name: string) {
14
- super(scope, name);
15
- new AwsProvider(this, "aws", {
16
- region: "us-east-1",
17
- });
18
- new SecurityGroupRule(this, "client_alb_allow_outbound", {
19
- cidrBlocks: ["0.0.0.0/0"],
20
- description: "Allow any outbound traffic.",
21
- fromPort: 0,
22
- ipv6CidrBlocks: ["::/0"],
23
- protocol: Token.asString(Op.negate(1)),
24
- securityGroupId: "sg-1234567890",
25
- toPort: 0,
26
- type: "egress",
27
- });
28
- }
29
- }
30
- "
31
- `;
32
-
33
- exports[`type coercion expressions need to be coerced to required type snapshot typescript 1`] = `
34
- "import { Construct } from "constructs";
35
- import {
36
- VariableType,
37
- TerraformVariable,
38
- Fn,
39
- Token,
40
- TerraformStack,
41
- } from "cdktn";
42
- /*
43
- * Provider bindings are generated by running \`cdktn get\`.
44
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
45
- */
46
- import { EksCluster } from "./.gen/providers/aws/eks-cluster";
47
- import { AwsProvider } from "./.gen/providers/aws/provider";
48
- class MyConvertedCode extends TerraformStack {
49
- constructor(scope: Construct, name: string) {
50
- super(scope, name);
51
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
52
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
53
- new AwsProvider(this, "aws", {
54
- region: "us-east-1",
55
- });
56
- const exampleSpotAndFargateName = new TerraformVariable(
57
- this,
58
- "example_spot_and_fargate_name",
59
- {
60
- type: VariableType.STRING,
61
- }
62
- );
63
- const privateSubnets = new TerraformVariable(this, "private_subnets", {
64
- type: VariableType.list(
65
- VariableType.object({
66
- id: VariableType.STRING,
67
- })
68
- ),
69
- });
70
- const publicSubnets = new TerraformVariable(this, "public_subnets", {
71
- type: VariableType.list(
72
- VariableType.object({
73
- id: VariableType.STRING,
74
- })
75
- ),
76
- });
77
- const roleArn = new TerraformVariable(this, "role_arn", {
78
- type: VariableType.STRING,
79
- });
80
- new EksCluster(this, "example_spot_and_fargate_eks_cluster", {
81
- name: exampleSpotAndFargateName.stringValue,
82
- roleArn: roleArn.stringValue,
83
- vpcConfig: {
84
- subnetIds: Token.asList(
85
- Fn.concat([
86
- Fn.lookupNested(privateSubnets.value, ["*", "id"]),
87
- Fn.lookupNested(publicSubnets.value, ["*", "id"]),
88
- ])
89
- ),
90
- },
91
- });
92
- }
93
- }
94
- "
95
- `;
96
-
97
- exports[`type coercion function arguments get coerced to the correct type snapshot typescript 1`] = `
98
- "import { Construct } from "constructs";
99
- import {
100
- VariableType,
101
- TerraformVariable,
102
- Token,
103
- Fn,
104
- TerraformStack,
105
- } from "cdktn";
106
- /*
107
- * Provider bindings are generated by running \`cdktn get\`.
108
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
109
- */
110
- import { AwsProvider } from "./.gen/providers/aws/provider";
111
- import { Route53Record } from "./.gen/providers/aws/route53-record";
112
- class MyConvertedCode extends TerraformStack {
113
- constructor(scope: Construct, name: string) {
114
- super(scope, name);
115
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
116
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
117
- new AwsProvider(this, "aws", {
118
- region: "us-east-1",
119
- });
120
- const zoneId = new TerraformVariable(this, "zone_id", {
121
- type: VariableType.STRING,
122
- });
123
- new Route53Record(this, "example_aws_route53_simple_record", {
124
- name: "example.com",
125
- records: ["example"],
126
- ttl: Token.asNumber("300"),
127
- type: "TXT",
128
- zoneId: Token.asString(
129
- Fn.textencodebase64(zoneId.stringValue, "UTF-16LE")
130
- ),
131
- });
132
- }
133
- }
134
- "
135
- `;
136
-
137
- exports[`type coercion references used in resource for_eachs need to understand how the value is used snapshot typescript 1`] = `
138
- "import { Construct } from "constructs";
139
- import {
140
- VariableType,
141
- TerraformVariable,
142
- Token,
143
- TerraformIterator,
144
- Fn,
145
- TerraformStack,
146
- } from "cdktn";
147
- /*
148
- * Provider bindings are generated by running \`cdktn get\`.
149
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
150
- */
151
- import { IamUserGroupMembership } from "./.gen/providers/aws/iam-user-group-membership";
152
- import { AwsProvider } from "./.gen/providers/aws/provider";
153
- class MyConvertedCode extends TerraformStack {
154
- constructor(scope: Construct, name: string) {
155
- super(scope, name);
156
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
157
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
158
- new AwsProvider(this, "aws", {
159
- region: "us-east-1",
160
- });
161
- const iamGroupsUsers = new TerraformVariable(this, "iam_groups_users", {
162
- type: VariableType.map(
163
- VariableType.object({
164
- groups: VariableType.ANY,
165
- })
166
- ),
167
- });
168
- /*In most cases loops should be handled in the programming language context and
169
- not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
170
- 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
171
- you need to keep this like it is.*/
172
- const iamUserGroupMembershipUserGroupsForEachIterator =
173
- TerraformIterator.fromList(Token.asAny(iamGroupsUsers.value));
174
- new IamUserGroupMembership(this, "iam_user_group_membership_user_groups", {
175
- groups: Token.asList(
176
- Fn.lookupNested(iamUserGroupMembershipUserGroupsForEachIterator.value, [
177
- '["groups"]',
178
- ])
179
- ),
180
- user: Token.asString(iamUserGroupMembershipUserGroupsForEachIterator.key),
181
- forEach: iamUserGroupMembershipUserGroupsForEachIterator,
182
- });
183
- }
184
- }
185
- "
186
- `;
187
-
188
- exports[`type coercion references used in resources need to use Token.asString snapshot typescript 1`] = `
189
- "import { Construct } from "constructs";
190
- import { Token, TerraformStack } from "cdktn";
191
- /*
192
- * Provider bindings are generated by running \`cdktn get\`.
193
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
194
- */
195
- import { AwsProvider } from "./.gen/providers/aws/provider";
196
- import { Route53Record } from "./.gen/providers/aws/route53-record";
197
- import { Route53Zone } from "./.gen/providers/aws/route53-zone";
198
- class MyConvertedCode extends TerraformStack {
199
- constructor(scope: Construct, name: string) {
200
- super(scope, name);
201
- new AwsProvider(this, "aws", {
202
- region: "us-east-1",
203
- });
204
- const exampleAwsRoute53SimpleZone = new Route53Zone(
205
- this,
206
- "example_aws_route53_simple_zone",
207
- {
208
- name: "example.com",
209
- }
210
- );
211
- new Route53Record(this, "example_aws_route53_simple_record", {
212
- name: "example.com",
213
- records: ["example"],
214
- ttl: Token.asNumber("300"),
215
- type: "TXT",
216
- zoneId: exampleAwsRoute53SimpleZone.zoneId,
217
- });
218
- }
219
- }
220
- "
221
- `;
222
-
223
- exports[`type coercion variables used in resources need to use stringValue snapshot typescript 1`] = `
224
- "import { Construct } from "constructs";
225
- import { VariableType, TerraformVariable, Token, TerraformStack } from "cdktn";
226
- /*
227
- * Provider bindings are generated by running \`cdktn get\`.
228
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
229
- */
230
- import { AwsProvider } from "./.gen/providers/aws/provider";
231
- import { Route53Record } from "./.gen/providers/aws/route53-record";
232
- class MyConvertedCode extends TerraformStack {
233
- constructor(scope: Construct, name: string) {
234
- super(scope, name);
235
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
236
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
237
- new AwsProvider(this, "aws", {
238
- region: "us-east-1",
239
- });
240
- const zoneId = new TerraformVariable(this, "zone_id", {
241
- type: VariableType.STRING,
242
- });
243
- new Route53Record(this, "example_aws_route53_simple_record", {
244
- name: "example.com",
245
- records: ["example"],
246
- ttl: Token.asNumber("300"),
247
- type: "TXT",
248
- zoneId: zoneId.stringValue,
249
- });
250
- }
251
- }
252
- "
253
- `;
@@ -1,150 +0,0 @@
1
- // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
-
3
- exports[`variables basic snapshot typescript 1`] = `
4
- "import { Construct } from "constructs";
5
- import { VariableType, TerraformVariable, 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 { DataLocalFile } from "./.gen/providers/local/data-local-file";
11
- import { LocalProvider } from "./.gen/providers/local/provider";
12
- class MyConvertedCode extends TerraformStack {
13
- constructor(scope: Construct, name: string) {
14
- super(scope, name);
15
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
16
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
17
- new LocalProvider(this, "local", {});
18
- const imageId = new TerraformVariable(this, "image_id", {
19
- type: VariableType.STRING,
20
- });
21
- new DataLocalFile(this, "foo", {
22
- filename: "./\${" + imageId.value + "}.img",
23
- });
24
- }
25
- }
26
- "
27
- `;
28
-
29
- exports[`variables complex type and default snapshot typescript 1`] = `
30
- "import { Construct } from "constructs";
31
- import {
32
- VariableType,
33
- TerraformVariable,
34
- Fn,
35
- Token,
36
- TerraformStack,
37
- } from "cdktn";
38
- /*
39
- * Provider bindings are generated by running \`cdktn get\`.
40
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
41
- */
42
- import { DataLocalFile } from "./.gen/providers/local/data-local-file";
43
- import { LocalProvider } from "./.gen/providers/local/provider";
44
- class MyConvertedCode extends TerraformStack {
45
- constructor(scope: Construct, name: string) {
46
- super(scope, name);
47
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
48
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
49
- new LocalProvider(this, "local", {});
50
- const dockerPorts = new TerraformVariable(this, "docker_ports", {
51
- default: [
52
- {
53
- external: 8300,
54
- internal: 8300,
55
- protocol: "tcp",
56
- },
57
- ],
58
- type: VariableType.list(
59
- VariableType.object({
60
- external: VariableType.NUMBER,
61
- internal: VariableType.NUMBER,
62
- protocol: VariableType.STRING,
63
- })
64
- ),
65
- });
66
- new DataLocalFile(this, "foo", {
67
- filename:
68
- "./" +
69
- Token.asString(Fn.lookupNested(dockerPorts.value, ["0", "protocol"])) +
70
- ".img",
71
- });
72
- }
73
- }
74
- "
75
- `;
76
-
77
- exports[`variables sensitive and required snapshot typescript 1`] = `
78
- "import { Construct } from "constructs";
79
- import {
80
- VariableType,
81
- TerraformVariable,
82
- Fn,
83
- Token,
84
- TerraformStack,
85
- } from "cdktn";
86
- /*
87
- * Provider bindings are generated by running \`cdktn get\`.
88
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
89
- */
90
- import { DataLocalFile } from "./.gen/providers/local/data-local-file";
91
- import { LocalProvider } from "./.gen/providers/local/provider";
92
- class MyConvertedCode extends TerraformStack {
93
- constructor(scope: Construct, name: string) {
94
- super(scope, name);
95
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
96
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
97
- new LocalProvider(this, "local", {});
98
- const userInformation = new TerraformVariable(this, "user_information", {
99
- sensitive: true,
100
- nullable: false,
101
- type: VariableType.object({
102
- address: VariableType.STRING,
103
- name: VariableType.STRING,
104
- }),
105
- });
106
- new DataLocalFile(this, "foo", {
107
- filename:
108
- "./" +
109
- Token.asString(Fn.lookupNested(userInformation.value, ["name"])) +
110
- ".img",
111
- });
112
- }
113
- }
114
- "
115
- `;
116
-
117
- exports[`variables validations snapshot typescript 1`] = `
118
- "import { Construct } from "constructs";
119
- import { VariableType, TerraformVariable, TerraformStack } from "cdktn";
120
- /*
121
- * Provider bindings are generated by running \`cdktn get\`.
122
- * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
123
- */
124
- import { DataLocalFile } from "./.gen/providers/local/data-local-file";
125
- import { LocalProvider } from "./.gen/providers/local/provider";
126
- class MyConvertedCode extends TerraformStack {
127
- constructor(scope: Construct, name: string) {
128
- super(scope, name);
129
- /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
130
- You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
131
- new LocalProvider(this, "local", {});
132
- const imageId = new TerraformVariable(this, "image_id", {
133
- description: "The id of the machine image (AMI) to use for the server.",
134
- validation: [
135
- {
136
- errorMessage:
137
- "The image_id value must be a valid AMI id, starting with ami-.",
138
- condition:
139
- '\${length(var.image_id) > 4 && substr(var.image_id, 0, 4) == "ami-"}',
140
- },
141
- ],
142
- type: VariableType.STRING,
143
- });
144
- new DataLocalFile(this, "foo", {
145
- filename: "./\${" + imageId.value + "}.img",
146
- });
147
- }
148
- }
149
- "
150
- `;
@@ -1,75 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
- import { testCase, Synth, Snapshot } from "./helpers/convert";
4
-
5
- describe("backends", () => {
6
- testCase.test(
7
- "local backend",
8
- `
9
- terraform {
10
- backend "local" {
11
- path = "relative/path/to/terraform.tfstate"
12
- }
13
- }
14
- `,
15
- [],
16
- Snapshot.yes,
17
- Synth.yes,
18
- );
19
-
20
- testCase.test(
21
- "remote backend",
22
- `
23
- terraform {
24
- backend "remote" {
25
- hostname = "app.terraform.io"
26
- organization = "company"
27
-
28
- workspaces {
29
- name = "my-app-prod"
30
- }
31
- }
32
- }
33
- `,
34
- [],
35
- Snapshot.yes,
36
- Synth.yes,
37
- );
38
-
39
- testCase.test(
40
- "remote state",
41
- `
42
- data "terraform_remote_state" "vpc" {
43
- backend = "remote"
44
-
45
- config = {
46
- organization = "hashicorp"
47
- workspaces = {
48
- name = "vpc-prod"
49
- }
50
- }
51
- }
52
- `,
53
- [],
54
- Snapshot.yes,
55
- Synth.yes,
56
- );
57
-
58
- testCase.test(
59
- "remote state types",
60
- `
61
- data "terraform_remote_state" "s3" {
62
- backend = "s3"
63
-
64
- config = {
65
- bucket = "mybucket"
66
- key = "path/to/my/key"
67
- region = "us-east-1"
68
- }
69
- }
70
- `,
71
- [],
72
- Snapshot.yes,
73
- Synth.yes,
74
- );
75
- });