agones.dev/agones@v1.54.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.32" = ["us-west1", "RAPID"]
    42      "1.33" = ["asia-east1", "RAPID"]
    43      "1.34" = ["europe-west1", "RAPID"]
    44      // "1.35" = ["us-east1", "RAPID"]
    45      //
    46      // Before merge: When adding Kubernetes version 1.{N}, first uncomment the line above, extending
    47      // the infrastructure to 4 versions temporarily. Come back to these instructions after the
    48      // update PR merges.
    49      //
    50      // After merge: After the Kubernetes update PR merges, and all active PRs are updated:
    51      //
    52      // * Move the 1.{N-3} line to the bottom and comment it out
    53      // * Change the (commented out) 1.{N-3} to 1.{N+1}
    54      // * You should now have 3 versions uncommented (versions 1.{N-2} .. 1.{N}),
    55      //   and 1.{N+1} commented out for the next update. The new, commented out 1.{N+1}
    56      //   should be using the region of the previous 1.{N-3} - this region will become
    57      //   unused.
    58      //
    59      // Rationale: We cycle the regions us-east1 -> us-west1 -> asia-east1 -> europe-west1 -> us-east1
    60      // as versions are added, using 4 regions so that the PR adding 1.{N} is in a unique region to
    61      // 1.{N-3} .. 1.{N-1}, meaning versions never need to share a region in CI.
    62    }
    63  }
    64  
    65  module "gke_standard_cluster" {
    66    for_each = var.kubernetes_versions
    67    source = "./gke-standard"
    68    project = var.project
    69    kubernetesVersion = each.key
    70    location = each.value[0]
    71    releaseChannel = each.value[1]
    72  }
    73  
    74  module "gke_autopilot_cluster" {
    75    for_each = var.kubernetes_versions
    76    source = "./gke-autopilot"
    77    project = var.project
    78    kubernetesVersion = each.key
    79    location = each.value[0]
    80    releaseChannel = each.value[1]
    81  }
    82  
    83  resource "google_compute_firewall" "udp" {
    84    name    = "gke-game-server-firewall"
    85    project = var.project
    86    network = "default"
    87  
    88    allow {
    89      protocol = "udp"
    90      ports    = ["7000-8000"]
    91    }
    92  
    93    target_tags = ["game-server"]
    94    source_ranges = ["0.0.0.0/0"]
    95  }
    96  
    97  resource "google_compute_firewall" "tcp" {
    98    name    = "gke-game-server-firewall-tcp"
    99    project = var.project
   100    network = "default"
   101  
   102    allow {
   103      protocol = "tcp"
   104      ports    = ["7000-8000"]
   105    }
   106  
   107    target_tags = ["game-server"]
   108    source_ranges = ["0.0.0.0/0"]
   109  }