-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-apply-aci-postgres.sh
83 lines (57 loc) · 1.92 KB
/
2-apply-aci-postgres.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
#!/bin/bash
set -e
cd aci-postgres
terraform init -backend-config=config.azurerm.tfbackend
terraform apply -auto-approve
terraform output -json > output.json
if ! docker info > /dev/null 2>&1; then
echo "This script uses docker, and it isn't running - please start docker and try again!"
exit 1
fi
fqdn=$(cat output.json| jq --raw-output '.aci_fqdn.value')
if [ -z $fqdn ]; then
echo "Could not find fqdn. Stopping!"
exit 1
fi
ip=$(cat output.json| jq --raw-output '.aci_ip_address.value')
if [ -z $ip ]; then
echo "Could not find ip. Stopping!"
exit 1
fi
secret_id=$(cat output.json| jq --raw-output '.pg_secret_id.value')
if [ -z $secret_id ]; then
echo "Could not find secret_id. Stopping!"
exit 1
fi
username=$(cat output.json| jq --raw-output '.pg_username.value')
if [ -z $username ]; then
echo "Could not find username. Stopping!"
exit 1
fi
instance_name=$(cat output.json| jq --raw-output '.pg_name.value')
if [ -z $instance_name ]; then
echo "Could not find name. Stopping!"
exit 1
fi
db_fqdn=$(cat output.json| jq --raw-output '.pg_fqdn.value')
if [ -z $db_fqdn ]; then
echo "Could not find fqdn. Stopping!"
exit 1
fi
db_name=$(cat output.json| jq --raw-output '.pg_db_name.value')
if [ -z $db_name ]; then
echo "Could not find fqdn. Stopping!"
exit 1
fi
password=$(az keyvault secret show --id $secret_id --query value | jq --raw-output)
# load test data
docker run -it --rm -v $PWD:/app -e PGPASSWORD="$password" bitnami/postgresql:11 psql -f /app/schema.sql -h $db_fqdn -U $username@$instance_name -d $db_name
docker run -it --rm -v $PWD:/app -e PGPASSWORD="$password" bitnami/postgresql:11 psql -f /app/users.sql -h $db_fqdn -U $username@$instance_name -d $db_name
echo "\nFQDN: "
echo "http://$fqdn:8080\n"
echo "IP: "
echo "http://$ip:8080\n"
echo "PostgreSQL \nusername: $username@$instance_name \npassword: $password"
open http://$fqdn:8080
open http://$ip:8080
cd ..