Skip to content

Commit

Permalink
Terraform template file for the performance test cluster (#3409)
Browse files Browse the repository at this point in the history
  • Loading branch information
gongmax authored Oct 3, 2023
1 parent 4060911 commit e3c0520
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 2 deletions.
12 changes: 10 additions & 2 deletions build/terraform/e2e/gke-standard/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ variable "kubernetesVersion" {}
variable "location" {}
variable "releaseChannel" {}

variable "machineType" {
default = "e2-standard-4"
}

variable "initialNodeCount" {
default = 10
}

variable "overrideName" {
default = ""
}
Expand All @@ -46,8 +54,8 @@ module "gke_cluster" {
"name" = var.overrideName != "" ? var.overrideName : format("standard-e2e-test-cluster-%s", replace(var.kubernetesVersion, ".", "-"))
"location" = var.location
"releaseChannel" = var.releaseChannel
"machineType" = "e2-standard-4"
"initialNodeCount" = 10
"machineType" = var.machineType
"initialNodeCount" = var.initialNodeCount
"enableImageStreaming" = true
"project" = var.project
"kubernetesVersion" = var.kubernetesVersion
Expand Down
86 changes: 86 additions & 0 deletions build/terraform/performance/module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2023 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


// Run:
// terraform init -backend-config="bucket=<YOUR_GCP_ProjectID>-performance-infra-bucket-tfstate" -backend-config="prefix=terraform/state"
// terraform apply -var project="<YOUR_GCP_ProjectID>"
// The performance test cluster is hosted in project `agones-e2e-1`, i.e:
// terraform init -backend-config="bucket=agones-e2e-1-performance-infra-bucket-tfstate" -backend-config="prefix=terraform/state"
// terraform apply -var project="agones-e2e-1"

terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.25.0"
}
helm = {
source = "hashicorp/helm"
version = "~> 2.3"
}
}
backend "gcs" {
}
}

variable "project" {}
variable "kubernetes_versions" {
description = "Create performance test clusters with these k8s versions in these regions"
type = map(list(string))
default = {
"1.26" = ["us-central1", "REGULAR"]
}
}

module "gke_standard_cluster" {
for_each = var.kubernetes_versions
source = "../e2e/gke-standard"
project = var.project
kubernetesVersion = each.key
location = each.value[0]
overrideName = format("standard-performance-test-cluster-%s", replace(each.key, ".", "-"))
releaseChannel = each.value[1]
machineType = "n2-standard-2"
initialNodeCount = 300
}

resource "google_compute_firewall" "udp" {
name = "gke-game-server-firewall"
project = var.project
network = "default"

allow {
protocol = "udp"
ports = ["7000-8000"]
}

target_tags = ["game-server"]
source_ranges = ["0.0.0.0/0"]
}

resource "google_compute_firewall" "tcp" {
name = "gke-game-server-firewall-tcp"
project = var.project
network = "default"

allow {
protocol = "tcp"
ports = ["7000-8000"]
}

target_tags = ["game-server"]
source_ranges = ["0.0.0.0/0"]
}
46 changes: 46 additions & 0 deletions build/terraform/performance/state-bucket/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2023 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


// Run:
// terraform apply -var project="<YOUR_GCP_ProjectID>"

// The performance test cluster is hosted in project `agones-e2e-1`, i.e:
// terraform apply -var project="agones-e2e-1"

// # GCS bucket for holding the Terraform state of the performance test Terraform config.

terraform {
required_version = ">= 1.0.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.25.0"
}
}
}

variable "project" {}

resource "google_storage_bucket" "default" {
project = var.project
name = "${var.project}-performance-infra-bucket-tfstate"
force_destroy = false
uniform_bucket_level_access = true
location = "US"
storage_class = "STANDARD"
versioning {
enabled = true
}
}
3 changes: 3 additions & 0 deletions install/terraform/modules/gke/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ resource "google_container_cluster" "primary" {
network = local.network
subnetwork = local.subnetwork

networking_mode = "VPC_NATIVE"
ip_allocation_policy {}

release_channel {
channel = local.releaseChannel
}
Expand Down

0 comments on commit e3c0520

Please sign in to comment.