Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
[skip ci] Improved documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Petri Autero committed Apr 10, 2019
1 parent 16ddf1b commit cf71d5f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 12 deletions.
8 changes: 7 additions & 1 deletion examples/gke-basic-tiller/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ terraform {
required_version = ">= 0.10.3"
}

# ---------------------------------------------------------------------------------------------------------------------
# PREPARE PROVIDERS
# ---------------------------------------------------------------------------------------------------------------------

provider "google" {
version = "~> 2.3.0"
project = "${var.project}"
Expand Down Expand Up @@ -74,7 +78,9 @@ module "gke_cluster" {
cluster_secondary_range_name = "${google_compute_subnetwork.main.secondary_ip_range.0.range_name}"
}

# Deploy a Node Pool
# ---------------------------------------------------------------------------------------------------------------------
# CREATE A NODE POOL
# ---------------------------------------------------------------------------------------------------------------------

resource "google_container_node_pool" "node_pool" {
provider = "google-beta"
Expand Down
2 changes: 1 addition & 1 deletion examples/gke-basic-tiller/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ---------------------------------------------------------------------------------------------------------------------

variable "project" {
description = "The name of the GCP Project where all resources will be launched."
description = "The project ID where all resources will be launched."
}

variable "location" {
Expand Down
17 changes: 15 additions & 2 deletions examples/gke-private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ terraform {
required_version = ">= 0.10.3"
}

# ---------------------------------------------------------------------------------------------------------------------
# PREPARE PROVIDERS
# ---------------------------------------------------------------------------------------------------------------------

provider "google" {
version = "~> 2.3.0"
project = "${var.project}"
Expand All @@ -21,6 +25,10 @@ provider "google-beta" {
region = "${var.region}"
}

# ---------------------------------------------------------------------------------------------------------------------
# DEPLOY A PRIVATE CLUSTER IN GOOGLE CLOUD
# ---------------------------------------------------------------------------------------------------------------------

module "gke_cluster" {
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
# to a specific version of the modules, such as the following example:
Expand Down Expand Up @@ -55,9 +63,10 @@ module "gke_cluster" {
cluster_secondary_range_name = "${google_compute_subnetwork.main.secondary_ip_range.0.range_name}"
}

# Node Pool
# ---------------------------------------------------------------------------------------------------------------------
# CREATE A NODE POOL
# ---------------------------------------------------------------------------------------------------------------------

// Node Pool Resource
resource "google_container_node_pool" "node_pool" {
provider = "google-beta"

Expand Down Expand Up @@ -124,6 +133,10 @@ module "gke_service_account" {
description = "${var.cluster_service_account_description}"
}

# ---------------------------------------------------------------------------------------------------------------------
# CREATE A NETWORK TO DEPLOY THE CLUSTER TO
# ---------------------------------------------------------------------------------------------------------------------

# TODO(rileykarson): Add proper VPC network config once we've made a VPC module
resource "random_string" "suffix" {
length = 4
Expand Down
2 changes: 1 addition & 1 deletion examples/gke-private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ---------------------------------------------------------------------------------------------------------------------

variable "project" {
description = "The name of the GCP Project where all resources will be launched."
description = "The project ID where all resources will be launched."
}

variable "location" {
Expand Down
16 changes: 14 additions & 2 deletions examples/gke-public-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ terraform {
required_version = ">= 0.10.3"
}

# ---------------------------------------------------------------------------------------------------------------------
# PREPARE PROVIDERS
# ---------------------------------------------------------------------------------------------------------------------

provider "google" {
version = "~> 2.3.0"
project = "${var.project}"
Expand All @@ -22,6 +26,10 @@ provider "google-beta" {
region = "${var.region}"
}

# ---------------------------------------------------------------------------------------------------------------------
# DEPLOY A PUBLIC CLUSTER IN GOOGLE CLOUD
# ---------------------------------------------------------------------------------------------------------------------

module "gke_cluster" {
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
# to a specific version of the modules, such as the following example:
Expand All @@ -38,9 +46,10 @@ module "gke_cluster" {
cluster_secondary_range_name = "${google_compute_subnetwork.main.secondary_ip_range.0.range_name}"
}

# Node Pool
# ---------------------------------------------------------------------------------------------------------------------
# CREATE A NODE POOL
# ---------------------------------------------------------------------------------------------------------------------

// Node Pool Resource
resource "google_container_node_pool" "node_pool" {
provider = "google-beta"

Expand Down Expand Up @@ -107,6 +116,9 @@ module "gke_service_account" {
description = "${var.cluster_service_account_description}"
}

# ---------------------------------------------------------------------------------------------------------------------
# CREATE A NETWORK TO DEPLOY THE CLUSTER TO
# ---------------------------------------------------------------------------------------------------------------------
# TODO(rileykarson): Add proper VPC network config once we've made a VPC module
resource "random_string" "suffix" {
length = 4
Expand Down
2 changes: 1 addition & 1 deletion examples/gke-public-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ---------------------------------------------------------------------------------------------------------------------

variable "project" {
description = "The name of the GCP Project where all resources will be launched."
description = "The project ID where all resources will be launched."
}

variable "location" {
Expand Down
18 changes: 14 additions & 4 deletions modules/gke-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# This module deploys a GKE cluster, a managed, production-ready environment for deploying containerized applications.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ---------------------------------------------------------------------------------------------------------------------
# Create the GKE Cluster
# We want to make a cluster with no node pools, and manage them all with the fine-grained google_container_node_pool resource
# ---------------------------------------------------------------------------------------------------------------------

resource "google_container_cluster" "cluster" {
name = "${var.name}"
description = "${var.description}"
Expand All @@ -16,11 +21,8 @@ resource "google_container_cluster" "cluster" {
monitoring_service = "${var.monitoring_service}"
min_master_version = "${local.kubernetes_version}"

# We want to make a cluster with no node pools, and manage them all with the
# fine-grained google_container_node_pool resource. The API requires a node
# pool or an initial count to be defined; that initial count creates the
# The API requires a node pool or an initial count to be defined; that initial count creates the
# "default node pool" with that # of nodes.
#
# So, we need to set an initial_node_count of 1. This will make a default node
# pool with server-defined defaults that Terraform will immediately delete as
# part of Create. This leaves us in our desired state- with a cluster master
Expand Down Expand Up @@ -94,11 +96,19 @@ resource "google_container_cluster" "cluster" {
}
}

# ---------------------------------------------------------------------------------------------------------------------
# Prepare locals to keep the code cleaner
# ---------------------------------------------------------------------------------------------------------------------

locals {
kubernetes_version = "${var.kubernetes_version != "latest" ? var.kubernetes_version : data.google_container_engine_versions.location.latest_node_version}"
network_project = "${var.network_project != "" ? var.network_project : var.project}"
}

# ---------------------------------------------------------------------------------------------------------------------
# Pull in data
# ---------------------------------------------------------------------------------------------------------------------

data "google_compute_network" "gke_network" {
name = "${var.network}"
project = "${local.network_project}"
Expand Down

0 comments on commit cf71d5f

Please sign in to comment.