agones.dev/agones@v1.53.0/build/terraform/e2e/module.tf (about)

     1  // Copyright 2020 Google LLC All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  
    16  // Run:
    17  //  terraform init -backend-config="bucket=<YOUR_GCP_ProjectID>-e2e-infra-bucket-tfstate" -backend-config="prefix=terraform/state"
    18  //  terraform apply -var project="<YOUR_GCP_ProjectID>"
    19  
    20  terraform {
    21    required_version = ">= 1.0.0"
    22    required_providers {
    23      google = {
    24        source = "hashicorp/google"
    25        version = "~> 4.25.0"
    26      }
    27      helm = {
    28        source = "hashicorp/helm"
    29        version = "~> 2.3"
    30      }
    31    }
    32    backend "gcs" {
    33    }
    34  }
    35  
    36  variable "project" {}
    37  variable "kubernetes_versions" {
    38    description = "Create e2e test clusters with these k8s versions in these regions"
    39    type        = map(list(string))
    40    default     = {
    41      "1.31" = ["us-east1", "RAPID"]
    42      "1.32" = ["us-west1", "RAPID"]
    43      "1.33" = ["asia-east1", "RAPID"]
    44  
    45      # "1.34" = ["europe-west1", "RAPID"]
    46      //
    47      // Before merge: When adding Kubernetes version 1.{N}, first uncomment the line above, extending
    48      // the infrastructure to 4 versions temporarily. Come back to these instructions after the
    49      // update PR merges.
    50      //
    51      // After merge: After the Kubernetes update PR merges, and all active PRs are updated:
    52      //
    53      // * Move the 1.{N-3} line to the bottom and comment it out
    54      // * Change the (commented out) 1.{N-3} to 1.{N+1}
    55      // * You should now have 3 versions uncommented (versions 1.{N-2} .. 1.{N}),
    56      //   and 1.{N+1} commented out for the next update. The new, commented out 1.{N+1}
    57      //   should be using the region of the previous 1.{N-3} - this region will become
    58      //   unused.
    59      //
    60      // Rationale: We cycle the regions us-east1 -> us-west1 -> asia-east1 -> europe-west1 -> us-east1
    61      // as versions are added, using 4 regions so that the PR adding 1.{N} is in a unique region to
    62      // 1.{N-3} .. 1.{N-1}, meaning versions never need to share a region in CI.
    63    }
    64  }
    65  
    66  module "gke_standard_cluster" {
    67    for_each = var.kubernetes_versions
    68    source = "./gke-standard"
    69    project = var.project
    70    kubernetesVersion = each.key
    71    location = each.value[0]
    72    releaseChannel = each.value[1]
    73  }
    74  
    75  module "gke_autopilot_cluster" {
    76    for_each = var.kubernetes_versions
    77    source = "./gke-autopilot"
    78    project = var.project
    79    kubernetesVersion = each.key
    80    location = each.value[0]
    81    releaseChannel = each.value[1]
    82  }
    83  
    84  resource "google_compute_firewall" "udp" {
    85    name    = "gke-game-server-firewall"
    86    project = var.project
    87    network = "default"
    88  
    89    allow {
    90      protocol = "udp"
    91      ports    = ["7000-8000"]
    92    }
    93  
    94    target_tags = ["game-server"]
    95    source_ranges = ["0.0.0.0/0"]
    96  }
    97  
    98  resource "google_compute_firewall" "tcp" {
    99    name    = "gke-game-server-firewall-tcp"
   100    project = var.project
   101    network = "default"
   102  
   103    allow {
   104      protocol = "tcp"
   105      ports    = ["7000-8000"]
   106    }
   107  
   108    target_tags = ["game-server"]
   109    source_ranges = ["0.0.0.0/0"]
   110  }