forked from netology-code/mnt-homeworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.sh
58 lines (46 loc) · 1.18 KB
/
go.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
#!/usr/bin/env bash
workdir=./infrastructure
if ! [ -x "$(command -v terraform)" ]; then
echo 'Terraform is not installed. Visit: https://hashicorp-releases.yandexcloud.net/terraform/' >&2
exit 1
fi
if ! [ -x "$(command -v yc)" ]; then
echo 'Yandex CLI is not installed. Visit: https://cloud.yandex.ru/docs/cli/quickstart' >&2
exit 2
fi
if [ ! -d $workdir ]; then
echo "Infrastructure files not exists"
exit 3
fi
export TF_VAR_YC_TOKEN=$(yc config get token)
export TF_VAR_YC_CLOUD_ID=$(yc config get cloud-id)
export TF_VAR_YC_FOLDER_ID=$(yc config get folder-id)
export TF_VAR_YC_ZONE=$(yc config get compute-default-zone)
init() {
terraform init
}
up() {
terraform apply --auto-approve
}
down() {
terraform destroy --auto-approve
}
clear() {
rm -rf .terraform*
rm terraform.tfstate*
}
deploy() {
ansible-playbook -i cicd site.yml
yc compute instance list
}
cd $workdir
if [ $1 ]; then
$1
else
echo "Possible commands:"
echo " init - Init terraform provider"
echo " up - Deplay cloud resources"
echo " down - Destroy all cloud resources"
echo " clear - Clear temporary files"
echo " deploy - Deploy Jenkins nodes"
fi