Benefits of using CDKTF
Besides writing provision code in the same way that you develop an application, CDKTF lets you use the same tools such as your IDE to write provision code. You can also add more logic to the code provisioning using the programming language’s existing toolset such as conditionals, specific input/output, testing, abstraction, etc.)
How does CDKTF work?
CDK for Terraform leverages libraries and concepts from AWS CDK to translate your code into infrastructure configuration files for Terraform.
You typically will go through the following steps:
- Create an application by scaffolding a project in your chosen language using either a custom template or a built-in template.
- Then, define the infrastructure that you want to provision on one or more providers using your chosen language. CDKTF will extract the schema from Terraform providers and modules automatically so that it can generate the required classes for your application. This can take some time to generate, but is only necessary once.
- Lastly, you will use the cdktf CLI commands to synthesize your code into a JSON terraform file that can be used by Terraform directly to provision your infrastructure.
You can also utilize all the Terraform modules and providers available on the Terraform Registry with CDKTF. It’s also available on their commercial product Terraform Cloud and their Enterprise edition.
What is the ideal Usage for CDKTF?
You should investigate whether to use CDKTF when:
- You want developers to provision infrastructure code and let them do that in a programming language they’re familiar with
- You need to manage complexities using abstractions such as when you want to create constructs to model a reusable infrastructure pattern composed of many resources and convenience methods.
- You have a strong preference for a procedural language or need to use one to define infrastructure.
Currently, CDKTF still in beta, so you should be comfortable with doing your own troubleshooting and don’t need commercial support until it’s stable.
You should choose the supported language that you are most familiar with and that fits your company’s present tooling.