agones.dev/agones@v1.54.0/install/terraform/modules/gke-autopilot/cluster.tf (about)

     1  # Copyright 2023 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  terraform {
    17    required_version = ">= 1.0.0"
    18  }
    19  
    20  data "google_client_config" "default" {}
    21  
    22  # A list of all parameters used in interpolation var.cluster
    23  # Set values to default if not key was not set in original map
    24  locals {
    25    name                          = lookup(var.cluster, "name", "test-cluster")
    26    project                       = lookup(var.cluster, "project", "agones")
    27    location                      = lookup(var.cluster, "location", "us-west1")
    28    network                       = lookup(var.cluster, "network", "default")
    29    subnetwork                    = lookup(var.cluster, "subnetwork", "")
    30    releaseChannel                = lookup(var.cluster, "releaseChannel", "REGULAR")
    31    kubernetesVersion             = lookup(var.cluster, "kubernetesVersion", "1.33")
    32    maintenanceExclusionStartTime = lookup(var.cluster, "maintenanceExclusionStartTime", null)
    33    maintenanceExclusionEndTime   = lookup(var.cluster, "maintenanceExclusionEndTime", null)
    34    deletionProtection            = lookup(var.cluster, "deletionProtection", true)
    35  }
    36  
    37  # echo command used for debugging purpose
    38  # Run `terraform taint null_resource.test-setting-variables` before second execution
    39  resource "null_resource" "test-setting-variables" {
    40    provisioner "local-exec" {
    41      command = <<EOT
    42      ${format("echo Current variables set as following - name: %s, project: %s, location: %s, network: %s, subnetwork: %s, releaseChannel: %s, kubernetesVersion: %s",
    43      local.name,
    44      local.project,
    45      local.location,
    46      local.network,
    47      local.subnetwork,
    48      local.releaseChannel,
    49      local.kubernetesVersion,
    50  )}
    51      EOT
    52  }
    53  }
    54  
    55  resource "google_container_cluster" "primary" {
    56    provider = google-beta # required for node_pool_auto_config.network_tags
    57  
    58    name                = local.name
    59    project             = local.project
    60    location            = local.location
    61    network             = local.network
    62    subnetwork          = local.subnetwork
    63    deletion_protection = local.deletionProtection
    64  
    65    release_channel {
    66      channel = local.releaseChannel != "" ? local.releaseChannel : "UNSPECIFIED"
    67    }
    68    min_master_version = local.kubernetesVersion
    69  
    70    dynamic "maintenance_policy" {
    71      for_each = (local.releaseChannel != "UNSPECIFIED" && local.maintenanceExclusionStartTime != null && local.maintenanceExclusionEndTime != null) ? [1] : []
    72      content {
    73        # When exclusions and maintenance windows overlap, exclusions have precedence.
    74        daily_maintenance_window {
    75          start_time = "03:00"
    76        }
    77        maintenance_exclusion {
    78          exclusion_name = format("%s-%s", local.name, "exclusion")
    79          start_time     = local.maintenanceExclusionStartTime
    80          end_time       = local.maintenanceExclusionEndTime
    81          exclusion_options {
    82            scope = "NO_MINOR_UPGRADES"
    83          }
    84        }
    85      }
    86    }
    87  
    88    enable_autopilot = true
    89    ip_allocation_policy {} # https://github.com/hashicorp/terraform-provider-google/issues/10782#issuecomment-1024488630
    90  
    91    node_pool_auto_config {
    92      network_tags {
    93        tags = ["game-server"]
    94      }
    95    }
    96  
    97    dns_config {
    98      cluster_dns        = "CLOUD_DNS"
    99      cluster_dns_domain = "cluster.local"
   100      cluster_dns_scope  = "CLUSTER_SCOPE"
   101    }
   102  
   103    timeouts {
   104      create = "40m"
   105      update = "60m"
   106    }
   107  }
   108  
   109  resource "google_compute_firewall" "default" {
   110    count   = var.udpFirewall ? 1 : 0
   111    name    = length(var.firewallName) == 0 ? "game-server-firewall-${local.name}" : var.firewallName
   112    project = local.project
   113    network = local.network
   114  
   115    allow {
   116      protocol = "udp"
   117      ports    = [var.ports]
   118    }
   119  
   120    target_tags   = ["game-server"]
   121    source_ranges = [var.sourceRanges]
   122  }