Skip to content

Commit 66e24cf

Browse files
committed
Add terraform configurations for single-cluster ref arch
1 parent 3646ecc commit 66e24cf

File tree

18 files changed

+726
-25
lines changed

18 files changed

+726
-25
lines changed

install/infra/modules/gke/main.tf

+37-10
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ provider "google" {
1717
}
1818

1919
resource "google_compute_network" "vpc" {
20-
name = "vpc-${var.name}"
20+
name = "vpc-${var.cluster_name}"
2121
auto_create_subnetworks = "false"
2222
}
2323

2424
resource "google_compute_subnetwork" "subnet" {
25-
name = "subnet-${var.name}"
25+
name = "subnet-${var.cluster_name}"
2626
region = var.region
2727
network = google_compute_network.vpc.name
2828
ip_cidr_range = "10.255.0.0/16"
@@ -39,7 +39,7 @@ resource "google_compute_subnetwork" "subnet" {
3939
}
4040

4141
resource "google_container_cluster" "gitpod-cluster" {
42-
name = "gitpod-${var.name}"
42+
name = var.cluster_name
4343
location = var.zone == null ? var.region : var.zone
4444

4545
cluster_autoscaling {
@@ -112,7 +112,7 @@ resource "google_container_cluster" "gitpod-cluster" {
112112
}
113113

114114
resource "google_container_node_pool" "workspaces" {
115-
name = "workspaces-${var.name}"
115+
name = "workspaces-${var.cluster_name}"
116116
location = google_container_cluster.gitpod-cluster.location
117117
cluster = google_container_cluster.gitpod-cluster.name
118118
version = var.cluster_version // kubernetes version
@@ -153,7 +153,8 @@ resource "google_container_node_pool" "workspaces" {
153153
}
154154

155155
resource "google_sql_database_instance" "gitpod" {
156-
name = "sql-${var.name}"
156+
count = var.enable_external_database ? 1 : 0
157+
name = "sql-${var.cluster_name}"
157158
database_version = "MYSQL_5_7"
158159
region = var.region
159160
settings {
@@ -162,17 +163,43 @@ resource "google_sql_database_instance" "gitpod" {
162163
deletion_protection = false
163164
}
164165

166+
resource "random_password" "password" {
167+
count = var.enable_external_database ? 1 : 0
168+
169+
length = 16
170+
special = true
171+
override_special = "!#$%&*()-_=+[]{}<>:?"
172+
}
173+
165174
resource "google_sql_database" "database" {
175+
count = var.enable_external_database ? 1 : 0
166176
name = "gitpod"
167-
instance = google_sql_database_instance.gitpod.name
177+
instance = google_sql_database_instance.gitpod[count.index].name
168178
charset = "utf8"
169179
collation = "utf8_general_ci"
170180
}
171181

172182
resource "google_sql_user" "users" {
173-
name = "gitpod"
174-
instance = google_sql_database_instance.gitpod.name
175-
password = "gitpod"
183+
count = var.enable_external_database ? 1 : 0
184+
name = "dbuser-${var.cluster_name}-${count.index}"
185+
instance = google_sql_database_instance.gitpod[count.index].name
186+
password = random_password.password[count.index].result
187+
}
188+
189+
resource "google_dns_managed_zone" "gitpod-dns-zone" {
190+
count = var.domain_name == null ? 0 : 1
191+
192+
name = "zone-${var.cluster_name}"
193+
dns_name = "${var.domain_name}."
194+
description = "Terraform managed DNS zone for ${var.cluster_name}"
195+
force_destroy = true
196+
labels = {
197+
app = "gitpod"
198+
}
199+
}
200+
201+
data "google_container_registry_repository" "gitpod" {
202+
count = var.enable_external_registry ? 1 : 0
176203
}
177204

178205
module "gke_auth" {
@@ -182,7 +209,7 @@ module "gke_auth" {
182209

183210
project_id = var.project
184211
location = google_container_cluster.gitpod-cluster.location
185-
cluster_name = "gitpod-${var.name}"
212+
cluster_name = var.cluster_name
186213
}
187214

188215
resource "local_file" "kubeconfig" {

install/infra/modules/gke/output.tf

+33
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ output "kubernetes_endpoint" {
33
value = module.gke_auth.host
44
}
55

6+
output "name_servers" {
7+
value = google_dns_managed_zone.gitpod-dns-zone[0].name_servers
8+
}
9+
610
output "client_token" {
711
sensitive = true
812
value = module.gke_auth.token
@@ -17,3 +21,32 @@ output "kubeconfig" {
1721
sensitive = true
1822
value = module.gke_auth.kubeconfig_raw
1923
}
24+
25+
output "database" {
26+
sensitive = true
27+
value = try({
28+
instance = "${var.project}:${var.region}:${google_sql_database_instance.gitpod[0].name}"
29+
username = "${google_sql_user.users[0].name}"
30+
password = random_password.password[0].result
31+
service_account_key = "Upload the JSON file corresponding the service account credentials"
32+
}, "No database created")
33+
}
34+
35+
output "registry" {
36+
sensitive = true
37+
value = try({
38+
url = data.google_container_registry_repository.gitpod[0].repository_url
39+
server = regex("[^/?#]*", data.google_container_registry_repository.gitpod[0].repository_url)
40+
username = "_json_key"
41+
password = "Copy paste the content of the service account credentials JSON file"
42+
}, "No container registry created")
43+
}
44+
45+
output "storage" {
46+
sensitive = true
47+
value = try({
48+
region = var.region
49+
project = var.project
50+
credentials = "Upload the JSON file corresponding the service account credentials"
51+
}, "No GCS bucket created for object storage")
52+
}

install/infra/modules/gke/variables.tf

+21-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ variable "cluster_version" {
2626
default = "1.22.8-gke.201"
2727
}
2828

29-
variable "name" {
29+
variable "cluster_name" {
3030
type = string
3131
description = "The name of the cluster."
3232
default = "gitpod"
@@ -60,3 +60,23 @@ variable "credentials" {
6060
description = "Path to the JSON file storing Google service account credentials"
6161
default = ""
6262
}
63+
64+
variable "domain_name" {
65+
description = "Domain name register with Cloud DNS, leave empty if you want to manage it yourself"
66+
default = null
67+
}
68+
69+
variable "enable_external_database" {
70+
default = true
71+
description = "Set this to false to avoid creating an RDS database to use with Gitpod instead of incluster mysql"
72+
}
73+
74+
variable "enable_external_storage" {
75+
default = true
76+
description = "Set this to false to avoid creating an s3 storage to use with Gitpod instead of incluster minio"
77+
}
78+
79+
variable "enable_external_registry" {
80+
default = true
81+
description = "Set this to false to create an AWS ECR registry to use with Gitpod(Not officially supported)"
82+
}

install/infra/modules/tools/cloud-dns-external-dns/main.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ data local_file "gcp_credentials" {
88

99
provider "google" {
1010
credentials = var.credentials
11-
project = var.gcp_project
12-
region = var.gcp_region
13-
zone = var.gcp_zone
11+
project = var.project
12+
region = var.region
13+
zone = var.zone
1414
}
1515

1616
provider "helm" {
@@ -57,7 +57,7 @@ resource "helm_release" "external-dns" {
5757
}
5858
set {
5959
name = "google.project"
60-
value = var.gcp_project
60+
value = var.project
6161
}
6262
set {
6363
name = "logFormat"

install/infra/modules/tools/cloud-dns-external-dns/variables.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ variable "kubeconfig" {
33
default = "./kubeconfig"
44
}
55

6-
variable "gcp_project" {
6+
variable "project" {
77
description = "Google cloud Region to perform operations in"
88
default = "dns-for-playgrounds"
99
}
1010

11-
variable "gcp_region" {
11+
variable "region" {
1212
description = "Google cloud Region to perform operations in"
1313
default = "europe-west1"
1414
}
1515

16-
variable "gcp_zone" {
16+
variable "zone" {
1717
description = "Google cloud Zone to perform operations in"
1818
default = "europe-west1-d"
1919
}

install/infra/single-cluster/aws/README.md

-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ This module will do the following steps:
1414

1515
> 💡 If you would like to create the infrastructure orchestrating the terraform modules by yourself, you can find all the modules we support [here](../../modules/).
1616
17-
1817
Since the entire setup requires more than one terraform target to be run due to
1918
dependencies (eg: helm provider depends on kubernetes cluster config, which is
2019
not available until the `eks` module finishes), this directory has a `Makefile`
@@ -79,9 +78,6 @@ be used as registry backend. By default `enable_external_storage_for_registry_ba
7978
is set to `false`. One can re-use the same `S3` bucket for both object storage and registry backend.
8079
8180
The expectation is that you can use the credentials to these setups(provided later
82-
as terraform outputs) during the setup of Gitpod via UI later in the process.
83-
Alternatively, one can choose to use incluster dependencies or separately
84-
created resources of choice.
8581
8682
### AMI Image ID and Kubernetes version
8783

install/infra/single-cluster/aws/terraform.tfvars

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# the cluster_name should be of length less than 16 characters
32
cluster_name = "nan"
43

install/infra/single-cluster/gcp/.terraform.lock.hcl

+97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)