Skip to content

Commit

Permalink
Terraform: update cluster version, use data source
Browse files Browse the repository at this point in the history
Add Kubernetes version prefix parameter.
`google_container_engine_versions` allows to select proper node and master
version which applicable for every zone in the region.
  • Loading branch information
aLekSer committed May 4, 2020
1 parent 6a02b31 commit 218acc6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
6 changes: 5 additions & 1 deletion build/includes/terraform.mk
Expand Up @@ -81,5 +81,9 @@ endif
GCP_CLUSTER_NAME=$(GCP_TF_CLUSTER_NAME) $(MAKE) gcloud-auth-cluster

gcloud-terraform-destroy-cluster:
ifndef GCP_PROJECT
$(eval GCP_PROJECT=$(shell sh -c "gcloud config get-value project 2> /dev/null"))
endif
$(DOCKER_RUN) bash -c 'cd $(mount_path)/build/terraform/gke && \
terraform destroy -target module.helm_agones.helm_release.agones -auto-approve && sleep 60 && terraform destroy -auto-approve'
terraform destroy -var project=$(GCP_PROJECT) -target module.helm_agones.helm_release.agones -auto-approve && sleep 60 && \
terraform destroy -var project=$(GCP_PROJECT) -auto-approve'
16 changes: 10 additions & 6 deletions build/terraform/gke/module.tf
Expand Up @@ -97,17 +97,21 @@ variable "feature_gates" {
default = ""
}

variable "kubernetes_version" {
default = "1.15"
}

module "gke_cluster" {
source = "../../../install/terraform/modules/gke"

cluster = {
"name" = var.name
"zone" = var.zone
"machineType" = var.machine_type
"initialNodeCount" = var.node_count
"project" = var.project
"network" = var.network
"name" = var.name
"zone" = var.zone
"machineType" = var.machine_type
"initialNodeCount" = var.node_count
"project" = var.project
"network" = var.network
"kubernetesVersion" = var.kubernetes_version
}
}

Expand Down
18 changes: 11 additions & 7 deletions examples/terraform-submodules/gke/module.tf
Expand Up @@ -46,7 +46,6 @@ variable "machine_type" {
variable "node_count" {
default = "4"
}

variable "zone" {
default = "us-west1-c"
description = "The GCP zone to create the cluster in"
Expand All @@ -65,6 +64,10 @@ variable "feature_gates" {
default = ""
}

variable "kubernetes_version" {
default = "1.15"
}

module "gke_cluster" {
// ***************************************************************************************************
// Update ?ref= to the agones release you are installing. For example, ?ref=release-1.3.0 corresponds
Expand All @@ -73,12 +76,13 @@ module "gke_cluster" {
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=master"

cluster = {
"name" = var.name
"zone" = var.zone
"machineType" = var.machine_type
"initialNodeCount" = var.node_count
"project" = var.project
"network" = var.network
"name" = var.name
"zone" = var.zone
"machineType" = var.machine_type
"initialNodeCount" = var.node_count
"project" = var.project
"network" = var.network
"kubernetesVersion" = var.kubernetes_version
}
}

Expand Down
14 changes: 11 additions & 3 deletions install/terraform/modules/gke/cluster.tf
Expand Up @@ -19,6 +19,12 @@ terraform {

data "google_client_config" "default" {}

data "google_container_engine_versions" "kubernetes" {
project = var.cluster["project"]
location = var.cluster["zone"]
version_prefix = var.cluster["kubernetesVersion"]
}

# echo command used for debugging purpose
# Run `terraform taint null_resource.test-setting-variables` before second execution
resource "null_resource" "test-setting-variables" {
Expand All @@ -27,9 +33,9 @@ resource "null_resource" "test-setting-variables" {
${format("echo Current variables set as following - name: %s, project: %s, machineType: %s, initialNodeCount: %s, network: %s, zone: %s",
var.cluster["name"], var.cluster["project"],
var.cluster["machineType"], var.cluster["initialNodeCount"], var.cluster["network"],
var.cluster["zone"])}
var.cluster["zone"])}
EOT
}
}
}

resource "google_container_cluster" "primary" {
Expand All @@ -38,7 +44,9 @@ resource "google_container_cluster" "primary" {
project = var.cluster["project"]
network = var.cluster["network"]

min_master_version = "1.14"
min_master_version = data.google_container_engine_versions.kubernetes.latest_master_version

node_version = data.google_container_engine_versions.kubernetes.latest_node_version

node_pool {
name = "default"
Expand Down
13 changes: 7 additions & 6 deletions install/terraform/modules/gke/variables.tf
Expand Up @@ -25,11 +25,12 @@ variable "cluster" {
type = map

default = {
"zone" = "us-west1-c"
"name" = "test-cluster"
"machineType" = "n1-standard-4"
"initialNodeCount" = "4"
"project" = "agones"
"network" = "default"
"zone" = "us-west1-c"
"name" = "test-cluster"
"machineType" = "n1-standard-4"
"initialNodeCount" = "4"
"project" = "agones"
"network" = "default"
"kubernetesVersion" = "1.15"
}
}
1 change: 1 addition & 0 deletions site/content/en/docs/Installation/Terraform/gke.md
Expand Up @@ -92,6 +92,7 @@ Configurable parameters:
- network - the name of the VPC network you want your cluster and firewall rules to be connected to (default is "default")
- log_level - possible values: Fatal, Error, Warn, Info, Debug (default is "info")
- feature_gates - a list of alpha and beta version features to enable. For example, "PlayerTracking=true&ContainerPortAllocation=true"
- kubernetes_version - a Kubernetes version of the GKE cluster

{{% alert title="Warning" color="warning"%}}
On the lines that read `source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=master"`
Expand Down

0 comments on commit 218acc6

Please sign in to comment.