Skip to content

Commit

Permalink
[installer-tests] Fix GCP database config
Browse files Browse the repository at this point in the history
  • Loading branch information
nandajavarma committed Aug 26, 2022
1 parent 0fc1903 commit cade635
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
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

0 comments on commit cade635

Please sign in to comment.