This guide was recovered from the Wayback Machine snapshot of “Build AWS infrastructure with CDK for Terraform”.
Prerequisites
- Terraform CLI v1.2+ (or OpenTofu)
- CDKTN CLI v0.15+
- HCP Terraform account with CLI authentication configured
- AWS account
- AWS credentials configured for Terraform (environment variables or another supported credential method)
- A recent version of your preferred language runtime (TypeScript, Python, Go, C#, or Java)
Initialize a new CDK Terrain application
Create a new project directory and move into it.Shell
learn-cdktn).
Define your CDK Terrain application
Replace the generated application code with the following for your language. The stack configures the AWS provider, creates an EC2 instance inus-west-1, and defines a public_ip output.
Replace <YOUR_ORG> with your HCP Terraform organization name. If you used a different workspace name, replace learn-cdktn with that name.
Provision infrastructure
Deploy the stack. CDKTN synthesizes Terraform configuration, runs a plan, and prompts you to approve the changes.Shell

Change infrastructure by adding the Name tag
Update the EC2 instance resource to add aName tag, then deploy again.
Shell
Clean up your infrastructure
Destroy the stack to remove the EC2 instance.Shell
Next steps
- Learn how to package and deploy Lambda functions.
- Follow the end-to-end Deploy applications tutorial.
- Review how CDKTN works with Terraform providers and stacks.