forked from GoogleCloudPlatform/gke-cloud-sql-postgres-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.sh
executable file
·95 lines (78 loc) · 2.45 KB
/
create.sh
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
#!/bin/bash -e
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script will build all the GCP resources in this demo
# The resources include a GKE cluster, a Cloud SQL instance, and
# some accompanying service accounts
help() {
echo "./create.sh POSTGRES_USERNAME PGADMIN_USERNAME"
echo "Passwords will be entered via prompts"
}
ROOT=$(dirname "${BASH_SOURCE[0]}")
RANDOM_SUFFIX=$(tr -dc 'a-z0-9' </dev/urandom | fold -w 6 | head -n 1)
export INSTANCE_NAME=demo-postgres-${RANDOM_SUFFIX}
echo "$INSTANCE_NAME" > "${ROOT}"/.instance
if [ -z "$INSTANCE_NAME" ] ; then
help
exit 1
fi
export USER_NAME=$1
if [ -z "$USER_NAME" ] ; then
help
exit 1
fi
export PG_ADMIN_CONSOLE_EMAIL=$2
if [ -z "$PG_ADMIN_CONSOLE_EMAIL" ]; then
help
exit 1
fi
CLUSTER_ZONE=$(gcloud config get-value compute/zone)
INSTANCE_REGION=$(gcloud config get-value compute/region)
export CLUSTER_ZONE
if [ -z "$CLUSTER_ZONE" ]; then
echo "Make sure that compute/zone is set in gcloud config"
exit 1
fi
export INSTANCE_REGION
if [ -z "$INSTANCE_REGION" ]; then
echo "Make sure that compute/region is set in gcloud config"
exit 1
fi
if [ -z "$USER_PASSWORD" ]; then
echo "Enter a password for $USER_NAME"
read -r USER_PASSWORD
export USER_PASSWORD=$USER_PASSWORD
fi
if [ -z "$USER_PASSWORD" ] ; then
echo "Password can't be blank or whitespace"
exit 1
fi
if [ -z "$PG_ADMIN_CONSOLE_PASSWORD" ]; then
echo "Enter a password for $PG_ADMIN_CONSOLE_EMAIL"
read -r PG_ADMIN_CONSOLE_PASSWORD
export PG_ADMIN_CONSOLE_PASSWORD=$PG_ADMIN_CONSOLE_PASSWORD
fi
if [ -z "$PG_ADMIN_CONSOLE_PASSWORD" ] ; then
echo "Password can't be blank or whitespace"
exit 1
fi
ROOT=$(dirname "${BASH_SOURCE[0]}")
if "$ROOT"/scripts/prerequisites.sh; then
"$ROOT"/scripts/enable_apis.sh
"$ROOT"/scripts/postgres_instance.sh
"$ROOT"/scripts/service_account.sh
"$ROOT"/scripts/cluster.sh
"$ROOT"/scripts/configs_and_secrets.sh
"$ROOT"/scripts/pgadmin_deployment.sh
fi