Announcing CDK for Terraform 0.5
The CDK for Terraform 0.5 introduces code generation from HCL and a new cdktf watch workflow for serverless workloads.
We are excited to announce the release of a cloud development kit (CDK) for Terraform 0.5. CDK for Terraform provides the ability to write HashiCorp Terraform configurations in C#, Python, TypeScript, and Java using all existing Terraform providers and Terraform modules.
Key improvements in 0.5 include:
- Convert: The ability to convert existing HCL Terraform configurations to C#, Python, TypeScript, and Java.
- Watch: A new experimental
watch
workflow designed for serverless workflows that require rapid iteration in production-like environments.
We’ll be hosting CDK for Terraform Community Office Hours at 1 p.m. PT on Thursday, July 29, where the engineering team will be available to answer questions about CDK for Terraform 0.5.
» Convert HCL Terraform Configurations
The new convert
command automatically translates HCL configuration to CDK’s supported languages.
Since CDK for Terraform internally uses Terraform Core, it’s compatible with all existing Terraform providers and modules, and the Terraform Registry provides a huge library of providers and modules, including copy-pasteable examples of nearly all resources across more than 1,000 providers.
However, these resource examples are in HCL. For many Terraform users, copying examples is a common starting point. To use those examples in other languages via CDK for Terraform, you would have to mentally translate them to the equivalent TypeScript, Python, and other supported languages, which can be slow. The new cdktf convert
command automates this translation to make it easier to apply the existing library of HCL Terraform content to CDK for Terraform.
Here is a simple macOS workflow that shows how to use example code from the Terraform Registry using the pbcopy
and pbpaste
commands: Copy the HCL example from the Terraform Registry, then run pbpaste | cdktf convert --language python | pbcopy
on a macOS terminal. This will convert the example to Python, then copy it again so you can paste it into an editor.
CDK for Terraform 0.5 also introduces the ability to convert full projects from HCL to TypeScript; support for full project conversion to other languages will be added in future releases. To create a new CDK for Terraform configuration by converting an existing HCL Terraform codebase, run:
cdktf init --template="typescript" --from-terraform-project /path/to/terraform/project
See the cdktf convert
documentation for more information, and read about our known limitations. We’re very interested in your practical experiences. Please file GitHub issues and enhancement requests!
» Watch Workflow
cdktf watch
is a new, experimental workflow introduced in CDK for Terraform 0.5 that deploys changes and shows diffs as you edit code.
We added this feature after using CDK for Terraform to build and deploy serverless applications, when we found ourselves wanting to continually redeploy in a production-like environment. This feature is intended to be used in a production-like development environment, and works in all supported languages.
As you edit code, CDK for Terraform watches for changes, synthesizes and applies changes, and continuously shows either changes or errors. The cdktf watch
command is the first step toward a faster iterative development process for CDK for Terraform users.
See the cdktf watch
documentation for more information on how to use this feature.
CDK for Terraform 0.5 also includes bug fixes. The CDK for Terraform changelog contains a comprehensive list of enhancements and bug fixes.
» Try CDK for Terraform
The CDK for Terraform Learn Guide is the best way to get started. Once you’ve completed that, check out our documentation and language-specific examples.
Whether you’re experimenting or actively using CDK for Terraform, we’d love to hear from you. Please drop notes in the discussion forum, and report any issues you encounter in our issue tracker. We’re particularly looking for feedback on the new, experimental Go support, so please reach out.
Sign up for the latest HashiCorp news
More blog posts like this one
Terraform delivers launch-day support for Amazon S3 Tables, EKS Hybrid Nodes, and more at re:Invent
The Terraform provider for AWS now enables users to manage a variety of new services just announced at re:Invent.
HashiCorp at re:Invent 2024: Infrastructure Lifecycle Management with AWS
A recap of HashiCorp infrastructure news and developments on AWS from the past year, from a new provider launch to simplifying infrastructure provisioning and more.
Simplify policy adoption in Terraform with pre-written Sentinel policies for AWS
HashiCorp introduces a new pre-written policy library co-developed with AWS, aiming to reduce the barrier of adoption for policy as code infrastructure workflows.