From 62ce38ca989f02f2ec2289ab82041f677f18ed26 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Wed, 26 Sep 2018 11:13:46 +0200 Subject: [PATCH 1/3] MON-311 auto generate relative path for modules.tf --- scripts/03_update_module.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/03_update_module.sh b/scripts/03_update_module.sh index 5ee4795..ca9dc8c 100755 --- a/scripts/03_update_module.sh +++ b/scripts/03_update_module.sh @@ -4,6 +4,8 @@ set -xueo pipefail source "$(dirname $0)/utils.sh" goto_root +root=$(basename $(pwd)) + # loop over every monitors set for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors-*.tf' -print | sort -fdbi); do cd $(dirname $path) @@ -11,10 +13,16 @@ for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors resource="$(basename $(dirname $path))" # if modules.tf does not exist AND if this set respect our tagging convention if ! [ -f modules.tf ] && grep -q filter_tags_use_defaults inputs.tf; then + relative="" + current="$(pwd)" + while [[ "$(basename $current)" != "$root" ]]; do + relative="${relative}../" + current="$(dirname $current)" + done # add the filter tags module cat > modules.tf < Date: Wed, 26 Sep 2018 11:24:51 +0200 Subject: [PATCH 2/3] MON-311 replace pwd function by env variable for pwd --- scripts/03_update_module.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/03_update_module.sh b/scripts/03_update_module.sh index ca9dc8c..67d3cfb 100755 --- a/scripts/03_update_module.sh +++ b/scripts/03_update_module.sh @@ -4,7 +4,7 @@ set -xueo pipefail source "$(dirname $0)/utils.sh" goto_root -root=$(basename $(pwd)) +root=$(basename ${PWD}) # loop over every monitors set for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors-*.tf' -print | sort -fdbi); do @@ -14,7 +14,7 @@ for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors # if modules.tf does not exist AND if this set respect our tagging convention if ! [ -f modules.tf ] && grep -q filter_tags_use_defaults inputs.tf; then relative="" - current="$(pwd)" + current="${PWD}" while [[ "$(basename $current)" != "$root" ]]; do relative="${relative}../" current="$(dirname $current)" From 999f301d3aebf747599ede0ee07a0de49929f4cf Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Wed, 26 Sep 2018 11:35:18 +0200 Subject: [PATCH 3/3] MON-311 add comments --- scripts/03_update_module.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/03_update_module.sh b/scripts/03_update_module.sh index 67d3cfb..4458c20 100755 --- a/scripts/03_update_module.sh +++ b/scripts/03_update_module.sh @@ -15,8 +15,11 @@ for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors if ! [ -f modules.tf ] && grep -q filter_tags_use_defaults inputs.tf; then relative="" current="${PWD}" + # iterate on path until we go back to root while [[ "$(basename $current)" != "$root" ]]; do + # for each iteration add "../" to generate relative path relative="${relative}../" + # remove last directory from current path current="$(dirname $current)" done # add the filter tags module