Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TerraformHclModule outputs need to use tokens #512

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/cdktf/lib/terraform-hcl-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Construct } from "constructs";
import { TerraformModuleOptions, TerraformModule } from "./terraform-module";
import { Token } from "./tokens";

export interface TerraformHclModuleOptions extends TerraformModuleOptions {
readonly variables?: {[key: string]: any};
Expand All @@ -26,23 +27,23 @@ export class TerraformHclModule extends TerraformModule {
}

public get(output: string): any {
return this.interpolationForOutput(output);
return Token.asAny(this.interpolationForOutput(output));
}

public getString(output: string): string {
return this.get(output);
return Token.asString(this.interpolationForOutput(output));
}

public getNumber(output: string): number {
return this.get(output);
return Token.asNumber(this.interpolationForOutput(output));
}

public getBoolean(output: string): boolean {
return this.get(output);
return Token.asString(this.interpolationForOutput(output)) as any as boolean;
}

public getList(output: string): string[] {
return this.get(output);
return Token.asList(this.interpolationForOutput(output));
}

protected synthesizeAttributes(): { [name: string]: any } {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,42 @@ exports[`reference module 1`] = `
}"
`;

exports[`reference module list 1`] = `
"{
\\"//\\": {
\\"metadata\\": {
\\"version\\": \\"stubbed\\",
\\"stackName\\": \\"test\\"
}
},
\\"module\\": {
\\"test\\": {
\\"source\\": \\"./foo\\",
\\"//\\": {
\\"metadata\\": {
\\"path\\": \\"test/test\\",
\\"uniqueId\\": \\"test\\"
}
}
}
},
\\"resource\\": {
\\"test_resource\\": {
\\"resource\\": {
\\"name\\": \\"test\\",
\\"names\\": \\"\${module.test.names}\\",
\\"//\\": {
\\"metadata\\": {
\\"path\\": \\"test/resource\\",
\\"uniqueId\\": \\"resource\\"
}
}
}
}
}
}"
`;

exports[`set variable 1`] = `
"{
\\"//\\": {
Expand Down
16 changes: 16 additions & 0 deletions packages/cdktf/test/terraform-hcl-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ test('reference module', () => {
expect(Testing.synth(stack)).toMatchSnapshot();
});

test('reference module list', () => {
const app = Testing.app();
const stack = new TerraformStack(app, 'test');

const module = new TerraformHclModule(stack, 'test', {
source: './foo'
});

const resource = new TestResource(stack, 'resource', {
name: 'test'
});
resource.names = module.getList('names');

expect(Testing.synth(stack)).toMatchSnapshot();
});

test('set variable', () => {
const app = Testing.app();
const stack = new TerraformStack(app, 'test');
Expand Down