The Cloud Development Kit for Terraform 0.4 introduces experimental Go language support, asset construct, and Terraform Cloud integration.
We are excited to announce the release of Cloud Development Kit (CDK) for Terraform 0.4. CDK for Terraform provides the ability to write Terraform configurations in C#, Python, TypeScript, and Java, using all existing Terraform providers and Terraform modules. CDK for Terraform 0.4 adds experimental Go support. You can download the new release by following the getting started guide in the programming language of your choice.
Key improvements in 0.4 include:
Support for the Go language has been one of the top requests from users. The jsii library, which we use to generate language bindings between TypeScript and each of the supported languages, recently added experimental Go support. Building on this, we’re excited to announce experimental Go support in CDK for Terraform: you can now define infrastructure with Terraform providers using Go!
package main import ( "github.com/hashicorp/terraform-cdk/examples/go/aws/generated/aws_eks_module" "github.com/hashicorp/terraform-cdk/examples/go/aws/generated/hashicorp/aws" "github.com/aws/constructs-go/constructs/v3" "github.com/aws/jsii-runtime-go" "github.com/hashicorp/terraform-cdk-go/cdktf") func NewExampleCdktfGoAwsStack(scope constructs.Construct, id string) cdktf.TerraformStack { stack := cdktf.NewTerraformStack(scope, &id) aws.NewAwsProvider(stack, jsii.String("aws"), &aws.AwsProviderConfig{ Region: jsii.String("us-east-1"), }) aws.NewInstance(stack, jsii.String("Hello"), &aws.InstanceConfig{ Ami: jsii.String("ami-2757f631"), InstanceType: jsii.String("t2.micro"), Tags: &map[string]*string{ "environment": jsii.String("development"), }, }) aws_eks_module.NewAwsEksModule(stack, jsii.String("EKS"), &aws_eks_module.AwsEksModuleOptions{ ClusterName: jsii.String("my-eks"), Subnets: jsii.Strings("a", "b"), VpcId: jsii.String("id"), ClusterVersion: jsii.String("1.17"), }) return stack} func main() { app := cdktf.NewApp(nil) NewExampleCdktfGoAwsStack(app, "ExampleCdktfGoAwsStack") app.Synth()}
To try out writing infrastructure as code in Go, try our Go Getting Started guide. Note that this feature is still considered experimental, therefore it should not be used in production, and you may see changes to Go syntax. Please share your experiences with us by posting to the CDK for Terraform Discuss forum.
Deploying files or folders is a common part of many workflows, such as provisioning serverless applications. The new asset
construct makes it easy to reference files and folders that need to be deployed alongside newly provisioned resources.
Here is a TypeScript example:
import * as path from "path";import { Construct } from "constructs";import { App, TerraformStack, TerraformAsset, AssetType } from "cdktf";import { AwsProvider } from "./.gen/providers/aws/aws-provider";import { S3BucketObject } from "./.gen/providers/aws/s3-bucket-object";import { S3Bucket } from "./.gen/providers/aws/s3-bucket"; class MyStack extends TerraformStack { constructor(scope: Construct, name: string) { super(scope, name); new AwsProvider(this, "provider", { region: "us-west-2", }); const bucket = new S3Bucket(this, "bucket", { bucket: "demo", }); const asset = new TerraformAsset(this, "lambda-asset", { path: path.resolve(__dirname, "../lambda"), type: AssetType.ARCHIVE, // if left empty it infers directory and file }); new S3BucketObject(this, "lambda-archive", { bucket: bucket.bucket, key: asset.fileName, source: asset.path, }); }} const app = new App();new MyStack(app, "demo");app.synth();
The CDK for Terraform project and team have grown significantly since its 0.1 launch in January. Ansgar Mertens and Daniel Schmidt have recently joined the team, and with more people on board we’ve been able to expand the feature set:
Each stack can be destroyed separately, and state is stored independently.
Remote templates were added in 0.3 to allow rapid creation of new projects without writing boilerplate code.
Language-specific bindings are now published in language-native package repositories, such as Maven Central, NPM, PyPi, and Nuget.
The CDK for Terraform changelog contains a comprehensive list of enhancements and bug fixes.
Whether you’re experimenting or actively using CDK for Terraform, we’d love to hear from you directly. Bring your questions to Terraform Community Office Hours on June 3rd, 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!
We have language-specific guides and documentation in our GitHub repository, but if you’re new to the project, the CDK for Terraform Learn Guide is the best way to get started.
No-code provisioning module version upgrades are now GA in HCP Terraform, providing validated self-service infrastructure to reduce toil and lower cloud spend.
Do cloud right with The Infrastructure Cloud from HashiCorp. Unlock developer potential while controlling cloud costs and risk.
A recap of HashiCorp infrastructure and security news and developments from Google Cloud Next, from scaling infrastructure as code to fighting secrets sprawl and more.