diff --git a/examples/go/google/main.go b/examples/go/google/main.go index cef153d866..0a55294190 100644 --- a/examples/go/google/main.go +++ b/examples/go/google/main.go @@ -18,6 +18,7 @@ func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack { Zone: jsii.String("us-west1"), Project: jsii.String("dschmidt-cdk-test"), }) + local.NewLocalProvider(stack, jsii.String("local"), &local.LocalProviderConfig{}) sa := google.NewServiceAccount(stack, jsii.String("sa"), &google.ServiceAccountConfig{ AccountId: jsii.String("cluster-admin"), diff --git a/examples/typescript/backends/s3/main.ts b/examples/typescript/backends/s3/main.ts index a1ee97aaaa..9c98ae61f4 100644 --- a/examples/typescript/backends/s3/main.ts +++ b/examples/typescript/backends/s3/main.ts @@ -5,12 +5,16 @@ import { S3Backend, DataTerraformRemoteStateS3, } from "cdktf"; -import { DataAwsS3BucketObject } from "./.gen/providers/aws"; +import { AwsProvider, DataAwsS3BucketObject } from "./.gen/providers/aws"; class MyStack extends TerraformStack { constructor(scope: Construct, name: string) { super(scope, name); + new AwsProvider(this, "aws", { + region: "eu-central-1", + }); + // Only one backend is supported by Terraform // S3 Backend - https://www.terraform.io/docs/backends/types/s3.html diff --git a/packages/cdktf/lib/terraform-stack.ts b/packages/cdktf/lib/terraform-stack.ts index 52e3131ddc..c80c7c2e8d 100644 --- a/packages/cdktf/lib/terraform-stack.ts +++ b/packages/cdktf/lib/terraform-stack.ts @@ -2,6 +2,8 @@ import { Construct, IConstruct, ISynthesisSession, Node } from "constructs"; import { resolve } from "./_tokens"; import * as fs from "fs"; import * as path from "path"; +import camelcase = require("camelcase"); // ES module interop + import { TerraformElement } from "./terraform-element"; import { deepMerge } from "./util"; import { TerraformProvider } from "./terraform-provider"; @@ -14,6 +16,9 @@ import { Manifest } from "./manifest"; const STACK_SYMBOL = Symbol.for("ckdtf/TerraformStack"); +const pascalCase = (str: string) => + camelcase(str.replace(/[-/]/g, "_"), { pascalCase: true }); + export interface TerraformStackMetadata { readonly stackName: string; readonly version: string; @@ -171,6 +176,34 @@ export class TerraformStack extends Construct { return resolve(this, tf); } + public validateTerraform(tfConfig: any): void { + // validate provider has been initialized + const requiredProviders = [ + ...new Set( + Object.keys({ ...tfConfig?.resource, ...tfConfig?.data }).map( + (providerName) => providerName.split("_")[0] + ) + ), + ]; + + const providers = Object.keys(tfConfig?.provider || {}); + + const uninitializedProviders = requiredProviders.filter( + (reqProvider) => + !providers.includes(reqProvider) && reqProvider !== "terraform" // e.g. terraform_remote_state + ); + + if (uninitializedProviders.length > 0) { + throw new Error( + `Validation failed: Could not find provider initialization for provider ${uninitializedProviders.join( + " & " + )}. Please initialize the provider(s) as ${uninitializedProviders + .map((p) => pascalCase(p + "Provider")) + .join(", ")} in the Stack ${Node.of(this).id}` + ); + } + } + protected onSynthesize(session: ISynthesisSession) { const manifest = session.manifest as Manifest; const stackManifest = manifest.forStack(this); @@ -181,9 +214,12 @@ export class TerraformStack extends Construct { ); if (!fs.existsSync(workingDirectory)) fs.mkdirSync(workingDirectory); + const tfConfig = this.toTerraform(); + this.validateTerraform(tfConfig); + fs.writeFileSync( path.join(session.outdir, stackManifest.synthesizedStackPath), - JSON.stringify(this.toTerraform(), undefined, 2) + JSON.stringify(tfConfig, undefined, 2) ); } } diff --git a/packages/cdktf/lib/testing.ts b/packages/cdktf/lib/testing.ts index 840d0e0df8..3d681c7d06 100644 --- a/packages/cdktf/lib/testing.ts +++ b/packages/cdktf/lib/testing.ts @@ -37,7 +37,10 @@ export class Testing { * Returns the Terraform synthesized JSON. */ public static synth(stack: TerraformStack) { - return JSON.stringify(stack.toTerraform(), null, 2); + const tfConfig = stack.toTerraform(); + stack.validateTerraform(tfConfig); + + return JSON.stringify(tfConfig, null, 2); } /* istanbul ignore next */ diff --git a/packages/cdktf/package.json b/packages/cdktf/package.json index daf7452644..a427f79ba7 100644 --- a/packages/cdktf/package.json +++ b/packages/cdktf/package.json @@ -79,15 +79,16 @@ }, "license": "MPL-2.0", "devDependencies": { + "@types/camelcase": "^5.2.0", "@types/jest": "^25.1.2", "@types/node": "^14.0.26", "@typescript-eslint/eslint-plugin": "^4.28.1", "@typescript-eslint/parser": "^4.28.1", "constructs": "^3.3.75", "eslint": "^7.29.0", + "jest": "^26.6.3", "jsii": "^1.29.0", "jsii-pacmak": "^1.29.0", - "jest": "^26.6.3", "json-schema-to-typescript": "^8.0.1", "typescript": "^3.9.7" }, @@ -98,11 +99,15 @@ ] }, "dependencies": { - "archiver": "5.3.0" + "archiver": "5.3.0", + "camelcase": "^6.2.0" }, - "bundledDependencies": ["archiver"], + "bundledDependencies": [ + "archiver", + "camelcase" + ], "stability": "experimental", "peerDependencies": { "constructs": "^3.3.75" } -} \ No newline at end of file +} diff --git a/packages/cdktf/test/__snapshots__/data-source.test.js.snap b/packages/cdktf/test/__snapshots__/data-source.test.js.snap index d4521a48c5..4fe708302c 100644 --- a/packages/cdktf/test/__snapshots__/data-source.test.js.snap +++ b/packages/cdktf/test/__snapshots__/data-source.test.js.snap @@ -9,6 +9,11 @@ exports[`dependent data source 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"resource\\": { \\"test_resource\\": { \\"resource\\": { @@ -49,6 +54,11 @@ exports[`minimal configuration 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"data\\": { \\"test_data_source\\": { \\"test\\": { @@ -73,6 +83,11 @@ exports[`with boolean map 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"data\\": { \\"test_data_source\\": { \\"test\\": { @@ -110,6 +125,11 @@ exports[`with complex computed list 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"data\\": { \\"test_data_source\\": { \\"test\\": { @@ -147,6 +167,11 @@ exports[`with number map 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"data\\": { \\"test_data_source\\": { \\"test\\": { @@ -184,6 +209,11 @@ exports[`with string map 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"data\\": { \\"test_data_source\\": { \\"test\\": { diff --git a/packages/cdktf/test/__snapshots__/local.test.js.snap b/packages/cdktf/test/__snapshots__/local.test.js.snap index 65b4da2c2a..384a3a3ee7 100644 --- a/packages/cdktf/test/__snapshots__/local.test.js.snap +++ b/packages/cdktf/test/__snapshots__/local.test.js.snap @@ -24,6 +24,11 @@ exports[`local reference 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"locals\\": { \\"resource_name\\": \\"my_resource\\" }, diff --git a/packages/cdktf/test/__snapshots__/output.test.js.snap b/packages/cdktf/test/__snapshots__/output.test.js.snap index 55db9f248e..223b6b8ba8 100644 --- a/packages/cdktf/test/__snapshots__/output.test.js.snap +++ b/packages/cdktf/test/__snapshots__/output.test.js.snap @@ -26,6 +26,11 @@ exports[`dependent output 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"resource\\": { \\"test_resource\\": { \\"weird-long-running-resource\\": { diff --git a/packages/cdktf/test/__snapshots__/remote-state.test.js.snap b/packages/cdktf/test/__snapshots__/remote-state.test.js.snap index 7dc4a0eda7..2d9e4d5920 100644 --- a/packages/cdktf/test/__snapshots__/remote-state.test.js.snap +++ b/packages/cdktf/test/__snapshots__/remote-state.test.js.snap @@ -433,6 +433,11 @@ exports[`s3 reference 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"data\\": { \\"terraform_remote_state\\": { \\"remote\\": { diff --git a/packages/cdktf/test/__snapshots__/resource.test.js.snap b/packages/cdktf/test/__snapshots__/resource.test.js.snap index ab1325c4b3..8bcf8c1bff 100644 --- a/packages/cdktf/test/__snapshots__/resource.test.js.snap +++ b/packages/cdktf/test/__snapshots__/resource.test.js.snap @@ -9,6 +9,11 @@ exports[`dependent resource 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"data\\": { \\"test_data_source\\": { \\"data_source\\": { @@ -49,6 +54,11 @@ exports[`do not change capitalization of arbritary nested types 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"resource\\": { \\"test_resource\\": { \\"test\\": { @@ -77,6 +87,11 @@ exports[`do not change capitalization of tags 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"resource\\": { \\"test_resource\\": { \\"test\\": { @@ -105,6 +120,11 @@ exports[`minimal configuration 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"resource\\": { \\"test_resource\\": { \\"test\\": { @@ -163,6 +183,14 @@ exports[`serialize list interpolation 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ], + \\"other\\": [ + {} + ] + }, \\"resource\\": { \\"test_resource\\": { \\"test\\": { @@ -199,6 +227,14 @@ exports[`with complex computed list 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ], + \\"other\\": [ + {} + ] + }, \\"resource\\": { \\"other_test_resource\\": { \\"othertest\\": { diff --git a/packages/cdktf/test/__snapshots__/stack.test.js.snap b/packages/cdktf/test/__snapshots__/stack.test.js.snap index a7af97ed42..ec61992a5a 100644 --- a/packages/cdktf/test/__snapshots__/stack.test.js.snap +++ b/packages/cdktf/test/__snapshots__/stack.test.js.snap @@ -21,7 +21,7 @@ exports[`stack synthesis merges all elements into a single output 1`] = ` } }, \\"provider\\": { - \\"test\\": [ + \\"aws\\": [ { \\"access_key\\": \\"foo\\" } @@ -110,7 +110,7 @@ exports[`stack synthesis no flags 1`] = ` } }, \\"provider\\": { - \\"test\\": [ + \\"aws\\": [ { \\"access_key\\": \\"foo\\" } diff --git a/packages/cdktf/test/__snapshots__/terraform-hcl-module.test.js.snap b/packages/cdktf/test/__snapshots__/terraform-hcl-module.test.js.snap index 5cca21b390..d7e5ab7847 100644 --- a/packages/cdktf/test/__snapshots__/terraform-hcl-module.test.js.snap +++ b/packages/cdktf/test/__snapshots__/terraform-hcl-module.test.js.snap @@ -94,6 +94,11 @@ exports[`depend on module 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"module\\": { \\"test\\": { \\"source\\": \\"../foo\\", @@ -263,6 +268,11 @@ exports[`reference module 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"module\\": { \\"test\\": { \\"source\\": \\"../foo\\", @@ -299,6 +309,11 @@ exports[`reference module list 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"module\\": { \\"test\\": { \\"source\\": \\"../foo\\", diff --git a/packages/cdktf/test/__snapshots__/variable.test.js.snap b/packages/cdktf/test/__snapshots__/variable.test.js.snap index 807c761da3..3181456b66 100644 --- a/packages/cdktf/test/__snapshots__/variable.test.js.snap +++ b/packages/cdktf/test/__snapshots__/variable.test.js.snap @@ -149,6 +149,11 @@ exports[`reference 1`] = ` \\"backend\\": \\"local\\" } }, + \\"provider\\": { + \\"test\\": [ + {} + ] + }, \\"variable\\": { \\"test-variable\\": { \\"type\\": \\"string\\" diff --git a/packages/cdktf/test/data-source.test.ts b/packages/cdktf/test/data-source.test.ts index 774cc41702..a3751cdd42 100644 --- a/packages/cdktf/test/data-source.test.ts +++ b/packages/cdktf/test/data-source.test.ts @@ -1,10 +1,12 @@ import { TerraformStack, Testing, Token } from "../lib"; import { TestResource } from "./helper"; import { TestDataSource } from "./helper/data-source"; +import { TestProvider } from "./helper/provider"; test("minimal configuration", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); new TestDataSource(stack, "test", { name: "foo", @@ -15,6 +17,7 @@ test("minimal configuration", () => { test("with complex computed list", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test-data-source"); + new TestProvider(stack, "provider", {}); const dataSource = new TestDataSource(stack, "test", { name: "foo", @@ -29,6 +32,7 @@ test("with complex computed list", () => { test("with string map", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test-data-source"); + new TestProvider(stack, "provider", {}); const dataSource = new TestDataSource(stack, "test", { name: "foo", @@ -43,6 +47,7 @@ test("with string map", () => { test("with number map", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test-data-source"); + new TestProvider(stack, "provider", {}); const dataSource = new TestDataSource(stack, "test", { name: "foo", @@ -57,6 +62,7 @@ test("with number map", () => { test("with boolean map", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test-data-source"); + new TestProvider(stack, "provider", {}); const dataSource = new TestDataSource(stack, "test", { name: "foo", @@ -71,6 +77,7 @@ test("with boolean map", () => { test("dependent data source", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); const resource = new TestResource(stack, "resource", { name: "foo", diff --git a/packages/cdktf/test/helper/provider.ts b/packages/cdktf/test/helper/provider.ts index e60e22e14b..976e1c9f98 100644 --- a/packages/cdktf/test/helper/provider.ts +++ b/packages/cdktf/test/helper/provider.ts @@ -3,7 +3,8 @@ import { Construct } from "constructs"; export interface TestProviderConfig { alias?: string; - accessKey: string; + accessKey?: string; + type?: string; } export enum TestProviderMetadata { @@ -11,11 +12,11 @@ export enum TestProviderMetadata { } export class TestProvider extends TerraformProvider { - public accessKey: string; + public accessKey?: string; constructor(scope: Construct, id: string, config: TestProviderConfig) { super(scope, id, { - terraformResourceType: TestProviderMetadata.TYPE, + terraformResourceType: config.type || TestProviderMetadata.TYPE, }); this.alias = config.alias; diff --git a/packages/cdktf/test/local.test.ts b/packages/cdktf/test/local.test.ts index a5952157a8..325cc34a21 100644 --- a/packages/cdktf/test/local.test.ts +++ b/packages/cdktf/test/local.test.ts @@ -1,5 +1,6 @@ import { Testing, TerraformStack, TerraformLocal } from "../lib"; import { TestResource } from "./helper"; +import { TestProvider } from "./helper/provider"; test("string local", () => { const app = Testing.app(); @@ -38,6 +39,7 @@ test("object local", () => { test("local reference", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "test", {}); const resourceName = new TerraformLocal( stack, diff --git a/packages/cdktf/test/output.test.ts b/packages/cdktf/test/output.test.ts index 431258501e..6d81e5fedc 100644 --- a/packages/cdktf/test/output.test.ts +++ b/packages/cdktf/test/output.test.ts @@ -1,5 +1,6 @@ import { Testing, TerraformStack, TerraformOutput } from "../lib"; import { TestResource } from "./helper"; +import { TestProvider } from "./helper/provider"; test("number output", () => { const app = Testing.app(); @@ -77,6 +78,7 @@ test("dependent output", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); const resource = new TestResource(stack, "weird-long-running-resource", { name: "foo", }); diff --git a/packages/cdktf/test/remote-state.test.ts b/packages/cdktf/test/remote-state.test.ts index ae3d35f0fd..520a15cbc3 100644 --- a/packages/cdktf/test/remote-state.test.ts +++ b/packages/cdktf/test/remote-state.test.ts @@ -1,6 +1,7 @@ import { Testing, TerraformStack } from "../lib"; import * as b from "../lib/backends"; import { TestResource } from "./helper"; +import { TestProvider } from "./helper/provider"; test("local", () => { const app = Testing.app(); @@ -289,6 +290,8 @@ test("s3 reference", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); + const remoteState = new b.DataTerraformRemoteStateS3(stack, "remote", { bucket: "mybucket", key: "path/to/my/key", diff --git a/packages/cdktf/test/resource.test.ts b/packages/cdktf/test/resource.test.ts index b0b2aacd46..7e2d6383b8 100644 --- a/packages/cdktf/test/resource.test.ts +++ b/packages/cdktf/test/resource.test.ts @@ -5,6 +5,7 @@ import { TestDataSource } from "./helper/data-source"; test("minimal configuration", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); new TestResource(stack, "test", { name: "foo", @@ -64,6 +65,10 @@ test("resource fqn", () => { test("serialize list interpolation", () => { const app = Testing.app(); const stack = new TerraformStack(app, "tests"); + new TestProvider(stack, "provider", {}); + new TestProvider(stack, "other_provider", { + type: "other", + }); const resource = new TestResource(stack, "test", { name: "bar", @@ -78,6 +83,10 @@ test("serialize list interpolation", () => { test("with complex computed list", () => { const app = Testing.app(); const stack = new TerraformStack(app, "tests"); + new TestProvider(stack, "provider", {}); + new TestProvider(stack, "other_provider", { + type: "other", + }); const otherResource = new OtherTestResource(stack, "othertest", {}); @@ -91,6 +100,7 @@ test("with complex computed list", () => { test("do not change capitalization of tags", () => { const app = Testing.app(); const stack = new TerraformStack(app, "tests"); + new TestProvider(stack, "provider", {}); new TestResource(stack, "test", { name: "bar", @@ -105,6 +115,7 @@ test("do not change capitalization of tags", () => { test("do not change capitalization of arbritary nested types", () => { const app = Testing.app(); const stack = new TerraformStack(app, "tests"); + new TestProvider(stack, "provider", {}); new TestResource(stack, "test", { name: "bar", @@ -119,6 +130,7 @@ test("do not change capitalization of arbritary nested types", () => { test("dependent resource", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); const dataSource = new TestDataSource(stack, "data_source", { name: "foo", diff --git a/packages/cdktf/test/stack.test.ts b/packages/cdktf/test/stack.test.ts index 02bb27717f..5bc3456e18 100644 --- a/packages/cdktf/test/stack.test.ts +++ b/packages/cdktf/test/stack.test.ts @@ -16,6 +16,7 @@ test("stack synthesis merges all elements into a single output", () => { new TestProvider(stack, "test-provider", { accessKey: "foo", + type: "aws", }); new MyResource(stack, "Resource1", { @@ -63,6 +64,7 @@ test("stack synthesis no flags", () => { new TestProvider(stack, "test-provider", { accessKey: "foo", + type: "aws", }); new MyResource(stack, "Resource1", { @@ -81,6 +83,19 @@ test("stack synthesis no flags", () => { expect(Testing.synth(stack)).toMatchSnapshot(); }); +test("stack validation fails with no provider", () => { + const app = Testing.stubVersion(new App({ stackTraces: false })); + const stack = new TerraformStack(app, "MyStack"); + + new MyResource(stack, "Resource1", { + terraformResourceType: "aws_bucket", + }); + + expect(() => Testing.synth(stack)).toThrowErrorMatchingInlineSnapshot( + `"Validation failed: Could not find provider initialization for provider aws. Please initialize the provider(s) as AwsProvider in the Stack MyStack"` + ); +}); + class MyModule extends TerraformModule { protected synthesizeAttributes() { return { diff --git a/packages/cdktf/test/terraform-hcl-module.test.ts b/packages/cdktf/test/terraform-hcl-module.test.ts index bab2fdc461..6a2ac8461e 100644 --- a/packages/cdktf/test/terraform-hcl-module.test.ts +++ b/packages/cdktf/test/terraform-hcl-module.test.ts @@ -95,6 +95,7 @@ test("complex providers", () => { test("reference module", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); const module = new TerraformHclModule(stack, "test", { source: "./foo", @@ -109,6 +110,7 @@ test("reference module", () => { test("reference module list", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); const module = new TerraformHclModule(stack, "test", { source: "./foo", @@ -153,6 +155,7 @@ test("add provider", () => { test("depend on module", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); const module = new TerraformHclModule(stack, "test", { source: "./foo", diff --git a/packages/cdktf/test/variable.test.ts b/packages/cdktf/test/variable.test.ts index 34effb7cc5..58f9c8fe5c 100644 --- a/packages/cdktf/test/variable.test.ts +++ b/packages/cdktf/test/variable.test.ts @@ -5,6 +5,7 @@ import { VariableType, } from "../lib"; import { TestResource } from "./helper"; +import { TestProvider } from "./helper/provider"; test("string type", () => { const app = Testing.app(); @@ -121,6 +122,7 @@ test("reference", () => { const app = Testing.app(); const stack = new TerraformStack(app, "test"); + new TestProvider(stack, "provider", {}); const variable = new TerraformVariable(stack, "test-variable", { type: "string", }); diff --git a/test/go/synth-app/__snapshots__/test.ts.snap b/test/go/synth-app/__snapshots__/test.ts.snap index d92498c71e..bce216813e 100644 --- a/test/go/synth-app/__snapshots__/test.ts.snap +++ b/test/go/synth-app/__snapshots__/test.ts.snap @@ -9,6 +9,19 @@ exports[`Go full integration test synth synth generates JSON 1`] = ` \\"backend\\": \\"local\\" } }, + \\"terraform\\": { + \\"required_providers\\": { + \\"random\\": { + \\"version\\": \\"~> 3.1.0\\", + \\"source\\": \\"hashicorp/random\\" + } + } + }, + \\"provider\\": { + \\"random\\": [ + {} + ] + }, \\"resource\\": { \\"random_pet\\": { \\"pet\\": { diff --git a/test/go/synth-app/main.go b/test/go/synth-app/main.go index 356e117fb2..e380d4ddf8 100644 --- a/test/go/synth-app/main.go +++ b/test/go/synth-app/main.go @@ -10,6 +10,8 @@ import ( func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack { stack := cdktf.NewTerraformStack(scope, &id) + random.NewRandomProvider(stack, jsii.String("provider"), &random.RandomProviderConfig{}) + random.NewPet(stack, jsii.String("pet"), &random.PetConfig{Prefix: jsii.String("my")}) return stack diff --git a/test/typescript/asset/cdktf.json b/test/typescript/asset/cdktf.json index 827ed077b2..71a5b1113b 100644 --- a/test/typescript/asset/cdktf.json +++ b/test/typescript/asset/cdktf.json @@ -2,7 +2,7 @@ "language": "typescript", "app": "npm run --silent compile && node main.js", "terraformProviders": [ - "null" + "null@ ~> 3.1.0" ], "context": { "excludeStackIdFromLogicalIds": "true" diff --git a/test/typescript/diff-deploy-destroy/cdktf.json b/test/typescript/diff-deploy-destroy/cdktf.json index 827ed077b2..71a5b1113b 100644 --- a/test/typescript/diff-deploy-destroy/cdktf.json +++ b/test/typescript/diff-deploy-destroy/cdktf.json @@ -2,7 +2,7 @@ "language": "typescript", "app": "npm run --silent compile && node main.js", "terraformProviders": [ - "null" + "null@ ~> 3.1.0" ], "context": { "excludeStackIdFromLogicalIds": "true" diff --git a/test/typescript/diff-deploy-destroy/main.ts b/test/typescript/diff-deploy-destroy/main.ts index 4cdfb6260c..d7d0e6ed1a 100644 --- a/test/typescript/diff-deploy-destroy/main.ts +++ b/test/typescript/diff-deploy-destroy/main.ts @@ -6,6 +6,8 @@ export class HelloTerra extends TerraformStack { constructor(scope: Construct, id: string) { super(scope, id); + new NullProvider.NullProvider(this, "null", {}); + const nullResouce = new NullProvider.Resource(this, "test", {}); nullResouce.addOverride("provisioner", [ diff --git a/test/typescript/feature-flags/cdktf.json b/test/typescript/feature-flags/cdktf.json new file mode 100644 index 0000000000..71a5b1113b --- /dev/null +++ b/test/typescript/feature-flags/cdktf.json @@ -0,0 +1,10 @@ +{ + "language": "typescript", + "app": "npm run --silent compile && node main.js", + "terraformProviders": [ + "null@ ~> 3.1.0" + ], + "context": { + "excludeStackIdFromLogicalIds": "true" + } +} \ No newline at end of file diff --git a/test/typescript/feature-flags/main.ts b/test/typescript/feature-flags/main.ts index 3074b9595f..c3ce3c45f2 100644 --- a/test/typescript/feature-flags/main.ts +++ b/test/typescript/feature-flags/main.ts @@ -6,6 +6,8 @@ export class HelloTerra extends TerraformStack { constructor(scope: Construct, id: string) { super(scope, id); + new NullProvider.NullProvider(this, "null", {}); + const nullResouce = new NullProvider.Resource(this, "test-Foo_Bar", {}); nullResouce.addOverride("provisioner", [ diff --git a/test/typescript/init-remote-template/cdktf.json b/test/typescript/init-remote-template/cdktf.json index 827ed077b2..71a5b1113b 100644 --- a/test/typescript/init-remote-template/cdktf.json +++ b/test/typescript/init-remote-template/cdktf.json @@ -2,7 +2,7 @@ "language": "typescript", "app": "npm run --silent compile && node main.js", "terraformProviders": [ - "null" + "null@ ~> 3.1.0" ], "context": { "excludeStackIdFromLogicalIds": "true" diff --git a/test/typescript/multiple-stacks/cdktf.json b/test/typescript/multiple-stacks/cdktf.json index 827ed077b2..71a5b1113b 100644 --- a/test/typescript/multiple-stacks/cdktf.json +++ b/test/typescript/multiple-stacks/cdktf.json @@ -2,7 +2,7 @@ "language": "typescript", "app": "npm run --silent compile && node main.js", "terraformProviders": [ - "null" + "null@ ~> 3.1.0" ], "context": { "excludeStackIdFromLogicalIds": "true" diff --git a/test/typescript/multiple-stacks/main.ts b/test/typescript/multiple-stacks/main.ts index 293ddb7b26..b5434604a2 100644 --- a/test/typescript/multiple-stacks/main.ts +++ b/test/typescript/multiple-stacks/main.ts @@ -5,6 +5,7 @@ import * as NullProvider from "./.gen/providers/null"; export class HelloTerra extends TerraformStack { constructor(scope: Construct, id: string) { super(scope, id); + new NullProvider.NullProvider(this, "null", {}); const nullResouce = new NullProvider.Resource(this, "test", {}); diff --git a/test/typescript/providers/main.ts b/test/typescript/providers/main.ts index d9dafb37b1..8f034599be 100644 --- a/test/typescript/providers/main.ts +++ b/test/typescript/providers/main.ts @@ -14,6 +14,7 @@ import * as External from "./.gen/providers/external"; export class HelloTerra extends TerraformStack { constructor(scope: Construct, id: string) { super(scope, id); + new NullProvider.NullProvider(this, "null", {}); const nullResouce = new NullProvider.Resource(this, "test", {}); diff --git a/test/typescript/terraform-cloud/cdktf.json b/test/typescript/terraform-cloud/cdktf.json index 827ed077b2..71a5b1113b 100644 --- a/test/typescript/terraform-cloud/cdktf.json +++ b/test/typescript/terraform-cloud/cdktf.json @@ -2,7 +2,7 @@ "language": "typescript", "app": "npm run --silent compile && node main.js", "terraformProviders": [ - "null" + "null@ ~> 3.1.0" ], "context": { "excludeStackIdFromLogicalIds": "true" diff --git a/test/typescript/terraform-cloud/main.ts b/test/typescript/terraform-cloud/main.ts index 49362ad7f6..acfc632e60 100644 --- a/test/typescript/terraform-cloud/main.ts +++ b/test/typescript/terraform-cloud/main.ts @@ -16,6 +16,7 @@ const localExecution = process.env.TF_EXECUTE_LOCAL === "true"; export class HelloTerra extends TerraformStack { constructor(scope: Construct, id: string) { super(scope, id); + new NullProvider.NullProvider(this, "null", {}); const nullResouce = new NullProvider.Resource(this, "test", {}); diff --git a/test/typescript/watch/cdktf.json b/test/typescript/watch/cdktf.json index 827ed077b2..71a5b1113b 100644 --- a/test/typescript/watch/cdktf.json +++ b/test/typescript/watch/cdktf.json @@ -2,7 +2,7 @@ "language": "typescript", "app": "npm run --silent compile && node main.js", "terraformProviders": [ - "null" + "null@ ~> 3.1.0" ], "context": { "excludeStackIdFromLogicalIds": "true" diff --git a/test/typescript/watch/main.ts b/test/typescript/watch/main.ts index 4cdfb6260c..22096a497f 100644 --- a/test/typescript/watch/main.ts +++ b/test/typescript/watch/main.ts @@ -5,6 +5,7 @@ import * as NullProvider from "./.gen/providers/null"; export class HelloTerra extends TerraformStack { constructor(scope: Construct, id: string) { super(scope, id); + new NullProvider.NullProvider(this, "null", {}); const nullResouce = new NullProvider.Resource(this, "test", {}); diff --git a/yarn.lock b/yarn.lock index 0020920629..cc085e5638 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1758,6 +1758,13 @@ "@types/connect" "*" "@types/node" "*" +"@types/camelcase@^5.2.0": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@types/camelcase/-/camelcase-5.2.0.tgz#5c139f8618a126827129587cce9ee904f9a79863" + integrity sha512-zhHaryYYUUsJ1h6Rq4hisPkljY7c2bkC5PFYQbom5fyKloGJEDK+wdsw2L4hnBwXr4plGjW6D/UVJBbNbOzVpQ== + dependencies: + camelcase "*" + "@types/cli-spinners@*": version "1.3.0" resolved "https://registry.yarnpkg.com/@types/cli-spinners/-/cli-spinners-1.3.0.tgz#631f5eec89e519447d326b12b2051ce40c88c0ea" @@ -3068,6 +3075,11 @@ camelcase-keys@^6.2.2: map-obj "^4.0.0" quick-lru "^4.0.1" +camelcase@*, camelcase@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809" + integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== + camelcase@^5.0.0, camelcase@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" @@ -3078,11 +3090,6 @@ camelcase@^6.0.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.0.0.tgz#5259f7c30e35e278f1bdc2a4d91230b37cad981e" integrity sha512-8KMDF1Vz2gzOq54ONPJS65IvTUaB1cHJ2DMM7MbPmLZljDH1qpzzLsWdiN9pHh6qvkRVDTi/07+eNGch/oLU4w== -camelcase@^6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809" - integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg== - capture-exit@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"