Merged in MON-259_improve_scripts (pull request #110)

MON-259: Improve auto_update scripts

Approved-by: Jérôme Respaut <shr3ps@gmail.com>
Approved-by: Alexandre Gaillet <alexandre.gaillet@fr.clara.net>
Approved-by: Quentin Manfroi <quentin.manfroi@yahoo.fr>
This commit is contained in:
Jérôme Respaut 2018-07-23 13:38:40 +00:00 committed by Quentin Manfroi
commit e450587fbb
25 changed files with 61 additions and 50 deletions

View File

@ -4,12 +4,12 @@ set -xueo pipefail
source "$(dirname $0)/utils.sh" source "$(dirname $0)/utils.sh"
goto_root goto_root
for path in $(find . -path ./incubator -prune -o -name 'monitors-*.tf' -print); do for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors-*.tf' -print); do
cd $(dirname $path) cd $(dirname $path)
> outputs.tf > outputs.tf
for monitor in $(grep 'resource "datadog_monitor"' $(basename $path) | awk '{print $3}' | tr -d '"' ); do for monitor in $(grep 'resource "datadog_monitor"' $(basename $path) | awk '{print $3}' | tr -d '"' ); do
echo $monitor echo $monitor
cat <<EOF >> outputs.tf cat >> outputs.tf <<EOF
output "${monitor}_id" { output "${monitor}_id" {
description = "id for monitor $monitor" description = "id for monitor $monitor"
value = "\${datadog_monitor.${monitor}.id}" value = "\${datadog_monitor.${monitor}.id}"
@ -19,4 +19,4 @@ EOF
done done
cd - >> /dev/null cd - >> /dev/null
done done
terraform fmt terraform fmt "$(get_scope $1)"

View File

@ -20,7 +20,7 @@ done
PATTERN_DOC="Related documentation" PATTERN_DOC="Related documentation"
for path in $(find . -path ./incubator -prune -o -name 'monitors-*.tf' -print); do for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors-*.tf' -print); do
cd $(dirname $path) cd $(dirname $path)
EXIST=0 EXIST=0
if [ -f README.md ]; then if [ -f README.md ]; then

View File

@ -1,7 +1,10 @@
#!/bin/bash #!/bin/bash
set -xueo pipefail set -xueo pipefail
source "$(dirname $0)/utils.sh"
cd $(dirname $0) cd $(dirname $0)
for script in [0-9][0-9]_*.sh; do for script in [0-9][0-9]_*.sh; do
./${script} ./${script} "$(get_scope $1)"
done done

View File

@ -9,6 +9,14 @@ function goto_root {
fi fi
} }
function get_scope {
TO_PARSE="."
if [ ! -z ${1+x} ]; then
TO_PARSE="$1"
fi
echo $TO_PARSE
}
function list_dirs { function list_dirs {
echo ${1} | awk -F '/' '{$1=""; print $0}' | cut -c 2- echo ${1} | awk -F '/' '{$1=""; print $0}' | cut -c 2-
} }