• Overview
    • Enforce Policy as Code
    • Infrastructure as Code
    • Inject Secrets into Terraform
    • Integrate with Existing Workflows
    • Manage Kubernetes
    • Manage Virtual Machine Images
    • Multi-Cloud Deployment
    • Network Infrastructure Automation
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
  • Registry
  • Tutorials
    • About the Docs
    • Intro to Terraform
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
    • Terraform Tools
    • CDK for Terraform
    • Glossary
  • Community
GitHubTerraform Cloud
Download

    CDK for Terraform

  • Overview
  • Get Started
    • Architecture
    • HCL Interoperability
    • Constructs
    • Providers and Resources
    • Modules
    • Data Sources
    • Variables and Outputs
    • Functions
    • Remote Backends
    • Aspects
    • Assets
    • Tokens
    • Stacks
  • Examples and Guides
    • Project Setup
    • Configuration File
    • Best Practices
    • Environment Variables
    • Remote Templates
    • AWS Adapter [preview]
    • Unit Tests
    • Debugging
    • CLI Configuration
    • Commands
    • Overview
    • Upgrading to Version 0.6
    • Upgrading to Version 0.7
    • Upgrading to Version 0.9
    • Upgrading to Version 0.10
    • Upgrading to Version 0.11
  • Community
  • Telemetry
  • Other Docs

  • Intro to Terraform
  • Configuration Language
  • Terraform CLI
  • Terraform Cloud
  • Terraform Enterprise
  • Provider Use
  • Plugin Development
  • Registry Publishing
  • Integration Program
  • Terraform Tools
  • CDK for Terraform
  • Glossary
Type '/' to Search

»Examples

This page contains links to tutorials, example projects in every supported language, explanatory videos, and other resources to help you learn to create and manage CDK for Terraform (CDKTF) applications.

»Tutorials

Follow these hands-on tutorials from HashiCorp Learn:

TutorialDescription
Install CDKTF and Run a Quick Start DemoWrite TypeScript code that will provision an NGINX server using Docker on Mac, Windows, or Linux.
Build AWS Infrastructure with TypeScript, Python, Java, C#, or GoProvision an EC2 instance on AWS using TypeScript.
Deploy Multiple Lambda Functions with TypeScriptDeploy a CDKTF application made up of two stacks, each containing a simple AWS Lambda function written in TypeScript.
Deploy Applications with CDK for TerraformUse CDKTF to deploy an application on Kubernetes.

»Example Projects

Note: You can find more information about all of the providers in the examples below on the Terraform Registry.

»Typescript

ExampleDescription
aws-ecs-docker-and-static-frontendUses a backend service in a Docker container with a static frontend running in Amazon Web Services (AWS). Walk through AWS setup and configuring the backend to run against a Postgres Database.
aws-lambda-end-to-endAn end-to-end example for a serverless web application hosted on AWS.
aws-prebuiltProvisions a DynamoDB table on the prebuilt AWS provider.
aws-multiple-stacksUses Stacks to pass different settings into the development, staging, and production environments.
aws-cloudfront-proxyUses AWS Cloudfront as a SSL proxy server for any existing domain.
azureProvisions a Virtual Network on Microsoft Azure.
azure-app-serviceUses the Azure App Service to deploy a Docker image.
dockerStarts a Docker container with an NGINX server.
googleCreates a simple Compute Instance with the Google Cloud Platform Provider.
google-cloudrunDefines a Google Cloud Run service with a hello world container.
kubernetesSets up a Kubernetes Deployment with a NGINX container.
ucloudProvisions a Linux base image on UCloud.
vaultCreates a Mount in Vault.

»Backends

Each CDK for Terraform project can specify a backend that defines where and how Terraform operations are performed, where Terraform state snapshots are stored, etc.

ExampleDescription
azurermSpecifies Azure Resource Manager (azurerm) as the backend.
gcsSpecifies Google Cloud Storage (gcs) as the backend.
remoteSpecifies a remote backend. You can use remote backends to run operations in Terraform Cloud.
s3Specifies Amazon S3 (s3) as the backend.

»Python

ExampleDescription
awsProvisions an AWS Virtual Private Cloud (VPC).
aws-eksProvisions an EKS cluster on an AWS Virtual Private Cloud.
azureProvisions a Virtual Network on Microsoft Azure.
dockerStarts a Docker container with an NGINX server.
kubernetesSchedules and exposes a NGINX deployment on a Kubernetes cluster.
ucloudProvisions a Linux base image on UCloud.

»Java

ExampleDescription
awsProvisions a DynamoDB table on the AWS provider.
azureProvisions a Virtual Network on Microsoft Azure.
googleCreates a simple Compute Instance with the Google Cloud Platform Provider.
gradle-shared-moduleUses gradle to build and share two AWS modules. Modules are distinct configurations that you can package and reuse across projects and teams.
kubernetesSchedules and exposes a NGINX deployment on a Kubernetes cluster.
ucloudProvisions a Linux base image on UCloud.

»C Sharp

ExampleDescription
awsProvisions a DynamoDB table on the AWS provider.
azureProvisions a Virtual Network on Microsoft Azure.
googleCreates a simple Compute Instance with the Google Cloud Platform Provider.
ucloudProvisions a Linux base image on UCloud.

»Go

Note: Golang support is experimental for both CDKTF and the upstream library JSII.

ExampleDescription
dockerStarts a Docker container with an NGINX server.
awsProvisions an EKS cluster on an AWS Virtual Private Cloud. High memory usage: The provider generation currently needs ~6 GB of memory, so the maximum for Node.js is currently set to 8GB.
google cloud kubernetes engine + kubernetesCreates a simple Compute Instance with the Google Cloud Platform Provider.
ucloudProvisions a Linux base image on UCloud.

»Youtube Playlist

  • The CDKTF engineering team builds a simple end to end serverless application in an end to end livestream
  • Getting Started with CDK for Terraform and Python, by Charles McLaughlin of ShopStyle
  • Extending constructs of the CDK for Terraform

»Release demos

  • 0.4: Go support, Asset construct, Terraform Cloud integration. This includes a Google Kubernetes Engine demo.

  • 0.5: Convert and watch command demos

    If you are interested in extending the cdktf convert command, you may also be interested in the convert deep dive. You do not need to watch this video to use the convert command successfully.

  • 0.6: Snapshot testing

»Pocket public codebase

Mozilla Pocket is a widely used application for managing reading lists that is built into the Firefox browser. Like many Mozilla projects, Pocket is open source, and the CDK for Terraform codebase that Pocket uses to manage infrastructure for the recommendation API is also public and open source. Pocket's codebase provides a great example of how to lay out a CDK for Terraform project.

In order to re-use components, Pocket's codebase is separated out into a set of reusable modules. These are then used from CDK for Terraform code in the recommendation-api codebase. The recommended reading order is to:

  1. Read Pocket/recommendation-api/.aws/src/main.ts.
  2. Look at the constructs used that are defined in the Pocket/terraform-modules repository, such as PocketALBApplication.
  3. Look at the "base" constructs, which are are used in the higher-level constructs in the previous step.
github logoEdit this page
  • Overview
  • Docs
  • Extend
  • Privacy
  • Security
  • Press Kit
  • Consent Manager