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.
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
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
- 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