Skip to content

Commit

Permalink
Add Terraform example for GKE custom VPC deployment (googleforgames#1697
Browse files Browse the repository at this point in the history
)

* Add Custom VPC to terraform gke example
* Add subnetwork to configurable parameters
  • Loading branch information
moesy authored and ilkercelikyilmaz committed Oct 23, 2020
1 parent 90e0d6d commit a60708f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
16 changes: 11 additions & 5 deletions examples/terraform-submodules/gke/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


// Run:
// terraform apply -var project="<YOUR_GCP_ProjectID>" [-var agones_version="1.4.0"]
// terraform apply -var project="<YOUR_GCP_ProjectID>" [-var agones_version="1.8.0"]

provider "google" {
version = "~> 2.10"
Expand Down Expand Up @@ -56,6 +56,11 @@ variable "network" {
description = "The name of the VPC network to attach the cluster and firewall rule to"
}

variable "subnetwork" {
default = ""
description = "The subnetwork to host the cluster in. Required field if network value isn't 'default'."
}

variable "log_level" {
default = "info"
}
Expand All @@ -66,8 +71,8 @@ variable "feature_gates" {

module "gke_cluster" {
// ***************************************************************************************************
// Update ?ref= to the agones release you are installing. For example, ?ref=release-1.3.0 corresponds
// to Agones version 1.3.0
// Update ?ref= to the agones release you are installing. For example, ?ref=release-1.8.0 corresponds
// to Agones version 1.8.0
// ***************************************************************************************************
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=master"

Expand All @@ -78,13 +83,14 @@ module "gke_cluster" {
"initialNodeCount" = var.node_count
"project" = var.project
"network" = var.network
"subnetwork" = var.subnetwork
}
}

module "helm_agones" {
// ***************************************************************************************************
// Update ?ref= to the agones release you are installing. For example, ?ref=release-1.3.0 corresponds
// to Agones version 1.3.0
// Update ?ref= to the agones release you are installing. For example, ?ref=release-1.8.0 corresponds
// to Agones version 1.8.0
// ***************************************************************************************************
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/helm3/?ref=master"

Expand Down
25 changes: 23 additions & 2 deletions site/content/en/docs/Installation/Terraform/gke.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Configurable parameters:
- zone - the name of the [zone](https://cloud.google.com/compute/docs/regions-zones) you want your cluster to be
created in (default is "us-west1-c")
- network - the name of the VPC network you want your cluster and firewall rules to be connected to (default is "default")
{{% feature publishVersion="1.9.0" %}}
- subnetwork - the name of the subnetwork in which the cluster's instances are launched. (required when using non default network)
{{% /feature %}}
- 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"
- gameserver_minPort - the lower bound of the port range which gameservers will listen on (default is "7000")
Expand Down Expand Up @@ -118,12 +121,30 @@ Next, make sure that you can authenticate using gcloud:
```
gcloud auth application-default login
```

{{% feature expiryVersion="1.9.0" %}}
Now you can create your GKE cluster (optionally specifying the version of Agones you want to use):
```
terraform apply -var project="<YOUR_GCP_ProjectID>" [-var agones_version="1.0.0"]
terraform apply -var project="<YOUR_GCP_ProjectID>"
```
{{% /feature %}}
{{% feature publishVersion="1.9.0" %}}
#### Option 1: Creating the cluster in the default VPC
To create your GKE cluster in the default VPC just specify the project variable.
```
terraform apply -var project="<YOUR_GCP_ProjectID>"
```
#### Option 2: Creating the cluster in a custom VPC
To create the cluster in a custom VPC you must specify the project, network and subnetwork variables.
```
terraform apply -var project="<YOUR_GCP_ProjectID>" -var network="<YOUR_NETWORK_NAME>" -var subnetwork="<YOUR_SUBNETWORK_NAME>"
```
{{% /feature %}}
To verify that the cluster was created successfully, set up your kubectl credentials:
```
gcloud container clusters get-credentials --zone us-west1-c agones-terraform-example
Expand Down

0 comments on commit a60708f

Please sign in to comment.