The latest release of CDK for Terraform includes TypeScript unit testing via Jest, improved handling of native Terraform functions, and Bash and zsh shell completion.
We are excited to announce the release of Cloud Development Kit (CDK) for HashiCorp Terraform 0.6. With CDK for Terraform, you can write Terraform configurations in your choice of C#, Python, TypeScript, or Java (Go experimental), and still benefit from the full ecosystem of Terraform providers and modules. CDK for Terraform 0.6 adds an opinionated unit-testing workflow for testing your infrastructure code.
Key improvements in the CDK for Terraform 0.6 include:
CDK for Terraform provides a workflow where writing infrastructure as code can feel like writing software. Since testing is a key part of writing high quality software, this release adds support for unit-testing TypeScript infrastructure code using Jest to do snapshot tests and assertions. Support for testing in other languages will be added in future releases.
Snapshot tests compare the synthesized Terraform configuration to a previously saved “snapshot” version. During refactoring, this provides a high level of confidence that no unintended changes were introduced. Snapshot tests run very quickly, and provide a high level of test coverage with a few test cases.
Assertions allow fine-grained testing of your generated Terraform configurations. For example, the following tests first confirm that the generated code has a Container
resource at all, then validates that the container image is ubuntu:latest
:
Finally, you can automate validation that the resulting code plans successfully:
Internally, the testing is powered by Jest, a popular JavaScript testing framework. Jest automates snapshot management and should be familiar to most TypeScript developers.
For more details on how to test your infrastructure code, see the CDK for Terraform Testing documentation on GitHub.
CDK for Terraform 0.6 also improves handling of native Terraform functions, adds Bash and zsh shell completion, and includes a variety of other improvements and bug fixes. See the function documentation for details on using Terraform functions. The CDK for Terraform changelog contains a comprehensive list of enhancements and bug fixes included in this release.
Please note that CDK for Terraform 0.6 contains breaking changes that will require code updates if you use Aspects
, construct.node.addInfo()
, construct.node.addWarning()
, construct.node.Error()
, construct.onPrepare()
, or construct.prepare()
. Please see the CHANGELOG and 0.6 Upgrade Guide for details.
If you’re new to the project, the tutorials for CDK for Terraform on HashiCorp Learn are the best way to get started. We also have language-specific guides and documentation in our GitHub repository.
Check out the recording of our Terraform Community Office Hours for a demo and detailed explanation of the new testing tools.
Whether you’re experimenting or actively using CDK for Terraform, we’d love to hear from you. We’re particularly looking for feedback on the new testing functionality — please file any bugs you encounter, let us know about your feature requests (for example, if you’d find Python testing useful), and share other questions, thoughts, and experiences in the CDK for Terraform discussion forum.
Terraform Enterprise now supports more flexible deployment options for self-hosted environments, including cloud-managed Kubernetes services.
Assigning agents at the organization level provides a faster, more consistent, and scalable approach to agent pool configuration.
Learn how creating a golden image pipeline can help unify and streamline your imaging and provisioning workflows throughout your infrastructure estate.