Skip to content

Commit 437ea8b

Browse files
committed
[installer-tests] Fix GCP database config
1 parent 284c109 commit 437ea8b

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

install/infra/modules/gke/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ resource "google_sql_database" "database" {
181181

182182
resource "google_sql_user" "users" {
183183
count = var.enable_external_database ? 1 : 0
184-
name = "dbuser-${var.cluster_name}-${count.index}"
184+
name = "gitpod"
185185
instance = google_sql_database_instance.gitpod[count.index].name
186186
password = random_password.password[count.index].result
187187
}

install/infra/modules/k3s/main.tf

+8-1
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,17 @@ resource "google_sql_database" "database" {
189189
collation = "utf8_general_ci"
190190
}
191191

192+
resource "random_password" "password" {
193+
194+
length = 16
195+
special = true
196+
override_special = "!#$%&*()-_=+[]{}<>:?"
197+
}
198+
192199
resource "google_sql_user" "users" {
193200
name = "gitpod"
194201
instance = google_sql_database_instance.gitpod.name
195-
password = "gitpod"
202+
password = random_password.password.result
196203
}
197204

198205
data "local_file" "kubeconfig" {

install/infra/modules/k3s/output.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "database" {
2+
sensitive = true
3+
value = try({
4+
instance = "${var.gcp_project}:${var.gcp_region}:${google_sql_database_instance.gitpod.name}"
5+
username = "${google_sql_user.users.name}"
6+
password = random_password.password.result
7+
service_account_key = "Upload the JSON file corresponding the service account credentials"
8+
}, "No database created")
9+
}

install/tests/Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ ami_id_121 := "ami-0d57fb01036fac543"
8080

8181
ami_id_122 := "ami-0b306cb7e98db98e4"
8282

83+
DOT:= .
84+
EMPTY:=
85+
8386
.PHONY:
8487
## eks-standard-cluster: Creates an EKS cluster
85-
eks-standard-cluster: ami_id = $(if $(ami_id_${TF_VAR_cluster_version//.}),$(ami_id_${TF_VAR_cluster_version//.}),$(ami_id_122))
88+
eks-standard-cluster: ami_id = $(if $(ami_id_$(subst $(DOT),$(EMPTY),$(TF_VAR_cluster_version))),$(ami_id_$(subst $(DOT),$(EMPTY),$(TF_VAR_cluster_version))),$(ami_id_122))
8689
eks-standard-cluster: check-env-cluster-version
8790
terraform init --upgrade && \
8891
terraform workspace new $(TF_VAR_TEST_ID) || $(MAKE) select-workspace && \
@@ -186,6 +189,10 @@ registry-config-gcp:
186189

187190
db-config-gcp:
188191
export BASE64_GCP_KEY=$$(cat $$TF_VAR_sa_creds | tr -d '\n' | base64 -w 0) && \
192+
export DB_OUTPUT=$$(terraform output -json k3s_database || terraform output -json gke_database) && \
193+
export DB_INSTANCE=$$(echo $$DB_OUTPUT | yq r - 'instance') && \
194+
export DB_PASSWORD=$$(echo $$DB_OUTPUT | yq r - 'password') && \
195+
export DB_USER=$$(echo $$DB_OUTPUT | yq r - 'username') && \
189196
envsubst < ./manifests/kots-config-gcp-db.yaml > tmp_4_config.yml
190197
envsubst < tmp_4_config.yml > tmp_5_config.yml
191198
yq m -i tmp_config.yml tmp_5_config.yml

install/tests/manifests/kots-config-gcp-db.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ spec:
99
value: "1"
1010
data: "db_cloudsql_enabled"
1111
db_cloudsql_instance:
12-
value: sh-automated-tests:europe-west1:sql-${TF_VAR_TEST_ID}
12+
value: "${DB_INSTANCE}"
1313
data: "db_cloudsql_instance"
1414
db_gcp_credentials:
1515
value: "${BASE64_GCP_KEY}"
16-
data: "db_cloudsql_credentials"
17-
db_gcp_username:
18-
value: gitpod
16+
data: "db_gcp_credentials"
17+
db_username:
18+
value: ${DB_USER}
1919
data: "db_username"
2020
db_password:
21-
value: gitpod
21+
value: ${DB_PASSWORD}
2222
data: "db_password"

install/tests/output.tf

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
output "gke_database" {
2+
sensitive = true
3+
value = try(module.gke.database, null)
4+
}
5+
6+
output "k3s_database" {
7+
sensitive = true
8+
value = try(module.k3s.database, null)
9+
}
10+
111
output "aws_storage" {
212
sensitive = true
313
value = try(module.eks.storage, null)

0 commit comments

Comments
 (0)