-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-instance.sh
executable file
·46 lines (38 loc) · 1.04 KB
/
create-instance.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
#!/usr/bin/env bash
echo -e "\nCreate remote instance"
echo -e "\n# 1/2 - Loading and setting options..."
## Show commands (if you want to check, uncomment it)
#set -x
## Stop on errors
set -e
## Validate target environment
if [[ $# -eq 0 ]]; then
echo "No arguments supplied - inform the branch (dev|test|staging|master)";
exit 1;
fi
if [[ !"$1" =~ ^(dev|test|staging|master)$ ]]; then
echo "$1 is not a valid branch";
exit 1;
fi
## Define the env name by branch
ENV=$1
if [[ ${ENV} == "master" ]]; then
ENV="production";
elif [[ ${ENV} == "dev" || ${ENV} == "devops" ]]; then
ENV="dev-online";
fi
## Include config
source config.sh
source ${ENV}/config.sh
## Set GCP compute zone
gcloud config set project ${PROJECT}
gcloud config set compute/zone ${ZONE}
## Create instance
echo -e "\n# 1/2 - Creating Compute Instance..."
gcloud compute instances create ${INSTANCE_NAME} \
--image-family ${IMAGE_FAMILY} \
--image-project ${IMAGE_PROJECT} \
--machine-type ${MACHINE_TYPE} \
--zone ${ZONE} \
--tags ${TAGS} \
--${DELETION_PROTECTION}