Skip to main content

CDK for Terraform 0.14 Makes it Easier to Use Providers

Cloud Development Kit for Terraform (CDKTF) 0.14 makes it easier to add and upgrade Terraform providers.

We are excited to announce the release of Cloud Development Kit for Terraform (CDKTF) 0.14. With CDK for Terraform, you can write Terraform configurations in your choice of C#, Python, TypeScript, Java, or Go, and still benefit from the full ecosystem of Terraform providers and modules.

Auto-generating the code bindings for a large Terraform provider can take several minutes, so CDKTF offers pre-built provider packages that you can import directly into your application. Version 0.14 introduces several improvements that make pre-built providers easier to use, including:

  • New provider upgrade command: Now you can upgrade installed provider bindings while respecting dependencies such as the CDKTF version.
  • Select pre-built providers when initializing a new project: The cdktf init command now lists all available pre-built providers when initializing a new project and allows you to directly install them when setting up a new CDKTF project.
  • More pre-built providers: We now publish pre-built provider packages for all official Terraform providers.
  • Improvements to the get Command: Subsequent runs of get are faster now because existing bindings are not regenerated.

Back in October, we announced significant performance improvements with CDKTF version 0.13. These improvements required breaking changes for which we provided backward-compatible provider bindings in version 0.13. As announced, the 0.12 (non-namespaced) provider bindings will no longer work starting with CDKTF 0.14. Refer to the upgrade guide for 0.13 to learn how to update your imports for these changes.

»New provider upgrade Command

With the new provider upgrade command, you can update your providers regardless of whether they are installed via pre-built provider packages or are available as locally generated providers. The command will update either the installed package or the version constraint for the locally generated providers, depending on how they are currently configured. While doing so, it will make sure that updated pre-built provider packages are compatible with the currently used CDKTF version:

$ cdktf provider upgrade random
Upgrading random...
Adding package @cdktf/provider-random @‎ 3.0.11
Installing package @cdktf/provider-random @ ‎3.0.11 using npm.
Package installed.
 
$ cdktf provider upgrade random
Upgrading random...
The latest version of @cdktf/provider-random is already installed: 3.0.11

Similar to the provider add command, you can also supply a version constraint to provider upgrade:

$ cdktf provider add "aws@~>3.0"
Checking whether pre-built provider exists for the following constraints:
  provider: aws
  version : ~>3.0
  language: typescript
  cdktf   : 0.13.3
 
Pre-built provider does not exist for the given constraints.
Adding local provider registry.terraform.io/hashicorp/aws with version constraint ~>3.0 to cdktf.json
Local providers have been updated. Running cdktf get to update...
Generated typescript constructs in the output directory: .gen
 
$ cdktf provider upgrade "aws@~>4.0"
Upgrading aws...
Local providers have been updated. Running cdktf get to update...
Generated typescript constructs in the output directory: .gen

»Select Pre-Built Providers When Initializing a New Project

After creating a new CDK for Terraform project using the cdktf init command, you can select from a list of all available pre-built provider packages and directly add them to your new project:

Note: You can always add providers using 'cdktf provider add' later on
? What providers do you want to use? (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
 vault
 vsphere
 acme
❯◯ ad
 archive
 aws
 azuread
(Move up and down to reveal more choices)

»More Pre-built Providers

We now publish pre-built provider packages for all official Terraform providers. Use the provider add command to add any one of them or select them when initializing a new CDKTF project:

$ cdktf provider add nomad
Checking whether pre-built provider exists for the following constraints:
  provider: nomad
  version : latest
  language: typescript
  cdktf   : 0.13.3
 
Found pre-built provider.
Adding package @cdktf/provider-nomad @ 1.0.3
Installing package @cdktf/provider-nomad @ 1.0.3 using npm.
Package installed.

»Improvements to the get Command

As of 0.14 the get command, which is used to generate local bindings for Terraform providers, won’t re-generate everything all the time. Instead, it will only generate bindings for providers that have been added or changed since the last time get was run. This drastically lowers the time spent generating provider bindings locally, for example, when new ones are added using the provider add command.

»What's Next for CDKTF

The upcoming CDKTF 0.15 release will focus primarily on quality-of-life improvements that make it easier to use Terraform Cloud and Terraform Enterprise with CDK for Terraform, such as creating workspaces when adding more stacks to projects.

»Try CDK for Terraform

If you’re new to the project, these tutorials for CDK for Terraform are the best way to get started. You can dive deeper into our documentation with this overview of CDKTF.

Whether you’re experimenting or actively using CDK for Terraform, we’d love to hear from you. Please file any bugs you encounter, let us know about your feature requests, and share other questions, thoughts, and experiences in the CDK for Terraform discussion forum.


Sign up for the latest HashiCorp news

By submitting this form, you acknowledge and agree that HashiCorp will process your personal information in accordance with the Privacy Policy.