Created
May 12, 2021 20:12
-
-
Save steveyackey/082c6ab85562166e1b122c26566b1718 to your computer and use it in GitHub Desktop.
EKS with CDK in Go
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
package main | |
import ( | |
"github.com/aws/aws-cdk-go/awscdk" | |
"github.com/aws/aws-cdk-go/awscdk/awseks" | |
"github.com/aws/constructs-go/constructs/v3" | |
"github.com/aws/jsii-runtime-go" | |
) | |
type EksCdkGoStackProps struct { | |
awscdk.StackProps | |
} | |
func NewEksCdkGoStack(scope constructs.Construct, id string, props *EksCdkGoStackProps) awscdk.Stack { | |
var sprops awscdk.StackProps | |
if props != nil { | |
sprops = props.StackProps | |
} | |
stack := awscdk.NewStack(scope, &id, &sprops) | |
cluster := awseks.NewCluster(stack, jsii.String("MyNewCluster"), &awseks.ClusterProps{ | |
Version: awseks.KubernetesVersion_V1_19(), | |
ClusterName: jsii.String("my-new-cluster"), // Overrides the auto-generated name | |
}) | |
cluster.AddHelmChart(jsii.String("KubePrometheusStack"), &awseks.HelmChartOptions{ | |
Chart: jsii.String("kube-prometheus-stack"), | |
Repository: jsii.String("https://prometheus-community.github.io/helm-charts"), | |
Namespace: jsii.String("prometheus"), | |
CreateNamespace: jsii.Bool(true), // Defaults to true and not required, but shown for clarity | |
Release: jsii.String("prometheus"), // Overrides the auto-generated release name | |
}) | |
return stack | |
} | |
func main() { | |
app := awscdk.NewApp(nil) | |
NewEksCdkGoStack(app, "EksCdkGoStack", &EksCdkGoStackProps{ | |
awscdk.StackProps{ | |
Env: env(), | |
}, | |
}) | |
app.Synth(nil) | |
} | |
// env determines the AWS environment (account+region) in which our stack is to | |
// be deployed. For more information see: https://docs.aws.amazon.com/cdk/latest/guide/environments.html | |
func env() *awscdk.Environment { | |
// If unspecified, this stack will be "environment-agnostic". | |
// Account/Region-dependent features and context lookups will not work, but a | |
// single synthesized template can be deployed anywhere. | |
//--------------------------------------------------------------------------- | |
return nil | |
// Uncomment if you know exactly what account and region you want to deploy | |
// the stack to. This is the recommendation for production stacks. | |
//--------------------------------------------------------------------------- | |
// return &awscdk.Environment{ | |
// Account: jsii.String("123456789012"), | |
// Region: jsii.String("us-east-1"), | |
// } | |
// Uncomment to specialize this stack for the AWS Account and Region that are | |
// implied by the current CLI configuration. This is recommended for dev | |
// stacks. | |
//--------------------------------------------------------------------------- | |
// return &awscdk.Environment{ | |
// Account: jsii.String(os.Getenv("CDK_DEFAULT_ACCOUNT")), | |
// Region: jsii.String(os.Getenv("CDK_DEFAULT_REGION")), | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment