Skip to content

[installer-tests] Fix GCP database config #12379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion install/infra/modules/gke/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ resource "google_sql_database" "database" {

resource "google_sql_user" "users" {
count = var.enable_external_database ? 1 : 0
name = "dbuser-${var.cluster_name}-${count.index}"
name = "gitpod"
instance = google_sql_database_instance.gitpod[count.index].name
password = random_password.password[count.index].result
}
Expand Down
9 changes: 8 additions & 1 deletion install/infra/modules/k3s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,17 @@ resource "google_sql_database" "database" {
collation = "utf8_general_ci"
}

resource "random_password" "password" {

length = 16
special = true
override_special = "!#$%&*()-_=+[]{}<>:?"
}

resource "google_sql_user" "users" {
name = "gitpod"
instance = google_sql_database_instance.gitpod.name
password = "gitpod"
password = random_password.password.result
}

data "local_file" "kubeconfig" {
Expand Down
9 changes: 9 additions & 0 deletions install/infra/modules/k3s/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "database" {
sensitive = true
value = try({
instance = "${var.gcp_project}:${var.gcp_region}:${google_sql_database_instance.gitpod.name}"
username = "${google_sql_user.users.name}"
password = random_password.password.result
service_account_key = "Upload the JSON file corresponding the service account credentials"
}, "No database created")
}
4 changes: 4 additions & 0 deletions install/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ registry-config-gcp:

db-config-gcp:
export BASE64_GCP_KEY=$$(cat $$TF_VAR_sa_creds | tr -d '\n' | base64 -w 0) && \
export DB_OUTPUT=$$(terraform output -json k3s_database || terraform output -json gke_database) && \
export DB_INSTANCE=$$(echo $$DB_OUTPUT | yq r - 'instance') && \
export DB_PASSWORD=$$(echo $$DB_OUTPUT | yq r - 'password') && \
export DB_USER=$$(echo $$DB_OUTPUT | yq r - 'username') && \
envsubst < ./manifests/kots-config-gcp-db.yaml > tmp_4_config.yml
envsubst < tmp_4_config.yml > tmp_5_config.yml
yq m -i tmp_config.yml tmp_5_config.yml
Expand Down
10 changes: 5 additions & 5 deletions install/tests/manifests/kots-config-gcp-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ spec:
value: "1"
data: "db_cloudsql_enabled"
db_cloudsql_instance:
value: sh-automated-tests:europe-west1:sql-${TF_VAR_TEST_ID}
value: "${DB_INSTANCE}"
data: "db_cloudsql_instance"
db_gcp_credentials:
value: "${BASE64_GCP_KEY}"
data: "db_cloudsql_credentials"
db_gcp_username:
value: gitpod
data: "db_gcp_credentials"
db_username:
value: ${DB_USER}
data: "db_username"
db_password:
value: gitpod
value: ${DB_PASSWORD}
data: "db_password"
10 changes: 10 additions & 0 deletions install/tests/output.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
output "gke_database" {
sensitive = true
value = try(module.gke.database, null)
}

output "k3s_database" {
sensitive = true
value = try(module.k3s.database, null)
}

output "aws_storage" {
sensitive = true
value = try(module.eks.storage, null)
Expand Down