DevOps at the core is a culture that relies on shared responsibility and continuous collaboration between development and operations of a product or service. In many organizations, a single multi-disciplinary team takes the complete accountability to build and run. This socio, technological and organizational culture shift can be further empowered and accelerated by leveraging technology stacks, programming languages and frameworks that are familiar to the entire team.
CDKTF (Cloud Development Kit for Terraform) is an Infrastructure as Code (IaC) framework that allows team to use programming languages like TypeScript, Python, C#, Java etc. that are more familiar to developers to define and manage infrastructure.
In this hands-on workshop, learn how to define and manage infrastructure using TypeScript, one of the most popular languages to build full stack applications.
In order to use CDKTF, you need:
- The Terraform CLI (1.1+).
- Node.js and npm v16+.
npm install --global cdktf-cli@latest
For more information and other installations options, you may checkout the CDKTF CLI documentation.
You will need to have an AWS account and have your AWS credentials configured locally. You can find instructions on how to do this in the AWS documentation.
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
export AWS_DEFAULT_REGION=us-east-1
CDKTF uses Terraform as the underlying engine to provision infrastructure. Terraform stores the state of the infrastructure in a state file. In this workshop, we will use an S3 bucket to store the state of the infrastructure.
# Create a new S3 bucket
aws s3api create-bucket \
--bucket cdktf-workshop-tfstate \
--region us-east-1
You may also use a local state file or Terraform Cloud to store the state information.
In this workshop, we will build a simple JAM Stack application, a sample ReactJS application built as a static website that uses a serverless backend with a sample Lambda function and API Gateway.
Optionally, we can setup custom domain name for the application using Route53 and ACM.
# Install dependencies and Build UI for deployment
cd app && npm install && npm run build && cd ..
# Install dependencies for the lambda function
cd functions/mainfunc && npm install && cd ../..
# Install dependencies for the CDKTF project/providers
cd isc && npm install
# Sample code is setup with 3 environments: dev, test and demo
# Deploy the infrastructure for the demo environment
cdktf deploy demo
demo
workshop-api
Backend URL = https://XXX.execute-api.us-east-1.amazonaws.com/demo/public/welcome
ui-deployment-demo
website_endpoint = https://XXX.cloudfront.net
# Destroy the infrastructure for the demo environment
cdktf destroy demo
To create a new environment, create a new instance of the CDKTFWorkShop class with appropriate name and details.
new CDKTFWorkShop(app, "demo", {
name: "cdktfworkshop-demo",
environment: "demo", // Our Environment name, this tells us which stage to deploy and name
region: "us-east-1",
uiDeployment: true, // Let's us check in code if we need to deploy the UI or not
uiBucketName: "workshop-demo.softrams.cloud", // If we are deploying the UI we need a bucketname for it.
lambdaBucketName: "workshop-demo-lambda", // Setups our lambda bucket to store our zips
setupDomain: false, // Again checks if a domain needs to be setup or not
domainZoneId: "", // Setups up domain in correct zone should be pulled from domain zone in AWS
ACMCertificateArn: "", // Sets up ACM certificate for our domain
});
If you have suggestions for how this workshop could be improved, or want to report a bug, open an issue! We'd love all and any contributions.