Initial Terraform CDK support

This commit is contained in:
Khue Doan 2021-08-03 17:14:13 +00:00
parent dc16722239
commit 872aac3e92
6 changed files with 100 additions and 0 deletions

21
infra/cdk/.gitignore vendored Normal file
View File

@ -0,0 +1,21 @@
# cdktf and terraform ignores
.terraform
cdktf.out
cdktf.log
*terraform.*.tfstate*
generated
# src https://github.com/github/gitignore/blob/master/Go.gitignore
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

11
infra/cdk/cdktf.json Normal file
View File

@ -0,0 +1,11 @@
{
"language": "go",
"app": "go run main.go",
"codeMakerOutput": "generated",
"terraformProviders": [],
"terraformModules": [],
"context": {
"excludeStackIdFromLogicalIds": "true",
"allowSepCharsInLogicalIds": "true"
}
}

7
infra/cdk/go.mod Normal file
View File

@ -0,0 +1,7 @@
module cdk.tf/go/stack
go 1.16
require github.com/aws/constructs-go/constructs/v3 v3.3.75
require github.com/hashicorp/terraform-cdk-go/cdktf v0.5.0

15
infra/cdk/go.sum Normal file
View File

@ -0,0 +1,15 @@
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/aws/constructs-go/constructs/v3 v3.3.75 h1:sunQ8/mQwVoV0OdGYmSh/s8Z2XyUXr8hCc/bKzz6SoU=
github.com/aws/constructs-go/constructs/v3 v3.3.75/go.mod h1:gh+X5UyxGPp/fWyp8iVMa75yMDQev4639pQ93HXXMoA=
github.com/aws/jsii-runtime-go v1.28.0/go.mod h1:6tZnlstx8bAB3vnLFF9n8bbkI//LDblAek9zFyMXV3E=
github.com/aws/jsii-runtime-go v1.29.0 h1:JH4GHSauYskfzREWaQMAMTXDRgNR2e5XeLbjD/xf9J0=
github.com/aws/jsii-runtime-go v1.29.0/go.mod h1:6tZnlstx8bAB3vnLFF9n8bbkI//LDblAek9zFyMXV3E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/terraform-cdk-go/cdktf v0.5.0 h1:zTy/YB8Q69QmiTAeVtG79TKKaFyJZF8ez7dvneRQ/LQ=
github.com/hashicorp/terraform-cdk-go/cdktf v0.5.0/go.mod h1:Lzi9rFr53rGiJGwD1OW6VjadHDApWJ94GXfdHDX3Mf4=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

24
infra/cdk/help Normal file
View File

@ -0,0 +1,24 @@
========================================================================================================
Your cdktf go project is ready!
cat help Prints this message
Compile:
go build Builds your go project
Synthesize:
cdktf synth [stack] Synthesize Terraform resources to cdktf.out/
Diff:
cdktf diff [stack] Perform a diff (terraform plan) for the given stack
Deploy:
cdktf deploy [stack] Deploy the given stack
Destroy:
cdktf destroy [stack] Destroy the given stack
Learn more about using modules and providers https://cdk.tf/modules-and-providers
========================================================================================================

22
infra/cdk/main.go Normal file
View File

@ -0,0 +1,22 @@
package main
import (
"github.com/aws/constructs-go/constructs/v3"
"github.com/hashicorp/terraform-cdk-go/cdktf"
)
func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack {
stack := cdktf.NewTerraformStack(scope, &id)
// The code that defines your stack goes here
return stack
}
func main() {
app := cdktf.NewApp(nil)
NewMyStack(app, "cdk")
app.Synth()
}