-
Notifications
You must be signed in to change notification settings - Fork 4
/
module.tf
193 lines (162 loc) · 4.86 KB
/
module.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.63"
}
helm = {
version = "~> 2.3"
source = "hashicorp/helm"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.6.1"
}
}
}
variable "agones_version" {
default = "1.28.0"
}
variable "cluster_name" {
default = "muddle-run"
}
variable "region" {
default = "eu-central-1"
}
variable "region_account" {
// https://docs.aws.amazon.com/eks/latest/userguide/add-ons-images.html
default = 602401143452
}
variable "hosted_zone_name" {
type = string
default = ""
}
variable "record_name" {
type = string
default = ""
}
variable "sentry_dsn_server" {
type = string
default = ""
sensitive = true
}
variable "sentry_dsn_matchmaker" {
type = string
default = ""
sensitive = true
}
variable "sentry_dsn_persistence" {
type = string
default = ""
sensitive = true
}
variable "persistence_db_password" {
type = string
sensitive = true
}
provider "aws" {
profile = "default"
region = var.region
}
data "aws_eks_cluster" "current" {
name = var.cluster_name
depends_on = [module.eks_cluster]
}
data "aws_eks_cluster_auth" "current" {
name = var.cluster_name
depends_on = [module.eks_cluster]
}
provider "helm" {
kubernetes {
host = data.aws_eks_cluster.current.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.current.certificate_authority[0].data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
}
provider "kubernetes" {
host = data.aws_eks_cluster.current.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.current.certificate_authority[0].data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
resource "kubernetes_secret" "sentry_dsn" {
metadata {
name = "sentry-dsn"
}
data = {
server = var.sentry_dsn_server
matchmaker = var.sentry_dsn_matchmaker
persistence = var.sentry_dsn_persistence
}
}
variable "log_level" {
default = "info"
}
module "eks_cluster" {
source = "./k8s/eks_cluster"
cluster_name = var.cluster_name
}
module "aws_load_balancer_controller" {
source = "./k8s/aws_load_balancer_controller"
cluster_name = var.cluster_name
region_account = var.region_account
depends_on = [data.aws_eks_cluster_auth.current]
}
module "aws_autoscaler" {
source = "./k8s/aws_autoscaler"
cluster_name = var.cluster_name
depends_on = [module.eks_cluster]
}
module "persistence" {
source = "./k8s/persistence"
depends_on = [module.aws_load_balancer_controller, module.helm_agones, kubernetes_secret.sentry_dsn]
persistence_db_password = var.persistence_db_password
vpc_id = module.eks_cluster.vpc_id
vpc_public_subnets = module.eks_cluster.vpc_public_subnets
worker_group_mgmt_one_sg_id = module.eks_cluster.worker_group_mgmt_one_sg_id
}
module "matchmaker" {
source = "./k8s/matchmaker"
depends_on = [module.aws_load_balancer_controller, module.helm_agones, kubernetes_secret.sentry_dsn]
}
module "web_client" {
source = "./k8s/web_client"
depends_on = [module.aws_load_balancer_controller]
}
module "service" {
source = "./k8s/service"
depends_on = [module.matchmaker, module.persistence, module.web_client]
}
module "route53" {
source = "./k8s/route53"
depends_on = [module.service]
count = min(length(var.hosted_zone_name), 1)
hosted_zone_name = var.hosted_zone_name
record_name = var.record_name
}
# Comment this out if running for the first time (i.e. when `helm_agones` is not installed).
module "agones" {
source = "./k8s/agones"
depends_on = [module.eks_cluster, module.helm_agones, kubernetes_secret.sentry_dsn]
}
// Next Helm module cause "terraform destroy" timeout, unless helm release would be deleted first.
// Therefore "helm delete --purge agones" should be executed from the CLI before executing "terraform destroy".
module "helm_agones" {
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/helm3/?ref=main"
udp_expose = "false"
agones_version = var.agones_version
values_file = ""
feature_gates = "PlayerTracking=true&StateAllocationFilter=true&PlayerAllocationFilter=true"
host = data.aws_eks_cluster.current.endpoint
token = data.aws_eks_cluster_auth.current.token
cluster_ca_certificate = base64decode(data.aws_eks_cluster.current.certificate_authority[0].data)
log_level = var.log_level
}