#!/bin/bash if [ -z "$BASH_VERSION" ]; then exec bash "$0" "$@"; exit; fi #---------------------------------------------------------------------------------------------------------------- # 변수 선언 current_path=`pwd` line="*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*" #---------------------------------------------------------------------------------------------------------------- # 파일 및 폴더 경로 확인 __find_path (){ script_file="00_terraform_var_change.sh" cd ../../ tmp_path=`find -name ${script_file} | grep -vi old` tmp_num=`grep -c "/" ${tmp_path}` path_num=`echo $(( $tmp_num - 1 ))` script_path=`echo ${tmp_path}| cut -d "/" -f1-${path_num}` _bash=`which bash` _terraform=`which terraform` } #---------------------------------------------------------------------------------------------------------------- # lambda 실행 __lambda_execute (){ lambda_file="lambda_${1}.sh" cd "${current_path}/lambda" #./${lambda_file} echo ${line} echo "lambda file : $(pwd)/${lambda_file}" #DEBUG ${_bash} ${lambda_file} echo ${line} } #---------------------------------------------------------------------------------------------------------------- # 변수 변경 스크립트 실행 뒤 terraform apply 실행 __terraform_target (){ cd ${current_path} cd ../../ cd ${script_path} echo "script_file : ${script_file}" #DEBUG ${_bash} ${script_file} echo ${line} ${_terraform} apply } #---------------------------------------------------------------------------------------------------------------- if [[ ${1} == '' ]];then echo "[Usage] ${0} { start | stop | restart } " exit else script_func=${1} __find_path if [[ ${script_func} == 'start' ]];then __lambda_execute start __terraform_target elif [[ ${script_func} == 'stop' ]];then __lambda_execute stop elif [[ ${script_func} == 'restart' ]];then __lambda_execute restart __terraform_target else echo "[Usage] ${0} { start | stop | restart } " exit fi fi