Prepare the CDK-tf

CDK Terraform is like AWS-CDK an node app.

Install cli

So once you have to install the commandline:

npm install --global cdktf-cli@latest

Create Project

For each project, you create a project template inside an empty directory:

mkdir learn-cdktf-go
cd learn-cdktf-go
cdktf init --template="go" --local

Define AWS provider

In the cdktf.json you have to define the terraformProvoiders.

Add the line

    "terraformProviders": [  "hashicorp/aws@~> 3.67.0" ],

The whole config should look like this now:

    "language": "go",
    "app": "go run main.go",
    "codeMakerOutput": "generated",
    "projectId": "c99f0e38-5feb-41a1-bfd0-2d00e6273780",
    "terraformProviders": [  "hashicorp/aws@~> 3.67.0" ],
    "terraformModules": [],
    "context": {
        "excludeStackIdFromLogicalIds": "true",
"allowSepCharsInLogicalIds": "true"

The version number of the terraform provider and the project ID will vary.

Copy AWS GO constructs to local directory

Now apply

cdktf get

This will take a few minutes. In the subdirectory generated all AWS constructs are created:


Generated go constructs in the output directory: generated

The generated code depends on jsii-runtime-go. If you haven't yet installed it, you can run go mod tidy to automatically install it.


Now you can proceed to create resources in the next chapter.