-
Notifications
You must be signed in to change notification settings - Fork 16
/
agones-gke.tf
124 lines (98 loc) · 3.82 KB
/
agones-gke.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2023 Google LLC
//
// 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
//
// https://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.
##------------------------------##
## Google Terraform: Agones GKE ##
##------------------------------##
data "google_container_engine_versions" "regions" {
for_each = merge(var.game_gke_standard_clusters, var.game_gke_autopilot_clusters)
location = each.value.region
}
module "agones_gke_standard_clusters" {
for_each = var.game_gke_standard_clusters
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=v1.45.0"
cluster = {
name = each.key
location = each.value.region
project = var.project
autoscale = true
workloadIdentity = true
machineType = each.value.machine_type
# Install Current GKE default version
kubernetesVersion = data.google_container_engine_versions.regions[each.key].default_cluster_version
network = google_compute_network.vpc.id
subnetwork = "global-game-${each.value.region}-subnet"
}
udpFirewall = false
depends_on = [google_compute_subnetwork.subnet, google_project_service.project]
}
module "agones_gke_autopilot_clusters" {
for_each = var.game_gke_autopilot_clusters
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke-autopilot/?ref=v1.45.0"
cluster = {
name = each.key
location = each.value.region
project = var.project
# Install Current GKE default version
kubernetesVersion = data.google_container_engine_versions.regions[each.key].default_cluster_version
network = google_compute_network.vpc.id
subnetwork = "global-game-${each.value.region}-subnet"
}
udpFirewall = false
depends_on = [google_compute_subnetwork.subnet, google_project_service.project]
}
data "google_container_cluster" "game-demo-agones" {
for_each = merge(var.game_gke_standard_clusters, var.game_gke_autopilot_clusters)
name = each.key
location = each.value.region
depends_on = [module.agones_gke_standard_clusters, module.agones_gke_autopilot_clusters]
}
resource "google_gke_hub_membership" "membership" {
for_each = merge(var.game_gke_standard_clusters, var.game_gke_autopilot_clusters)
provider = google-beta
project = var.project
membership_id = "${each.key}-membership"
endpoint {
gke_cluster {
resource_link = "//container.googleapis.com/${data.google_container_cluster.game-demo-agones[each.key].id}"
}
}
depends_on = [google_project_service.project]
}
resource "google_gke_hub_feature" "servicemesh" {
project = var.project
name = "servicemesh"
location = "global"
depends_on = [google_project_service.project]
}
resource "google_gke_hub_feature_membership" "mesh-member" {
for_each = merge(var.game_gke_standard_clusters, var.game_gke_autopilot_clusters)
project = var.project
location = "global"
feature = google_gke_hub_feature.servicemesh.name
membership = google_gke_hub_membership.membership[each.key].membership_id
mesh {
management = "MANAGEMENT_AUTOMATIC"
}
}
resource "google_compute_firewall" "agones-gameservers" {
name = "agones-gameservers"
project = var.project
network = google_compute_network.vpc.id
allow {
protocol = "udp"
ports = ["7000-8000"]
}
target_tags = ["game-server"]
source_ranges = ["0.0.0.0/0"]
}