@cdktn/hcl2cdk 0.24.0-pre.6 → 0.24.0-pre.60

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 (84) hide show
  1. package/.spec.swcrc +22 -0
  2. package/LICENSE +355 -0
  3. package/README.md +1 -1
  4. package/build/__tests__/jsii-rosetta-workarounds.test.js +2 -2
  5. package/build/expressions.js +3 -4
  6. package/build/function-bindings/functions.generated.d.ts +50 -1
  7. package/build/function-bindings/functions.generated.js +76 -4
  8. package/build/generation.js +2 -2
  9. package/build/index.d.ts +20 -20
  10. package/build/index.js +4 -4
  11. package/build/references.js +2 -3
  12. package/build/schema.d.ts +60 -60
  13. package/build/utils.d.ts +1 -1
  14. package/build/utils.js +3 -3
  15. package/jest.config.js +18 -11
  16. package/package.json +36 -25
  17. package/package.sh +1 -1
  18. package/src/__tests__/coerceType.test.ts +207 -0
  19. package/src/__tests__/expressionToTs.test.ts +1167 -0
  20. package/src/__tests__/expressions.test.ts +541 -0
  21. package/src/__tests__/findExpressionType.test.ts +112 -0
  22. package/src/__tests__/functions.test.ts +768 -0
  23. package/src/__tests__/generation.test.ts +72 -0
  24. package/src/__tests__/jsii-rosetta-workarounds.test.ts +145 -0
  25. package/src/__tests__/partialCode.test.ts +432 -0
  26. package/src/__tests__/terraformSchema.test.ts +107 -0
  27. package/src/__tests__/testHelpers.ts +11 -0
  28. package/src/coerceType.ts +261 -0
  29. package/src/dynamic-blocks.ts +61 -0
  30. package/src/expressions.ts +968 -0
  31. package/src/function-bindings/functions.generated.ts +1211 -0
  32. package/src/function-bindings/functions.ts +104 -0
  33. package/src/generation.ts +1189 -0
  34. package/src/index.ts +584 -0
  35. package/src/iteration.ts +156 -0
  36. package/src/jsii-rosetta-workarounds.ts +145 -0
  37. package/src/partialCode.ts +132 -0
  38. package/src/provider.ts +60 -0
  39. package/src/references.ts +193 -0
  40. package/src/schema.ts +74 -0
  41. package/src/terraformSchema.ts +182 -0
  42. package/src/types.ts +58 -0
  43. package/src/utils.ts +19 -0
  44. package/src/variables.ts +214 -0
  45. package/test/__snapshots__/backends.test.ts.snap +70 -0
  46. package/test/__snapshots__/externals.test.ts.snap +37 -0
  47. package/test/__snapshots__/granular-imports.test.ts.snap +180 -0
  48. package/test/__snapshots__/imports.test.ts.snap +159 -0
  49. package/test/__snapshots__/iteration.test.ts.snap +532 -0
  50. package/test/__snapshots__/jsiiLanguage.test.ts.snap +347 -0
  51. package/test/__snapshots__/locals.test.ts.snap +55 -0
  52. package/test/__snapshots__/modules.test.ts.snap +127 -0
  53. package/test/__snapshots__/outputs.test.ts.snap +77 -0
  54. package/test/__snapshots__/partialCode.test.ts.snap +120 -0
  55. package/test/__snapshots__/provider.test.ts.snap +128 -0
  56. package/test/__snapshots__/references.test.ts.snap +376 -0
  57. package/test/__snapshots__/resource-meta-properties.test.ts.snap +342 -0
  58. package/test/__snapshots__/resources.test.ts.snap +613 -0
  59. package/test/__snapshots__/tfExpressions.test.ts.snap +537 -0
  60. package/test/__snapshots__/typeCoercion.test.ts.snap +253 -0
  61. package/test/__snapshots__/variables.test.ts.snap +150 -0
  62. package/test/backends.test.ts +75 -0
  63. package/test/convertProject.test.ts +257 -0
  64. package/test/externals.test.ts +35 -0
  65. package/test/globalSetup.ts +224 -0
  66. package/test/globalTeardown.ts +11 -0
  67. package/test/granular-imports.test.ts +161 -0
  68. package/test/hcl2cdk.test.ts +88 -0
  69. package/test/helpers/convert.ts +543 -0
  70. package/test/helpers/tmp.ts +25 -0
  71. package/test/imports.test.ts +141 -0
  72. package/test/iteration.test.ts +342 -0
  73. package/test/jsiiLanguage.test.ts +73 -0
  74. package/test/locals.test.ts +47 -0
  75. package/test/modules.test.ts +143 -0
  76. package/test/outputs.test.ts +69 -0
  77. package/test/partialCode.test.ts +25 -0
  78. package/test/provider.test.ts +106 -0
  79. package/test/references.test.ts +287 -0
  80. package/test/resource-meta-properties.test.ts +288 -0
  81. package/test/resources.test.ts +551 -0
  82. package/test/tfExpressions.test.ts +300 -0
  83. package/test/typeCoercion.test.ts +154 -0
  84. package/test/variables.test.ts +96 -0
