123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #! /bin/bash
- if [ `pwd` != '/Users/frederick.t.damstra/variables_project/xdr-terraform-modules/base' ]; then
- echo Wrong directory!
- exit 1
- fi
- VARIABLE=$1
- VARFILE=$2
- GO=$3
- if [ "${VARIABLE}" == "" ]; then
- echo No variable name specified.
- exit 2
- fi
- if [ "${VARFILE}" == "" ]; then
- echo No file specified. Cannot run for real.
- GO=""
- fi
- if [ ! -f ../variables/${VARFILE} ]; then
- echo File ../variables/${VARFILE} not found. Canot run for real.
- GO=""
- fi
- if [ "${GO}" == "GO" ]; then
- cmd=''
- else
- echo Remember to add \'GO\' to the command line to run for real.
- cmd="/bin/echo Would run: "
- fi
- REGEX="s/var.${VARIABLE}/local.${VARIABLE}/g"
- echo REGEX: $REGEX
- REGEX2="/variable \"${VARIABLE}\" { type = .\* }/d"
- echo REGEX2: $REGEX2
- # Find the directories that use the variable
- DIRS=$( find . -type f -name "*.tf" -exec grep -Hl var.${VARIABLE} {} \; | xargs dirname | sort -u )
- echo Directories: $DIRS
- for d in $DIRS; do
- pushd $d
- ls -l | grep -- '->'
- SRC=`ls -l constants.tf | awk '{ print $11 }' | sed "s/constants.tf/variables\/${VARFILE}/"`
- $cmd ln -s $SRC .
- $cmd sed -i "" $REGEX `find . -type f -name "*.tf"`
- $cmd sed -i "" "${REGEX2}" vars.tf
- popd
- done
|