> ## Documentation Index
> Fetch the complete documentation index at: https://cdktn.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples and Guides - CDK Terrain

> Resources to help you learn CDK Terrain, including example projects in Typescript, Java, Python, C#, and Go.

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 Terrain (CDKTN) applications.

## Tutorials

Follow these hands-on tutorials:

| Tutorial                                                                                  | Description                                                                                                           |
| ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [Install CDKTN and Run a Quick Start Demo](/tutorials/install)                            | Write TypeScript code that will provision an NGINX server using Docker on Mac, Windows, or Linux.                     |
| [Build AWS Infrastructure with TypeScript, Python, Java, C#, or Go](/tutorials/build-aws) | Provision an EC2 instance on AWS using TypeScript.                                                                    |
| [Deploy Multiple Lambda Functions with TypeScript](/tutorials/lambda-functions)           | Deploy a CDKTN application made up of two stacks, each containing a simple AWS Lambda function written in TypeScript. |
| [Deploy Applications with CDK Terrain](/tutorials/deploy-applications)                    | Use CDKTN to deploy an application on Kubernetes.                                                                     |

## Example Projects

<Note>The [Terraform Registry](https://registry.terraform.io/) and [OpenTofu Registry](https://search.opentofu.org/) have more information about all of the providers in the following examples.</Note>

### Typescript

| Example                                                                                                                   | Description                                                                                                                                                                                      | Complexity |
| ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
| [aws-ecs-docker-and-static-frontend](https://github.com/hashicorp/docker-on-aws-ecs-with-terraform-cdk-using-typescript)  | Uses 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. | High       |
| [aws-lambda-end-to-end](https://github.com/hashicorp/cdktn-integration-serverless-example)                                | An end-to-end example for a serverless web application hosted on AWS.                                                                                                                            | High       |
| [aws-prebuilt](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/aws-prebuilt)                 | Provisions a DynamoDB table on the prebuilt AWS provider.                                                                                                                                        | Low        |
| [aws-multiple-stacks](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/aws-multiple-stacks)   | Uses Stacks to pass different settings into the development, staging, and production environments.                                                                                               | Low        |
| [aws-cloudfront-proxy](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/aws-cloudfront-proxy) | Uses AWS Cloudfront as a SSL proxy server for any existing domain.                                                                                                                               | Low        |
| [azure](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/azure)                               | Provisions a Virtual Network on Microsoft Azure.                                                                                                                                                 | Low        |
| [azure-app-service](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/azure-app-service)       | Uses the Azure App Service to deploy a Docker image.                                                                                                                                             | Low        |
| [docker](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/docker)                             | Starts a Docker container with an NGINX server.                                                                                                                                                  | Low        |
| [ecs-microservices-cdktn](https://github.com/jcolemorrison/ecs-microservices-cdktn)                                       | Creates a microservice architecture on AWS ECS Fargate with Datadog monitoring using the CDK Terrain                                                                                             | High       |
| [google](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/google)                             | Creates a simple Compute Instance with the Google Cloud Platform Provider.                                                                                                                       | Low        |
| [google-cloudrun](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/google-cloudrun)           | Defines a Google Cloud Run service with a hello world container.                                                                                                                                 | Low        |
| [kubernetes](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/kubernetes)                     | Sets up a Kubernetes Deployment with a NGINX container.                                                                                                                                          | Low        |
| [ucloud](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/ucloud)                             | Provisions a Linux base image on UCloud.                                                                                                                                                         | Low        |
| [vault](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/vault)                               | Creates a Mount in Vault.                                                                                                                                                                        | Low        |

#### Backends

Each CDK Terrain project can specify a [backend](https://developer.hashicorp.com/terraform/language/backend) that defines where and how Terraform operations are performed, where Terraform [state snapshots](https://developer.hashicorp.com/terraform/language/state) are stored, etc.

| Example                                                                                                  | Description                                                                                                                                                                | Complexity |
| -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| [azurerm](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/backends/azurerm) | Specifies Azure Resource Manager ([azurerm](https://developer.hashicorp.com/terraform/language/settings/backends/azurerm)) as the backend.                                 | Low        |
| [gcs](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/backends/gcs)         | Specifies Google Cloud Storage ([gcs](https://developer.hashicorp.com/terraform/language/settings/backends/gcs)) as the backend.                                           | Low        |
| [remote](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/backends/remote)   | Specifies a [remote](https://developer.hashicorp.com/terraform/language/settings/backends/remote) backend. You can use remote backends to run operations in HCP Terraform. | Low        |
| [s3](https://github.com/open-constructs/cdk-terrain/tree/main/examples/typescript/backends/s3)           | Specifies Amazon S3 ([s3](https://developer.hashicorp.com/terraform/language/settings/backends/s3)) as the backend.                                                        | Low        |

### Python

| Example                                                                                           | Description                                                                                 | Complexity |
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------- |
| [aws-lambda-end-to-end](https://github.com/hashicorp/cdktn-integration-serverless-python-example) | An end-to-end example for a serverless web application hosted on AWS.                       | High       |
| [aws](https://github.com/open-constructs/cdk-terrain/tree/main/examples/python/aws)               | Provisions an AWS Virtual Private Cloud (VPC).                                              | Low        |
| [aws-eks](https://github.com/open-constructs/cdk-terrain/tree/main/examples/python/aws-eks)       | Provisions an EKS cluster on an AWS Virtual Private Cloud.                                  | Low        |
| [google-end-to-end](https://github.com/hashicorp/cdktn-integration-serverless-python-gcp-example) | An end-to-end example for a serverless web application hosted on the Google Cloud Provider. | High       |
| [azure](https://github.com/open-constructs/cdk-terrain/tree/main/examples/python/azure)           | Provisions a Virtual Network on Microsoft Azure.                                            | Low        |
| [docker](https://github.com/open-constructs/cdk-terrain/tree/main/examples/python/docker)         | Starts a Docker container with an NGINX server.                                             | Low        |
| [kubernetes](https://github.com/open-constructs/cdk-terrain/tree/main/examples/python/kubernetes) | Schedules and exposes a NGINX deployment on a Kubernetes cluster.                           | Low        |
| [ucloud](https://github.com/open-constructs/cdk-terrain/tree/main/examples/python/ucloud)         | Provisions a Linux base image on UCloud.                                                    | Low        |

### Java

#### Gradle

| Example                                                                                                             | Description                                                                                                                                                        | Complexity |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
| [aws-gradle](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/aws-gradle)                     | Provisions a DynamoDB table on the AWS provider.                                                                                                                   | Low        |
| [azure-gradle](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/azure-gradle)                 | Provisions a Virtual Network on Microsoft Azure.                                                                                                                   | Low        |
| [google-gradle](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/google-gradle)               | Creates a simple Compute Instance with the Google Cloud Platform Provider.                                                                                         | Low        |
| [gradle-shared-module](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/gradle-shared-module) | Uses gradle to build and share two AWS modules. [Modules](/concepts/modules) are distinct configurations that you can package and reuse across projects and teams. | Low        |
| [kubernetes-gradle](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/kubernetes-gradle)       | Schedules and exposes a NGINX deployment on a Kubernetes cluster.                                                                                                  | Low        |
| [ucloud-gradle](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/ucloud-gradle)               | Provisions a Linux base image on UCloud.                                                                                                                           | Low        |

#### Maven

| Example                                                                                         | Description                                                                                 | Complexity |
| ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------- |
| [aws-lambda-end-to-end](https://github.com/hashicorp/cdktn-integration-serverless-java-example) | An end-to-end example for a serverless web application hosted on AWS.                       | High       |
| [aws](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/aws)               | Provisions a DynamoDB table on the AWS provider.                                            | Low        |
| [azure](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/azure)           | Provisions a Virtual Network on Microsoft Azure.                                            | Low        |
| [google-end-to-end](https://github.com/hashicorp/cdktn-integration-serverless-java-gcp-example) | An end-to-end example for a serverless web application hosted on the Google Cloud Provider. | High       |
| [google](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/google)         | Creates a simple Compute Instance with the Google Cloud Platform Provider.                  | Low        |
| [kubernetes](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/kubernetes) | Schedules and exposes a NGINX deployment on a Kubernetes cluster.                           | Low        |
| [ucloud](https://github.com/open-constructs/cdk-terrain/tree/main/examples/java/ucloud)         | Provisions a Linux base image on UCloud.                                                    | Low        |

### C Sharp

| Example                                                                                   | Description                                                                | Complexity |
| ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------- |
| [aws](https://github.com/open-constructs/cdk-terrain/tree/main/examples/csharp/aws)       | Provisions a DynamoDB table on the AWS provider.                           | Low        |
| [azure](https://github.com/open-constructs/cdk-terrain/tree/main/examples/csharp/azure)   | Provisions a Virtual Network on Microsoft Azure.                           | Low        |
| [google](https://github.com/open-constructs/cdk-terrain/tree/main/examples/csharp/google) | Creates a simple Compute Instance with the Google Cloud Platform Provider. | Low        |
| [ucloud](https://github.com/open-constructs/cdk-terrain/tree/main/examples/csharp/ucloud) | Provisions a Linux base image on UCloud.                                   | Low        |

### Go

| Example                                                                                                                    | Description                                                                                                                                                                                                                                                                                                                                         | Complexity |
| -------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| [docker](https://github.com/open-constructs/cdk-terrain/tree/main/examples/go/docker)                                      | Starts a Docker container with an NGINX server.                                                                                                                                                                                                                                                                                                     | Low        |
| [aws](https://github.com/open-constructs/cdk-terrain/tree/main/examples/go/aws)                                            | Provisions 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](https://github.com/open-constructs/cdk-terrain/blob/11d2e783d1fe94e50abd116ba73689c02590a391/packages/cdktn-cli/lib/get/constructs-maker.ts#L279). | Low        |
| [google cloud kubernetes engine + kubernetes](https://github.com/open-constructs/cdk-terrain/tree/main/examples/go/google) | Creates a simple Compute Instance with the Google Cloud Platform Provider.                                                                                                                                                                                                                                                                          | Low        |
| [ucloud](https://github.com/open-constructs/cdk-terrain/tree/main/examples/go/ucloud)                                      | Provisions a Linux base image on UCloud.                                                                                                                                                                                                                                                                                                            | Low        |

## Youtube Playlist

* [Our official playlist](https://www.youtube.com/watch?v=nNr8JrN-9HE\&list=PL81sUbsFNc5ZWUfivG9-KAtLhMbJ4aUmV) contains a set of videos from community office hours to deep dives into technical topics
* [CDK Day 2022 - Hybrid Constructs](https://www.youtube.com/watch?v=s8tO-ymVQPg\&t=10260s): How to build CDKTN abstractions that cooperate with your HCL
* The CDKTN engineering team builds a simple end to end serverless application in an [end to end livestream](https://www.youtube.com/watch?v=Ey0SW0c6p8c)
* [Getting Started with CDK Terrain and Python](https://www.youtube.com/watch?v=Ee2qh-pEC5k\&t=258s), by Charles McLaughlin of ShopStyle
* [Extending constructs of the CDK Terrain](https://www.youtube.com/watch?v=cfU-WOGdNqA)

### Release demos

* **0.4:** [Go support, Asset construct, Terraform Cloud (now HCP Terraform) integration](https://www.youtube.com/watch?v=TTfFAIeSqgo). This includes a [Google Kubernetes Engine demo](https://youtu.be/TTfFAIeSqgo?t=1573).

* **0.5:** [Convert and watch command demos](https://www.youtube.com/watch?v=4caW8WJM4h4\&t=1s)

  If you are interested in extending the `cdktn convert` command, you may also be interested in the [convert deep dive](https://www.youtube.com/watch?v=rSn4-Ki5nho). You do not need to watch this video to use the `convert` command successfully.

* **0.6:** [Snapshot testing](https://www.youtube.com/watch?v=9Is4QJT2664)

## 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 Terrain 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 Terrain project.

In order to re-use components, Pocket's codebase is separated out into a [set of reusable modules](https://github.com/Pocket/terraform-modules/tree/main/src/pocket). These are then used from CDK Terrain code in the [recommendation-api codebase](https://github.com/Pocket/recommendation-api/tree/main/.aws). The recommended reading order is to:

1. Read [`Pocket/recommendation-api/.aws/src/main.ts`](https://github.com/Pocket/recommendation-api/blob/main/.aws/src/main.ts).
2. Look at the constructs used that are defined in the [`Pocket/terraform-modules`](https://github.com/Pocket/terraform-modules/tree/main/src/pocket) repository, such as [`PocketALBApplication`](https://github.com/Pocket/terraform-modules/blob/main/src/pocket/PocketALBApplication.ts).
3. Look at the ["base" constructs](https://github.com/Pocket/terraform-modules/tree/main/src/base), which are are used in the higher-level constructs in the previous step.
