Easily authenticate against a Google Kubernetes Engine (GKE) within your CDK for Terraform stack. Without the need to
resort to Google's terraform GKE auth module. You can avoid running cdktf get
as pre-synth step.
This project uses projen and jsii to compile the construct to Typescript, Python, Go and .Net (Java upon request).
Install the construct with: yarn install cdktf-gke-auth
.
import { GoogleProvider } from "@cdktf/provider-google/lib/provider";
import { TerraformOutput, TerraformStack } from "cdktf";
import { Construct } from "constructs";
import { GKEAuth } from 'cdktf-gke-auth';
export class MyKubeStack extends TerraformStack {
constructor(scope: Construct, name: string) {
super(scope, name);
new GoogleProvider(this, "google-provider", {});
const auth = new GKEAuth(this, "gke-auth", {
clusterName: "my-cluster",
location: "europe-west1",
projectId: "my-project",
});
// init the Kubernetes provider like so:
new KubernetesProvider(this, "kubernetes", {
...auth.authCredentials
});
// Or a helm provider like so:
new HelmProvider(this, "helm", {
kubernetes: auth.authCredentials,
});
}
}
The GKEAuth
instance expose host
, clusterCaCertificate
, clusterCaCertificatePEM
, and token
you can use to authenticate using
any of the kubernetes popular cdktf providers.
For other languages examples, checkout this construct on ConstructHub.
- Implements: cdktf.ITerraformDependable
import { GKEAuth } from 'cdktf-gke-auth'
new GKEAuth(scope: Construct, id: string, props: ClusterInfo)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
ClusterInfo |
No description. |
- Type: constructs.Construct
- Type: string
- Type: ClusterInfo
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
public toString(): string
Returns a string representation of this construct.
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
import { GKEAuth } from 'cdktf-gke-auth'
GKEAuth.isConstruct(x: any)
Checks if x
is a construct.
Use this method instead of instanceof
to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs
library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct
in each copy of the constructs
library
is seen as a different class, and an instance of one class will not test as
instanceof
the other class. npm install
will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof
will behave
unpredictably. It is safest to avoid using instanceof
, and using
this type-testing method instead.
- Type: any
Any object.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
authCredentials |
AuthCredentials |
No description. |
clientConfig |
@cdktf/provider-google.dataGoogleClientConfig.DataGoogleClientConfig |
No description. |
clusterCaCertificate |
string |
No description. |
clusterCaCertificatePEM |
string |
No description. |
clusterInfo |
@cdktf/provider-google.dataGoogleContainerCluster.DataGoogleContainerCluster |
No description. |
context |
string |
No description. |
fqn |
string |
No description. |
host |
string |
No description. |
kubeConfigRaw |
string |
No description. |
token |
string |
No description. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly authCredentials: AuthCredentials;
- Type: AuthCredentials
public readonly clientConfig: DataGoogleClientConfig;
- Type: @cdktf/provider-google.dataGoogleClientConfig.DataGoogleClientConfig
public readonly clusterCaCertificate: string;
- Type: string
public readonly clusterCaCertificatePEM: string;
- Type: string
public readonly clusterInfo: DataGoogleContainerCluster;
- Type: @cdktf/provider-google.dataGoogleContainerCluster.DataGoogleContainerCluster
public readonly context: string;
- Type: string
public readonly fqn: string;
- Type: string
public readonly host: string;
- Type: string
public readonly kubeConfigRaw: string;
- Type: string
public readonly token: string;
- Type: string
import { AuthCredentials } from 'cdktf-gke-auth'
const authCredentials: AuthCredentials = { ... }
Name | Type | Description |
---|---|---|
clusterCaCertificate |
string |
No description. |
host |
string |
No description. |
token |
string |
No description. |
public readonly clusterCaCertificate: string;
- Type: string
public readonly host: string;
- Type: string
public readonly token: string;
- Type: string
import { ClusterInfo } from 'cdktf-gke-auth'
const clusterInfo: ClusterInfo = { ... }
Name | Type | Description |
---|---|---|
clusterName |
string |
No description. |
location |
string |
No description. |
projectId |
string |
No description. |
public readonly clusterName: string;
- Type: string
public readonly location: string;
- Type: string
public readonly projectId: string;
- Type: string