Skip to content

kameshsampath/gke-tf

Repository files navigation

GKE Terraform Template

A GitHub template that could be used to get started with Google Kubernetes Engine(GKE) using terraform.

Pre-requisites

Using this Template

On browser navigate to the repo https://github.com/kameshsampath/gke-tf and click Use Template, follow the wizard to create your repository based on the template.

Using github cli

gh repo create --public --description="My GKE Demos and Examples" --template https://github.com/kameshsampath/gke-tf my-gke-demos
gh repo clone my-gke-demos

Environment Variables

When working with Google Cloud the following environment variables helps in setting the right Google Cloud context like Service Account Key file, project etc., You can use direnv or set the following variables on your shell,

export GOOGLE_APPLICATION_CREDENTIALS="the google cloud service account key json file to use"
export CLOUDSDK_ACTIVE_CONFIG_NAME="the google cloud cli profile to use"

You can find more information about gcloud cli configurations at https://cloud.google.com/sdk/docs/configurations.

As you may need to override few terraform variables that you don't want to check in to VCS, add them to a file called <name>.local.tfvars and set the following environment variable to be picked up by terraform runs,

export TFVARS_FILE=<name>.local.tfvars

NOTE: All .local.tfvars file are git ignored by this template.

Inputs

Name Description Type Default Required
cluster_name the gke cluster name string "my-demos" no
gke_num_nodes number of gke nodes number 2 no
kubernetes_version the kubernetes versions of the GKE clusters string "1.24." no
machine_type the google cloud machine types for each cluster node string "e2-standard-4" no
project_id project id any n/a yes
region the region or zone where the cluster will be created string "asia-south1" no
release_channel the GKE release channel to use string "stable" no

Outputs

Name Description
kubeconfig_path Kubeconfig file
kubernetes_cluster_host GKE Cluster Host
kubernetes_cluster_name GKE Cluster Name
project_id GCloud Project ID
region GCloud Region
zone GCloud Zone

Providers

Name Version
google 4.47.0
local 2.2.3
random 3.4.3

Requirements

Name Version
terraform >= 0.14
google >= 4.47.0
helm 2.8.0
kubernetes 2.16.1
local 2.2.3
random 3.4.3

Resources

Name Type
google_compute_network.vpc resource
google_compute_subnetwork.subnet resource
google_container_cluster.primary resource
google_container_node_pool.primary_nodes resource
local_file.kubeconfig resource
random_shuffle.az resource
google_compute_zones.available data source
google_container_engine_versions.supported data source

References

License

Apache License

About

Deploy a GKE cluster using terraform

Topics

Resources

License

Stars

Watchers

Forks