Technology / Security

Should I Use CDK for Terraform?

Should I Use CDK for Terraform?
Follow us
Published on September 4, 2023

Terraform is a fantastic management application for cloud assets, making it simple to manage, deploy, and tear down cloud resources. Like other management apps, it’s designed to be used with a custom single-use programming language called HashiCorp Configuration Language (HCL).

HCL is used to write scaffolding for cloud resources. It also includes keyword blocks for defining important details, such as the vendor a cloud asset should be deployed in, API keys, and configuration blocks. HCL is similar to languages like YAML. However, techs with an application development background might notice it looks like JavaScript and JSON because writing blocks in HCL is similar to writing a JS object.

But what if you don’t want to learn another language built specifically for one tool?

Cloud Development Kit (CDK) for Terraform may be just what you are looking for. Throughout this article, we’ll share the pros and cons of CDK for Terraform so you can decide if it’s right for your next project.

If you are interested in deep diving into Terraform, check out Trevor Sullivan’s HashiCorp Certified: Terraform Associate online training course.

What is CDK for Terraform?

CDK for Terraform enables you to use familiar programming languages to define and provision infrastructure. It’s designed to help engineers leverage Terraform without needing to learn HCL. It is an excellent option for engineers with an application development background. Instead of using HCL, the CDK for Terraform uses common programming languages to create deployment records. 

CDK for Terraform Versus HCL: Which Should You Choose?

As mentioned above, programmers will prefer the CDK instead of HCL. The CDK supports common programming languages, so the onboarding process for Terraform newbies with programming experience is much faster with the CDK. 

That said, system administrators or network engineers familiar with YAML may be more comfortable with HCL. The HCL design and workflow aren’t vastly different from other DevOps management apps, such as Ansible or Chef. However, it’s easier to create reusable templates for cloud deployments in Terraform with the CDK. This boils down to the differences in the capabilities and design patterns of different programming languages. 

HCL is written to operate as a configuration language. Its sole responsibility is to define key/value pairs. Languages like TypeScript and Java support object-oriented models, however. The CDK can accept classes built in these languages, which can be extended or mutated as needed. For this reason, re-usable infrastructure is easier to define with the CDK for Terraform. 

Also, consider whether your Terraform deployments depend on procedural instructions for architecture definitions. Some edge cases may require defining infrastructure in specific, predictable steps. The Terraform CDK is a better option in these edge cases than using workarounds in HCL. 

Which Programming Languages Does the CDK for Terraform Support?

The Terraform CDK supports the following programming languages:

Keep in Mind That Terraform CDK is Beta

You may not want to use the Terraform CDK if you are uncomfortable with using bleeding-edge tools. Note that the Terraform CDK is still in beta at the time of this writing. Some features and options may change or break after the Terraform CDK reaches version 1. 

Learn the Ins and Outs of HashiCorp Certified Terraform 

The CDK for Terraform is an excellent option for engineers with an application development background, but it still has a pretty steep learning curve. You’ll need to master many functions and learn quite a few libraries. 

If you are new to Terraform, we recommend you take our Hashicorp Certified: Terraform Associate course. This course walks new Terraform engineers through the process of building and maintaining infrastructure as code with Terraform. You’ll discover how to: 

  • Navigate Terraform's basic commands and related tools

  • Construct and consume Terraform modules

  • Write and review Terraform configs that create infrastructure

  • Modify cloud resource configurations with Terraform

  • Deploy to Google Cloud, Microsoft Azure, and Amazon Web Services with Terraform

Learn Terraform. 

Not a CBT Nuggets subscriber? Begin your 7-day free trial now.


Download

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522