TerraConstructs Overview
By Vincent De Smet••1 min read
Introduction
TerraConstructs provides high-level L2 Constructs for AWS infrastructure, built on top of CDK for Terraform (CDKTF). This guide will walk you through creating your first project.
Prerequisites
Before you begin, make sure you have:
- Node.js 20 or later installed
- AWS CLI configured with credentials
- Terraform CLI
- Basic familiarity with TypeScript
Installation
Init your NodeJS project:
npm initInstall the required dependencies:
npm install cdktf constructs terraconstructs @cdktf/provider-awsYour First Stack
Create a simple S3 bucket with TerraConstructs:
import { App } from "cdktf";import { AwsStack } from "terraconstructs/lib/aws";import { Bucket } from "terraconstructs/lib/aws/storage";
const app = new App();const stack = new AwsStack(app, "my-stack",{ providerConfig: { region: "ap-southeast-1", },});
new Bucket(stack, "bucket", { bucketName: "my-demo-bucket",});
app.synth();Generating Terraform Configuration
npx -y tsx index.tsThis will generate your Terraform configuration at cdktf.out/stacks/my-stack.
Next Steps
Now that you have a basic stack, you can:
- Explore more AWS constructs in the TerraConstructs Reference Docs
- Add additional resources to your stack
- Deploy your infrastructure with
opentofuorterraformdirectly from the output directory (or using the CDKTF CLI wrappers) - Go through the full AWS CDK Workshop
Conclusion
You've successfully created your first TerraConstructs - Typescript project. Check out our other tutorials for more advanced patterns and best practices.