Created
August 7, 2020 09:04
-
-
Save Tirke/d45fb6dd105af2d63e74d2d5e55c2cb6 to your computer and use it in GitHub Desktop.
Multiple stacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Construct} from 'constructs'; | |
import {App, TerraformOutput, TerraformStack} from 'cdktf'; | |
import {AwsProvider, LambdaFunction, IamRole} from "./.gen/providers/aws"; | |
import {SecondStack} from "./second-stack"; | |
class MainStack extends TerraformStack { | |
constructor(scope: Construct, id: string) { | |
super(scope, id); | |
new AwsProvider(this, "aws", { | |
region: "eu-west-1", | |
}); | |
const lambdaRole = new IamRole(this, "cdk-tf-lambda-role", { | |
name: "cdk-tf-lambda-role", | |
assumeRolePolicy: JSON.stringify({ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "lambda.amazonaws.com" | |
}, | |
"Effect": "Allow", | |
} | |
] | |
}) | |
}) | |
const lambda = new LambdaFunction(this, "cdk-tf-lambda", { | |
filename: '../lambda/lambda.zip', | |
functionName: 'cdk-tf', | |
handler: 'index.handler', | |
role: lambdaRole.arn, | |
runtime: 'nodejs12.x' | |
}); | |
new TerraformOutput(this, 'cdk-tf-lambda-arn', { | |
value: lambda.arn | |
}); | |
} | |
} | |
const app = new App(); | |
new MainStack(app, 'dec-imp-main-stack'); | |
new SecondStack(app, 'dec-imp-sec-stack'); // another stack declared in another file is imported here | |
app.synth(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment