Skip to content
Snippets Groups Projects
Verified Commit 973882d5 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

Update terraform base files

parent 0261160b
Branches
No related tags found
No related merge requests found
#!/bin/bash
BASEDIR=$(dirname "$0")
if ! [ -f "$BASEDIR/secret/login.sh" ]; then
echo "Please create the login.sh file!"
exit 0
fi
source $BASEDIR/secret/login.sh
if [ -d "$BASEDIR/.terraform" ]; then
echo ".terraform folder exists."
else
terraform init \
-backend-config="address=https://git.sch.bme.hu/api/v4/projects/${GITLAB_PROJECT_ID}/terraform/state/${GITLAB_STATE_NAME}" \
-backend-config="lock_address=https://git.sch.bme.hu/api/v4/projects/${GITLAB_PROJECT_ID}/terraform/state/${GITLAB_STATE_NAME}/lock" \
-backend-config="unlock_address=https://git.sch.bme.hu/api/v4/projects/${GITLAB_PROJECT_ID}/terraform/state/${GITLAB_STATE_NAME}/lock" \
-backend-config="username=${GITLAB_USER}" \
-backend-config="password=${GITLAB_REPO_TOKEN}" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5" \
-reconfigure
fi
echo "Environment has been set up."
# to stay in our comfy virtualenv
exec "${SHELL:bash}"
\ No newline at end of file
#!/bin/bash
BASEDIR=$(dirname "$0")
PROJ_ID="3594"
STATE_NAME="state"
if [ -f "$BASEDIR/secret/login.sh" ]; then
echo "This folder is already initialized."
read -r -p "Reinitialize it? [y/N] " response
if ! [[ "$response" =~ ^([yY])$ ]]
then
echo "Doing nothing. Don't forget to source the secret/login.sh file"
exit 0
fi
fi
## Get variables
echo "Gitlab username:"
read GITLAB_USER
echo "Private access token for the Terraform state repo:"
read GITLAB_REPO_PAT
echo "Vsphere user:"
read TF_VAR_vsphere_user
echo "Vsphere password:"
read TF_VAR_vsphere_password
## Create login.sh
cat > "$BASEDIR/secret/login.sh" << EOF
# This file is managed with init.sh
export GITLAB_USER="$GITLAB_USER"
export GITLAB_REPO_PAT="$GITLAB_REPO_PAT"
export TF_VAR_vsphere_user="$TF_VAR_vsphere_user"
export TF_VAR_vsphere_password="$TF_VAR_vsphere_password"
EOF
chmod +x "$BASEDIR/secret/login.sh"
## Initialize Terraform
terraform init \
-backend-config="address=https://git.sch.bme.hu/api/v4/projects/${PROJ_ID}/terraform/state/${STATE_NAME}" \
-backend-config="lock_address=https://git.sch.bme.hu/api/v4/projects/${PROJ_ID}/terraform/state/${STATE_NAME}/lock" \
-backend-config="unlock_address=https://git.sch.bme.hu/api/v4/projects/${PROJ_ID}/terraform/state/${STATE_NAME}/lock" \
-backend-config="username=${GITLAB_USER}" \
-backend-config="password=${GITLAB_REPO_PAT}" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5" \
-reconfigure
echo "Initilized. Don't forget to source the secret/login.sh file"
\ No newline at end of file
export GITLAB_USER="gitsch user" #!/bin/bash
export GITLAB_REPO_PAT="gitsch repo private access token"
export TF_VAR_vsphere_user="" # Gitlab Project ID, this will be used as state store
export TF_VAR_vsphere_password="" export GITLAB_PROJECT_ID="0"
# If you want to rename the terraform state name, feel free.
export GITLAB_STATE_NAME="state"
# GitLab username
export GITLAB_USER="user"
# Access token with API Acces to the repo
export GITLAB_REPO_TOKEN="acces token"
# vSphere Username
export TF_VAR_vsphere_user="username"
# vSphere Password
export TF_VAR_vsphere_password="pw"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment