Эх сурвалжийг харах

Adds Script to Update a Module's Reference Everywhere

And a helper script for aws40 imports for account standards.
Fred Damstra [afs macbook] 3 жил өмнө
parent
commit
5c0c871ba8

+ 22 - 0
bin/aws40_import_account_standards

@@ -0,0 +1,22 @@
+#! /bin/bash
+#
+# Simple helper script to do the appropriate imports for the account_standards module.
+
+TO_IMPORT=(
+  module.kinesis_firehose.aws_s3_bucket_server_side_encryption_configuration.kinesis_firehose_s3_bucket
+  module.kinesis_firehose.aws_s3_bucket_lifecycle_configuration.kinesis_firehose_s3_bucket
+  module.kinesis_firehose.aws_s3_bucket_acl.kinesis_firehose_s3_bucket
+)
+
+ACCOUNT_ID=$(cat ../account.hcl | egrep -v '^#' | egrep aws_account_id | awk '{ print $3 }' | sed 's/"//g')
+REGION=$(cat ../../region.hcl | egrep -v '^#' | egrep aws_region | awk '{ print $3 }' | sed 's/"//g')
+BUCKET_NAME=kinesis-flowlogs-${ACCOUNT_ID}-${REGION}
+
+for i in ${TO_IMPORT[@]}; do
+  if [[ $i =~ acl ]]; then
+    EXTRA=",private"
+  else
+    EXTRA=""
+  fi
+  terragrunt-local import $i ${BUCKET_NAME}${EXTRA}
+done

+ 124 - 0
bin/update_module_refs

@@ -0,0 +1,124 @@
+#! /bin/bash
+# 
+# Run from the xdr-terraform-live root, enviromment root, or partition root
+# to update the reference for all instances of a given module.
+#
+# USAGE:
+#  update_module_refs --module 006-account-standards --newtag v4.0.2
+
+function argparse {
+  PARAMS=""
+  while (( "$#" )); do
+    case "$1" in
+      -m|--module)
+        if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+          MODULE=$2
+          shift 2
+        else
+          echo "Error: Argument for $1 is missing" >&2
+          exit 1
+        fi
+        ;;
+      -n|--newtag)
+        if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+          NEWTAG=$2
+          shift 2
+        else
+          echo "Error: Argument for $1 is missing" >&2
+          exit 1
+        fi
+        ;;
+      -h|--help)
+        echo Usage: $0 '[-t|--test] [-d|--debug] -m|--module MODULE -n|--newtag NEWTAG'
+        exit 0
+        ;;
+      -t|--test)
+        TESTING="/bin/echo TESTING: "
+        shift
+        ;;
+      -d|--debug)
+        >&2 echo debug: Enabling debugging..
+        DEBUG=1
+        shift
+        ;;
+#      -p|--only-path)
+#        if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+#          ONLY_PATH=$2
+#          shift 2
+#        else
+#          echo "Error: Argument for $1 is missing" >&2
+#          exit 1
+#        fi
+#        ;;
+      -*|--*=) # unsupported flags
+        echo "Error: Unsupported flag $1" >&2
+        exit 1
+        ;;
+      *) # preserve positional arguments
+        PARAMS="$PARAMS $1"
+        shift
+        ;;
+    esac
+  done
+  # set positional arguments in their proper place
+  eval set -- "$PARAMS"
+}
+
+# Main
+argparse $*
+
+SHORT_PWD=$( basename ${PWD}  )
+PARENT_PWD=$( basename $( cd .. && pwd ) )
+[[ $DEBUG == 1 ]] && >&2 echo debug: PWD=$PWD
+[[ $DEBUG == 1 ]] && >&2 echo debug: SHORT_PWD=$SHORT_PWD
+
+# Sanity Checking
+if [[ "$NEWTAG" == "" ]]; then
+  >&2 echo Error: Parameter \'--newtag\' is required.
+  exit 5
+fi
+
+# Sanity Checking
+if [[ "$MODULE" == "" ]]; then
+  >&2 echo Error: Parameter \'--module\' is required.
+  exit 6
+fi
+
+# Only function in the root, the environment, or the partition directories
+# 
+# There's probably a clean way to do this syntax but I couldn't get it to work.
+# This check is "If globals.hcl doesn't exist AND env.hcl doesn't exist AND ..."
+if [ ! -e globals.hcl -a ! -e env.hcl -a ! -e partition.hcl ]; then
+  read -p "You do not appear to be in an appropriate directory. Continue anyway [y/N]? " -n 1 -r
+  echo ""
+  if [[ $REPLY =~ ^[Yy]$ ]]
+  then
+    echo Continuing...
+  else
+    echo Exiting...
+    exit 10
+  fi
+fi
+
+if [[ $NEWTAG =~ v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+  [[ $TESTING ]] && >&2 echo debug: Newtag $NEWTAG is valid format.
+else
+  >&2 echo Error: Invalid format for new tag. \"$NEWTAG\" must be of format v1.2.3
+  exit 6
+fi
+
+if [[ $MODULE =~ ^[0-9]{3}- ]]; then
+  [[ $TESTING ]] && >&2 echo debug: module $MODULE is valid format.
+else
+  >&2 echo Error: Invalid format for Module. \"$MODULE\" must be of format xxx-modulename, where the x\'s are numeric digits.
+  exit 7
+fi
+
+for i in `find . -type d -name "$MODULE"`; do
+  if [[ $i =~ skeleton ]]; then
+    echo ======= Skipping $i
+    continue
+  fi
+  echo ======= Processing $i
+  ${TESTING} sed -E -i .bak 's/ref=v[0-9]+.[0-9]+\.[0-9]+"$/ref='${NEWTAG}'"/' $i/terragrunt.hcl
+done