@@ -0,0 +1,120 @@
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
+
3
+ exports[`Partial code (missing properties) missing top-level required property snapshot csharp 1`] = `
4
+ "using Constructs;
5
+ using Io.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
+ using docker.Config;
11
+ class MyConfig
12
+ {
13
+ public object Data { get; set; }
14
+ }
15
+ class MyConvertedCode : TerraformStack
16
+ {
17
+ public MyConvertedCode(Construct scope, string name, MyConfig config) : base(scope, name)
18
+ {
19
+ new Config(this, "service_config", new ConfigConfig {
20
+ Name = "my-config",
21
+ Data = config.Data
22
+ });
23
+ }
24
+ }"
25
+ `;
26
+
27
+ exports[`Partial code (missing properties) missing top-level required property snapshot go 1`] = `
28
+ "import "github.com/aws/constructs-go/constructs"
29
+ import "github.com/open-constructs/cdk-terrain-go/cdktn"
30
+ /*
31
+ * Provider bindings are generated by running \`cdktn get\`.
32
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
33
+ */
34
+ import "cdk.tf/go/stack/generated/docker/config"
35
+ type myConfig struct {
36
+ data interface{}
37
+ }
38
+ type myConvertedCode struct {
39
+ TerraformStack
40
+ }
41
+
42
+ func newMyConvertedCode(scope Construct, name *string, config myConfig) *myConvertedCode {
43
+ this := &myConvertedCode{}
44
+ newTerraformStack_Override(this, scope, name)
45
+ genprovidersdockerconfig.NewConfig(this, jsii.String("service_config"), &ConfigConfig{
46
+ name: jsii.String("my-config"),
47
+ data: config.data,
48
+ })
49
+ return this
50
+ }"
51
+ `;
52
+
53
+ exports[`Partial code (missing properties) missing top-level required property snapshot java 1`] = `
54
+ "import software.constructs.Construct;
55
+ import io.cdktn.cdktn.TerraformStack;
56
+ /*
57
+ * Provider bindings are generated by running \`cdktn get\`.
58
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
59
+ */
60
+ import imports.docker.config.Config;
61
+ public class MyConfig {
62
+ private Object data;
63
+ public Object getData() {
64
+ return this.data;
65
+ }
66
+ public MyConfig data(Object data) {
67
+ this.data = data;
68
+ return this;
69
+ }
70
+ }
71
+ public class MyConvertedCode extends TerraformStack {
72
+ public MyConvertedCode(Construct scope, String name, MyConfig config) {
73
+ super(scope, name);
74
+ new Config(this, "service_config", new ConfigConfig()
75
+ .name("my-config")
76
+ .data(config.getData())
77
+ );
78
+ }
79
+ }"
80
+ `;
81
+
82
+ exports[`Partial code (missing properties) missing top-level required property snapshot python 1`] = `
83
+ "from constructs import Construct
84
+ from cdktn import TerraformStack
85
+ #
86
+ # Provider bindings are generated by running \`cdktn get\`.
87
+ # See https://cdktn.io/docs/concepts/providers#import-providers for more details.
88
+ #
89
+ from imports.docker.config import Config
90
+ class MyConvertedCode(TerraformStack):
91
+ def __init__(self, scope, name, *, data):
92
+ super().__init__(scope, name)
93
+ Config(self, "service_config",
94
+ name="my-config",
95
+ data=data
96
+ )"
97
+ `;
98
+
99
+ exports[`Partial code (missing properties) missing top-level required property snapshot typescript 1`] = `
100
+ "import { Construct } from "constructs";
101
+ import { TerraformStack } from "cdktn";
102
+ /*
103
+ * Provider bindings are generated by running \`cdktn get\`.
104
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
105
+ */
106
+ import { Config } from "./.gen/providers/docker/config";
107
+ interface MyConfig {
108
+ data: any;
109
+ }
110
+ class MyConvertedCode extends TerraformStack {
111
+ constructor(scope: Construct, name: string, config: MyConfig) {
112
+ super(scope, name);
113
+ new Config(this, "service_config", {
114
+ name: "my-config",
115
+ data: config.data,
116
+ });
117
+ }
118
+ }
119
+ "
120
+ `;
@@ -0,0 +1,128 @@
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
+
3
+ exports[`provider empty provider 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 { DockerProvider } from "./.gen/providers/docker/provider";
11
+ class MyConvertedCode extends TerraformStack {
12
+ constructor(scope: Construct, name: string) {
13
+ super(scope, name);
14
+ new DockerProvider(this, "docker", {});
15
+ }
16
+ }
17
+ "
18
+ `;
19
+
20
+ exports[`provider null provider snapshot typescript 1`] = `
21
+ "import { Construct } from "constructs";
22
+ import { TerraformStack } from "cdktn";
23
+ /*
24
+ * Provider bindings are generated by running \`cdktn get\`.
25
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
26
+ */
27
+ import { NullProvider } from "./.gen/providers/null/provider";
28
+ import { Resource } from "./.gen/providers/null/resource";
29
+ class MyConvertedCode extends TerraformStack {
30
+ constructor(scope: Construct, name: string) {
31
+ super(scope, name);
32
+ new NullProvider(this, "null", {});
33
+ new Resource(this, "test", {});
34
+ }
35
+ }
36
+ "
37
+ `;
38
+
39
+ exports[`provider provider alias snapshot typescript 1`] = `
40
+ "import { Construct } from "constructs";
41
+ import { TerraformStack } 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 { Instance } from "./.gen/providers/aws/instance";
47
+ import { AwsProvider } from "./.gen/providers/aws/provider";
48
+ import * as Vpc from "./.gen/modules/terraform-aws-modules/aws/vpc";
49
+ class MyConvertedCode extends TerraformStack {
50
+ constructor(scope: Construct, name: string) {
51
+ super(scope, name);
52
+ new AwsProvider(this, "aws", {
53
+ region: "us-east-1",
54
+ });
55
+ const west = new AwsProvider(this, "aws_1", {
56
+ alias: "west",
57
+ region: "us-west-2",
58
+ });
59
+ new Vpc.Vpc(this, "vpc", {
60
+ providers: [
61
+ {
62
+ moduleAlias: "aws",
63
+ provider: west,
64
+ },
65
+ ],
66
+ });
67
+ new Instance(this, "foo", {
68
+ foo: "bar",
69
+ provider: west,
70
+ });
71
+ }
72
+ }
73
+ "
74
+ `;
75
+
76
+ exports[`provider provider with complex config snapshot typescript 1`] = `
77
+ "import { Construct } from "constructs";
78
+ import { TerraformStack } from "cdktn";
79
+ /*
80
+ * Provider bindings are generated by running \`cdktn get\`.
81
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
82
+ */
83
+ import { AwsProvider } from "./.gen/providers/aws/provider";
84
+ class MyConvertedCode extends TerraformStack {
85
+ constructor(scope: Construct, name: string) {
86
+ super(scope, name);
87
+ new AwsProvider(this, "aws", {
88
+ accessKey: "mock_access_key",
89
+ endpoints: [
90
+ {
91
+ dynamodb: "http://localhost:8000",
92
+ },
93
+ ],
94
+ region: "us-east-1",
95
+ secretKey: "mock_secret_key",
96
+ skipCredentialsValidation: true,
97
+ skipRequestingAccountId: true,
98
+ });
99
+ }
100
+ }
101
+ "
102
+ `;
103
+
104
+ exports[`provider required namespaced provider snapshot typescript 1`] = `
105
+ "import { Construct } from "constructs";
106
+ import { TerraformVariable, TerraformStack } from "cdktn";
107
+ /*
108
+ * Provider bindings are generated by running \`cdktn get\`.
109
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
110
+ */
111
+ import { Auth0Provider } from "./.gen/providers/auth0/provider";
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
+ const domain = new TerraformVariable(this, "domain", {
118
+ description: "A domain",
119
+ });
120
+ new Auth0Provider(this, "auth0", {
121
+ clientId: "42",
122
+ clientSecret: "secret",
123
+ domain: domain.stringValue,
124
+ });
125
+ }
126
+ }
127
+ "
128
+ `;
@@ -0,0 +1,376 @@
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
+
3
+ exports[`references aliased duplicate provider with var reference snapshot typescript 1`] = `
4
+ "import { Construct } from "constructs";
5
+ import { 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 { Auth0Provider } from "./.gen/providers/auth0/provider";
11
+ class MyConvertedCode extends TerraformStack {
12
+ constructor(scope: Construct, name: string) {
13
+ super(scope, name);
14
+ /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
15
+ You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
16
+ const clientId = new TerraformVariable(this, "client_id", {
17
+ description: "A client_id",
18
+ });
19
+ const clientSecret = new TerraformVariable(this, "client_secret", {
20
+ description: "A client_secret",
21
+ });
22
+ const domain = new TerraformVariable(this, "domain", {
23
+ description: "A domain",
24
+ });
25
+ new Auth0Provider(this, "auth0", {
26
+ clientId: clientId.stringValue,
27
+ clientSecret: clientSecret.stringValue,
28
+ domain: domain.stringValue,
29
+ });
30
+ new Auth0Provider(this, "auth0_4", {
31
+ alias: "private_auth0",
32
+ clientId: clientId.stringValue,
33
+ clientSecret: clientSecret.stringValue,
34
+ debug: true,
35
+ domain: domain.stringValue,
36
+ });
37
+ }
38
+ }
39
+ "
40
+ `;
41
+
42
+ exports[`references data local_file snapshot typescript 1`] = `
43
+ "import { Construct } from "constructs";
44
+ import { TerraformStack } from "cdktn";
45
+ /*
46
+ * Provider bindings are generated by running \`cdktn get\`.
47
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
48
+ */
49
+ import { DataLocalFile } from "./.gen/providers/local/data-local-file";
50
+ import { LocalProvider } from "./.gen/providers/local/provider";
51
+ class MyConvertedCode extends TerraformStack {
52
+ constructor(scope: Construct, name: string) {
53
+ super(scope, name);
54
+ new LocalProvider(this, "local", {});
55
+ new DataLocalFile(this, "_01_please_verify", {
56
+ filename: "./email_templates/01_please_verify/template.html",
57
+ });
58
+ }
59
+ }
60
+ "
61
+ `;
62
+
63
+ exports[`references data references snapshot typescript 1`] = `
64
+ "import { Construct } from "constructs";
65
+ import { VariableType, TerraformVariable, Token, TerraformStack } from "cdktn";
66
+ /*
67
+ * Provider bindings are generated by running \`cdktn get\`.
68
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
69
+ */
70
+ import { DataAwsS3Bucket } from "./.gen/providers/aws/data-aws-s3-bucket";
71
+ import { AwsProvider } from "./.gen/providers/aws/provider";
72
+ import { S3BucketObject } from "./.gen/providers/aws/s3-bucket-object";
73
+ class MyConvertedCode extends TerraformStack {
74
+ constructor(scope: Construct, name: string) {
75
+ super(scope, name);
76
+ /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
77
+ You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
78
+ new AwsProvider(this, "aws", {
79
+ region: "us-east-1",
80
+ });
81
+ const bucketName = new TerraformVariable(this, "bucket_name", {
82
+ default: "demo",
83
+ type: VariableType.STRING,
84
+ });
85
+ const examplebucket = new DataAwsS3Bucket(this, "examplebucket", {
86
+ bucket: bucketName.stringValue,
87
+ });
88
+ new S3BucketObject(this, "examplebucket_object", {
89
+ bucket: Token.asString(examplebucket.arn),
90
+ key: "someobject",
91
+ source: "index.html",
92
+ });
93
+ }
94
+ }
95
+ "
96
+ `;
97
+
98
+ exports[`references double references snapshot typescript 1`] = `
99
+ "import { Construct } from "constructs";
100
+ import { VariableType, TerraformVariable, TerraformStack } from "cdktn";
101
+ /*
102
+ * Provider bindings are generated by running \`cdktn get\`.
103
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
104
+ */
105
+ import { AwsProvider } from "./.gen/providers/aws/provider";
106
+ import { S3Bucket } from "./.gen/providers/aws/s3-bucket";
107
+ class MyConvertedCode extends TerraformStack {
108
+ constructor(scope: Construct, name: string) {
109
+ super(scope, name);
110
+ /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
111
+ You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
112
+ new AwsProvider(this, "aws", {
113
+ region: "us-east-1",
114
+ });
115
+ const bucketName = new TerraformVariable(this, "bucket_name", {
116
+ default: "demo",
117
+ type: VariableType.STRING,
118
+ });
119
+ new S3Bucket(this, "examplebucket", {
120
+ acl: "private",
121
+ bucket: bucketName.stringValue,
122
+ tags: {
123
+ "tag-key": bucketName.stringValue,
124
+ },
125
+ });
126
+ }
127
+ }
128
+ "
129
+ `;
130
+
131
+ exports[`references locals references snapshot typescript 1`] = `
132
+ "import { Construct } from "constructs";
133
+ import { TerraformStack } from "cdktn";
134
+ /*
135
+ * Provider bindings are generated by running \`cdktn get\`.
136
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
137
+ */
138
+ import { AwsProvider } from "./.gen/providers/aws/provider";
139
+ import { S3Bucket } from "./.gen/providers/aws/s3-bucket";
140
+ class MyConvertedCode extends TerraformStack {
141
+ constructor(scope: Construct, name: string) {
142
+ super(scope, name);
143
+ new AwsProvider(this, "aws", {
144
+ region: "us-east-1",
145
+ });
146
+ const bucketName = "foo";
147
+ new S3Bucket(this, "examplebucket", {
148
+ acl: "private",
149
+ bucket: bucketName,
150
+ });
151
+ }
152
+ }
153
+ "
154
+ `;
155
+
156
+ exports[`references provider with var reference snapshot typescript 1`] = `
157
+ "import { Construct } from "constructs";
158
+ import { TerraformVariable, TerraformStack } from "cdktn";
159
+ /*
160
+ * Provider bindings are generated by running \`cdktn get\`.
161
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
162
+ */
163
+ import { Auth0Provider } from "./.gen/providers/auth0/provider";
164
+ class MyConvertedCode extends TerraformStack {
165
+ constructor(scope: Construct, name: string) {
166
+ super(scope, name);
167
+ /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
168
+ You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
169
+ const domain = new TerraformVariable(this, "domain", {
170
+ description: "A domain",
171
+ });
172
+ new Auth0Provider(this, "auth0", {
173
+ clientId: "client_id",
174
+ clientSecret: "client_secret",
175
+ domain: domain.stringValue,
176
+ });
177
+ }
178
+ }
179
+ "
180
+ `;
181
+
182
+ exports[`references resource references snapshot typescript 1`] = `
183
+ "import { Construct } from "constructs";
184
+ import { TerraformStack } from "cdktn";
185
+ /*
186
+ * Provider bindings are generated by running \`cdktn get\`.
187
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
188
+ */
189
+ import { KmsKey } from "./.gen/providers/aws/kms-key";
190
+ import { AwsProvider } from "./.gen/providers/aws/provider";
191
+ import { S3Bucket } from "./.gen/providers/aws/s3-bucket";
192
+ import { S3BucketObject } from "./.gen/providers/aws/s3-bucket-object";
193
+ class MyConvertedCode extends TerraformStack {
194
+ constructor(scope: Construct, name: string) {
195
+ super(scope, name);
196
+ new AwsProvider(this, "aws", {
197
+ region: "us-east-1",
198
+ });
199
+ const examplekms = new KmsKey(this, "examplekms", {
200
+ deletionWindowInDays: 7,
201
+ description: "KMS key 1",
202
+ });
203
+ const examplebucket = new S3Bucket(this, "examplebucket", {
204
+ acl: "private",
205
+ bucket: "examplebuckettftest",
206
+ });
207
+ new S3BucketObject(this, "examplebucket_object", {
208
+ bucket: examplebucket.id,
209
+ key: "someobject",
210
+ kmsKeyId: examplekms.arn,
211
+ source: "index.html",
212
+ });
213
+ }
214
+ }
215
+ "
216
+ `;
217
+
218
+ exports[`references resource references with HCL functions snapshot typescript 1`] = `
219
+ "import { Construct } from "constructs";
220
+ import { Token, TerraformCount, Fn, TerraformStack } from "cdktn";
221
+ /*
222
+ * Provider bindings are generated by running \`cdktn get\`.
223
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
224
+ */
225
+ import { KmsKey } from "./.gen/providers/aws/kms-key";
226
+ import { AwsProvider } from "./.gen/providers/aws/provider";
227
+ import { S3Bucket } from "./.gen/providers/aws/s3-bucket";
228
+ import { S3BucketObject } from "./.gen/providers/aws/s3-bucket-object";
229
+ class MyConvertedCode extends TerraformStack {
230
+ constructor(scope: Construct, name: string) {
231
+ super(scope, name);
232
+ new AwsProvider(this, "aws", {
233
+ region: "us-east-1",
234
+ });
235
+ const examplekms = new KmsKey(this, "examplekms", {
236
+ deletionWindowInDays: 7,
237
+ description: "KMS key 1",
238
+ });
239
+ /*In most cases loops should be handled in the programming language context and
240
+ not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
241
+ 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
242
+ you need to keep this like it is.*/
243
+ const examplebucketCount = TerraformCount.of(Token.asNumber("2"));
244
+ const examplebucket = new S3Bucket(this, "examplebucket", {
245
+ acl: "private",
246
+ bucket: "examplebuckettftest-\${" + examplebucketCount.index + "}",
247
+ count: examplebucketCount,
248
+ });
249
+ new S3BucketObject(this, "examplebucket_object", {
250
+ bucket: Token.asString(
251
+ Fn.lookupNested(Fn.element(examplebucket, 0), ["id"])
252
+ ),
253
+ key: "someobject",
254
+ kmsKeyId: examplekms.arn,
255
+ source: "index.html",
256
+ });
257
+ }
258
+ }
259
+ "
260
+ `;
261
+
262
+ exports[`references resources with splat expressions should work snapshot typescript 1`] = `
263
+ "import { Construct } from "constructs";
264
+ import {
265
+ VariableType,
266
+ TerraformVariable,
267
+ TerraformOutput,
268
+ Fn,
269
+ TerraformStack,
270
+ } from "cdktn";
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
+ const keyValuePairs = new TerraformVariable(this, "key_value_pairs", {
277
+ default: [
278
+ {
279
+ bar: "not food",
280
+ foo: "foo",
281
+ },
282
+ {
283
+ bar: "not beer",
284
+ foo: "bar",
285
+ },
286
+ ],
287
+ description: "List of key value pairs",
288
+ type: VariableType.list(
289
+ VariableType.object({
290
+ bar: VariableType.STRING,
291
+ foo: VariableType.STRING,
292
+ })
293
+ ),
294
+ });
295
+ new TerraformOutput(this, "values", {
296
+ value: Fn.lookupNested(keyValuePairs.value, ["*", "bar"]),
297
+ });
298
+ }
299
+ }
300
+ "
301
+ `;
302
+
303
+ exports[`references variable references snapshot typescript 1`] = `
304
+ "import { Construct } from "constructs";
305
+ import { VariableType, TerraformVariable, TerraformStack } from "cdktn";
306
+ /*
307
+ * Provider bindings are generated by running \`cdktn get\`.
308
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
309
+ */
310
+ import { AwsProvider } from "./.gen/providers/aws/provider";
311
+ import { S3Bucket } from "./.gen/providers/aws/s3-bucket";
312
+ class MyConvertedCode extends TerraformStack {
313
+ constructor(scope: Construct, name: string) {
314
+ super(scope, name);
315
+ /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
316
+ You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
317
+ new AwsProvider(this, "aws", {
318
+ region: "us-east-1",
319
+ });
320
+ const bucketName = new TerraformVariable(this, "bucket_name", {
321
+ default: "demo",
322
+ type: VariableType.STRING,
323
+ });
324
+ new S3Bucket(this, "examplebucket", {
325
+ acl: "private",
326
+ bucket: bucketName.stringValue,
327
+ });
328
+ }
329
+ }
330
+ "
331
+ `;
332
+
333
+ exports[`references variables with maps need to use accessor syntax snapshot typescript 1`] = `
334
+ "import { Construct } from "constructs";
335
+ import {
336
+ VariableType,
337
+ TerraformVariable,
338
+ Fn,
339
+ Token,
340
+ TerraformStack,
341
+ } from "cdktn";
342
+ /*
343
+ * Provider bindings are generated by running \`cdktn get\`.
344
+ * See https://cdktn.io/docs/concepts/providers#import-providers for more details.
345
+ */
346
+ import { Eip } from "./.gen/providers/aws/eip";
347
+ import { AwsProvider } from "./.gen/providers/aws/provider";
348
+ class MyConvertedCode extends TerraformStack {
349
+ constructor(scope: Construct, name: string) {
350
+ super(scope, name);
351
+ /*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
352
+ You can read more about this at https://cdktn.io/docs/concepts/variables-and-outputs#input-variables*/
353
+ new AwsProvider(this, "aws", {
354
+ region: "us-east-1",
355
+ });
356
+ const defaultTags = new TerraformVariable(this, "default_tags", {
357
+ default: [
358
+ {
359
+ project: "Learning Live with AWS & HashiCorp",
360
+ },
361
+ ],
362
+ description: "Map of default tags to apply to resources",
363
+ type: VariableType.map(VariableType.STRING),
364
+ });
365
+ new Eip(this, "nat", {
366
+ tags: {
367
+ Name:
368
+ Token.asString(Fn.lookupNested(defaultTags.value, ["project"])) +
369
+ "-nat-eip",
370
+ },
371
+ vpc: true,
372
+ });
373
+ }
374
+ }
375
+ "
376
+ `;