-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): add google cloud kubernetes example
- Loading branch information
1 parent
33b5132
commit 5b2da57
Showing
8 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"language": "go", | ||
"app": "go run main.go", | ||
"codeMakerOutput": "generated", | ||
"terraformProviders": [ | ||
"hashicorp/kubernetes@ ~> 2.2.0", | ||
"kreuzwerker/docker@ ~> 2.11.0", | ||
"hashicorp/local@ ~> 2.1.0", | ||
"hashicorp/helm@ ~> 2.1.2", | ||
"hashicorp/google@ ~> 3.69.0" | ||
], | ||
"terraformModules": [ | ||
{ | ||
"name": "gkeAuth", | ||
"source": "terraform-google-modules/kubernetes-engine/google//modules/auth", | ||
"version": "14.3.0" | ||
} | ||
], | ||
"context": { | ||
"excludeStackIdFromLogicalIds": "true", | ||
"allowSepCharsInLogicalIds": "true" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/hashicorp/terraform-cdk/examples/go/google | ||
|
||
go 1.16 | ||
|
||
require github.com/aws/constructs-go/constructs/v3 v3.3.75 | ||
|
||
require ( | ||
github.com/aws/jsii-runtime-go v1.29.0 | ||
github.com/hashicorp/terraform-cdk-go/cdktf v0.0.0 | ||
) | ||
|
||
replace github.com/hashicorp/terraform-cdk-go/cdktf => ../../../packages/cdktf/dist/go/cdktf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
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 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||
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 h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
======================================================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package main | ||
|
||
import ( | ||
constructs "github.com/aws/constructs-go/constructs/v3" | ||
"github.com/hashicorp/terraform-cdk-go/cdktf" | ||
|
||
jsii "github.com/aws/jsii-runtime-go" | ||
"github.com/hashicorp/terraform-cdk/examples/go/google/generated/gkeAuth" | ||
"github.com/hashicorp/terraform-cdk/examples/go/google/generated/hashicorp/google" | ||
"github.com/hashicorp/terraform-cdk/examples/go/google/generated/hashicorp/helm" | ||
"github.com/hashicorp/terraform-cdk/examples/go/google/generated/hashicorp/kubernetes" | ||
"github.com/hashicorp/terraform-cdk/examples/go/google/generated/hashicorp/local" | ||
) | ||
|
||
func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack { | ||
stack := cdktf.NewTerraformStack(scope, &id) | ||
google.NewGoogleProvider(stack, jsii.String("google"), &google.GoogleProviderConfig{ | ||
Zone: jsii.String("us-west1"), | ||
Project: jsii.String("dschmidt-cdk-test"), | ||
}) | ||
|
||
sa := google.NewServiceAccount(stack, jsii.String("sa"), &google.ServiceAccountConfig{ | ||
AccountId: jsii.String("cluster-admin"), | ||
DisplayName: jsii.String("Cluster Admin"), | ||
}) | ||
|
||
cluster := google.NewContainerCluster(stack, jsii.String("cluster"), &google.ContainerClusterConfig{ | ||
Name: jsii.String("cluster"), | ||
RemoveDefaultNodePool: jsii.Bool(true), | ||
InitialNodeCount: jsii.Number(1), | ||
}) | ||
|
||
google.NewContainerNodePool(stack, jsii.String("main-pool"), &google.ContainerNodePoolConfig{ | ||
Name: jsii.String("main"), | ||
Cluster: cluster.Name(), | ||
NodeConfig: &[]*google.ContainerNodePoolNodeConfig{ | ||
{ | ||
MachineType: jsii.String("e2-medium"), | ||
Preemptible: jsii.Bool(true), | ||
ServiceAccount: sa.Email(), | ||
OauthScopes: &[]*string{jsii.String("https://www.googleapis.com/auth/cloud-platform")}, | ||
}, | ||
}, | ||
}) | ||
|
||
auth := gkeAuth.NewGkeAuth(stack, jsii.String("auth"), &gkeAuth.GkeAuthOptions{ | ||
ClusterName: cluster.Name(), | ||
Location: cluster.Location(), | ||
ProjectId: cluster.Project(), | ||
}) | ||
|
||
local.NewFile(stack, jsii.String("kubeconfig"), &local.FileConfig{ | ||
Filename: jsii.String("kubeconfig.yaml"), | ||
Content: auth.KubeconfigRawOutput(), | ||
}) | ||
|
||
kubernetes.NewKubernetesProvider(stack, jsii.String("kubernetes"), &kubernetes.KubernetesProviderConfig{ | ||
ClusterCaCertificate: auth.ClusterCaCertificateOutput(), | ||
Host: auth.HostOutput(), | ||
Token: auth.TokenOutput(), | ||
}) | ||
|
||
namespaceName := "development" | ||
kubernetes.NewNamespace(stack, jsii.String("namespace"), &kubernetes.NamespaceConfig{ | ||
Metadata: &[]*kubernetes.NamespaceMetadata{ | ||
{ | ||
Name: jsii.String(namespaceName), | ||
}, | ||
}, | ||
}) | ||
|
||
helm.NewHelmProvider(stack, jsii.String("helm"), &helm.HelmProviderConfig{ | ||
Kubernetes: &[]*helm.HelmProviderKubernetes{ | ||
{ | ||
ClusterCaCertificate: auth.ClusterCaCertificateOutput(), | ||
Host: auth.HostOutput(), | ||
Token: auth.TokenOutput(), | ||
}, | ||
}, | ||
}) | ||
|
||
helm.NewRelease(stack, jsii.String("cert-manager"), &helm.ReleaseConfig{ | ||
Name: jsii.String("cert-manager"), | ||
Repository: jsii.String("https://charts.jetstack.io"), | ||
Chart: jsii.String("cert-manager"), | ||
CreateNamespace: jsii.Bool(true), | ||
Namespace: jsii.String("cert-manager"), | ||
Version: jsii.String("v1.3.1"), | ||
}) | ||
|
||
return stack | ||
} | ||
|
||
func main() { | ||
app := cdktf.NewApp(nil) | ||
|
||
NewMyStack(app, "google") | ||
|
||
app.Synth() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@examples/go-google", | ||
"version": "0.0.0", | ||
"license": "MPL-2.0", | ||
"scripts": { | ||
"reinstall": "rm go.sum", | ||
"build": "cdktf get && go mod tidy", | ||
"synth": "cdktf synth" | ||
} | ||
} |