helper.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #! /bin/bash
  2. if [ `pwd` != '/Users/frederick.t.damstra/variables_project/xdr-terraform-modules/base' ]; then
  3. echo Wrong directory!
  4. exit 1
  5. fi
  6. VARIABLE=$1
  7. VARFILE=$2
  8. GO=$3
  9. if [ "${VARIABLE}" == "" ]; then
  10. echo No variable name specified.
  11. exit 2
  12. fi
  13. if [ "${VARFILE}" == "" ]; then
  14. echo No file specified. Cannot run for real.
  15. GO=""
  16. fi
  17. if [ ! -f ../variables/${VARFILE} ]; then
  18. echo File ../variables/${VARFILE} not found. Canot run for real.
  19. GO=""
  20. fi
  21. if [ "${GO}" == "GO" ]; then
  22. cmd=''
  23. else
  24. echo Remember to add \'GO\' to the command line to run for real.
  25. cmd="/bin/echo Would run: "
  26. fi
  27. REGEX="s/var.${VARIABLE}/local.${VARIABLE}/g"
  28. echo REGEX: $REGEX
  29. REGEX2="/variable \"${VARIABLE}\" { type = .\* }/d"
  30. echo REGEX2: $REGEX2
  31. # Find the directories that use the variable
  32. DIRS=$( find . -type f -name "*.tf" -exec grep -Hl var.${VARIABLE} {} \; | xargs dirname | sort -u )
  33. echo Directories: $DIRS
  34. for d in $DIRS; do
  35. pushd $d
  36. ls -l | grep -- '->'
  37. SRC=`ls -l constants.tf | awk '{ print $11 }' | sed "s/constants.tf/variables\/${VARFILE}/"`
  38. $cmd ln -s $SRC .
  39. $cmd sed -i "" $REGEX `find . -type f -name "*.tf"`
  40. $cmd sed -i "" "${REGEX2}" vars.tf
  41. popd
  42. done