Skip to content

Instantly share code, notes, and snippets.

@Tirke
Created August 5, 2020 13:20
Show Gist options
  • Save Tirke/74c089a8b0c275853a47d706446fd9b7 to your computer and use it in GitHub Desktop.
Save Tirke/74c089a8b0c275853a47d706446fd9b7 to your computer and use it in GitHub Desktop.
simple-cdk-tf
import {Construct} from 'constructs';
import {App, TerraformOutput, TerraformStack} from 'cdktf';
import {AwsProvider, LambdaFunction, IamRole} from "./.gen/providers/aws";
class MyStack 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 MyStack(app, 'dec-imp');
app.synth();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment