bunkerized-nginx/tests/create.sh

47 lines
929 B
Bash
Raw Normal View History

2023-03-03 14:47:18 +01:00
#!/bin/bash
# drop and export secrets
echo "${CICD_SECRETS}" > /opt/.env
2023-08-31 08:17:56 +02:00
echo "export TF_VAR_k8s_ip=${K8S_IP}" >> /opt/.env
2023-03-03 14:47:18 +01:00
chmod +x /opt/.env
. /opt/.env
# create terraform env
mkdir "/tmp/$1"
cp ./tests/terraform/providers.tf "/tmp/$1"
cp -r ./tests/terraform/templates "/tmp/$1"
cp "./tests/terraform/${1}.tf" "/tmp/$1"
old_dir="$(pwd)"
cd "/tmp/$1"
# terraform init
terraform init
if [ $? -ne 0 ] ; then
echo "terraform init failed"
exit 1
fi
# terraform apply
terraform apply -auto-approve
if [ $? -ne 0 ] ; then
echo "terraform apply failed"
terraform destroy -auto-approve
exit 2
fi
# run ansible playbook
if [ -f "/tmp/${1}_inventory" ] ; then
cd "${old_dir}/tests/ansible"
export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook -i "/tmp/${1}_inventory" "${1}_playbook"
if [ $? -ne 0 ] ; then
echo "ansible-playbook failed"
cd "/tmp/$1"
terraform destroy -auto-approve
exit 3
fi
fi
# done
exit 0