forked from claranet/terraform-datadog-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path30_update_module.sh
executable file
·44 lines (40 loc) · 1.46 KB
/
30_update_module.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
source "$(dirname $0)/utils.sh"
init
if [ "${REPO}" != "monitors" ]; then
# Run this script only for monitors repo
exit 0
fi
echo "Generate outputs.tf files when does not exist for every monitors modules"
root=$(basename ${PWD})
# loop over every modules
for module in $(browse_modules "$(get_scope ${1:-})" "${REPO}-*.tf"); do
cd ${module}
# get name of the monitors set directory
resource="$(basename ${module})"
# 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
echo -e "\t- Generate modules.tf for module: ${module}"
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
cat > modules.tf <<EOF
module "filter-tags" {
source = "${relative}common/filter-tags"
environment = var.environment
resource = "$resource"
filter_tags_use_defaults = var.filter_tags_use_defaults
filter_tags_custom = var.filter_tags_custom
filter_tags_custom_excluded = var.filter_tags_custom_excluded
}
EOF
fi
cd - >> /dev/null
done