What Is Terraform CDK? - Terraform code in JavaScript
Raghav Mrituanjaya
Posted on October 28, 2021
What is Terraform🤔?
Terraform is an open-source infrastructure as a code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. It was developed by HashiCorp
What is Terraform CDK?
Terraform CDK is a tool developed by terraform developers which allows you to write your infrastructure in your favorite language
- It supports TypeScript, Python, C#, Go(Beta), and Java Currently.
Getting started 😃
Before we get started install cdktf-cli by running npm i -g cdktf-cli@latest
and then run cdktf init
to initialize a broiler code for you. Choose the language and name as your choice. For this instance, I will be using typescript.
Let's add AWS providers and try to make an EC2 Instance. There are some prebuilt providers like the following for typescript. So in this case we install the AWS provider by running npm i @cdktf/provider-aws
If in case you are using any other language then you can add your providers to the terraformProviders field in the cdktf.json file and run cdktf get
to install the constructs and convert them to your native language
Here's my Typescript Code
Running cdktf synth
will create a directory called cdktf.out where you will have your stack named folder which contains the terraform files.
Now you can run terraform init
& terraform plan
to initialize terraform and review your infrastructure resources and if you want to go ahead and apply the changes run terraform apply
Notes
- You must have to terraform installed in order for cdktf to work. You can Download the latest version by visiting this link
- If you guys want me write the same for other language do let me know in the comment section below.
Video Reference
Posted on October 28, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.