forked from CryptoManufaktur-io/vouchdirk-gcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch-terraform.sh
executable file
·39 lines (32 loc) · 1.23 KB
/
switch-terraform.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
#!/usr/bin/env bash
# Kill old SSH sessions
kill $(ps aux | grep '[:]localhost:8888 -N -q -f' | awk '{print $2}')
project_id=$(grep -o 'project_id\s*=\s*"[^"]*"' terraform.tfvars | cut -d'"' -f2)
# folder_name=$(basename $(pwd))
folder_name=$project_id
# GCloud
if gcloud config configurations list | grep -q "^$folder_name"; then
echo "Activate the config named $folder_name"
gcloud config configurations activate $folder_name
# echo "Set quota project to $folder_name"
# gcloud auth application-default set-quota-project $folder_name
else
echo "Create a config named $folder_name with matching Google project; don't set a default compute region"
gcloud init
fi
active_account=$(gcloud auth list --filter=status:ACTIVE --format="value(account)" 2>/dev/null)
if gcloud auth application-default print-access-token &> /dev/null; then
echo "Application default credentials are set."
else
echo "Application default credentials are not yet set."
gcloud auth application-default login
fi
if [[ -z "$active_account" ]]
then
echo "No interactive gcloud login yet"
gcloud auth login
else
echo "Active gcloud account is: $active_account"
fi
# Terraform
terraform init -backend-config=backend.conf -reconfigure -upgrade