MON-494 global refactor and format output
This commit is contained in:
parent
8f34a19d26
commit
f91ad224ec
@ -2,6 +2,7 @@
|
||||
|
||||
source "$(dirname $0)/utils.sh"
|
||||
init
|
||||
echo "Check requirements"
|
||||
|
||||
function check_command() {
|
||||
local cmd="$1"
|
||||
@ -44,6 +45,7 @@ function check_version() {
|
||||
}
|
||||
|
||||
for cmd in terraform terraform-docs; do
|
||||
echo -e "\t- Check command \"$cmd\" exists and in right version"
|
||||
check_command $cmd
|
||||
check_version $cmd
|
||||
done
|
||||
|
||||
@ -2,18 +2,21 @@
|
||||
|
||||
source "$(dirname $0)/utils.sh"
|
||||
init
|
||||
echo "Generate terraform outputs.tf files for every monitors modules"
|
||||
|
||||
# loop over every monitors set
|
||||
for path in $(find "$(get_scope ${1:-})" -name 'monitors-*.tf' -print | sort -fdbi); do
|
||||
cd $(dirname $path)
|
||||
for path in $(browse_modules "$(get_scope ${1:-})" 'monitors-*.tf'); do
|
||||
module=$(dirname ${path})
|
||||
echo -e "\t- Generate outputs.tf for module: ${module}"
|
||||
cd ${module}
|
||||
# empty outputs
|
||||
> outputs.tf
|
||||
# loop over monitors for each set
|
||||
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
|
||||
# create output block for current monitor
|
||||
cat >> outputs.tf <<EOF
|
||||
output "${monitor}_id" {
|
||||
description = "id for monitor $monitor"
|
||||
description = "id for monitor ${monitor}"
|
||||
value = datadog_monitor.${monitor}.*.id
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
source "$(dirname $0)/utils.sh"
|
||||
init
|
||||
echo "Update global README.md"
|
||||
|
||||
# only keep current README from begining to "Monitors summary" section (delete monitors list)
|
||||
sed -i '/### Monitors summary ###/q' README.md
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
source "$(dirname $0)/utils.sh"
|
||||
init
|
||||
echo "Update README.md for every monitors modules"
|
||||
|
||||
# download awk script to hack terraform-docs
|
||||
TERRAFORM_AWK="/tmp/terraform-docs.awk"
|
||||
@ -10,8 +11,10 @@ curl -Lso ${TERRAFORM_AWK} "https://raw.githubusercontent.com/cloudposse/build-h
|
||||
PATTERN_DOC="Related documentation"
|
||||
|
||||
# loop over every monitors set readme
|
||||
for path in $(find "$(get_scope ${1:-})" -name 'monitors-*.tf' -print | sort -fdbi); do
|
||||
cd $(dirname $path)
|
||||
for path in $(browse_modules "$(get_scope ${1:-})" 'monitors-*.tf'); do
|
||||
module=$(dirname $path)
|
||||
echo -e "\t- Generate outputs.tf for module: ${module}"
|
||||
cd ${module}
|
||||
EXIST=0
|
||||
if [ -f README.md ]; then
|
||||
mv README.md README.md.bak
|
||||
|
||||
@ -2,15 +2,18 @@
|
||||
|
||||
source "$(dirname $0)/utils.sh"
|
||||
init
|
||||
echo "Generate outputs.tf files when does not exist for every monitors modules"
|
||||
root=$(basename ${PWD})
|
||||
|
||||
# loop over every monitors set
|
||||
for path in $(find "$(get_scope ${1:-})" -name 'monitors-*.tf' -print | sort -fdbi); do
|
||||
cd $(dirname $path)
|
||||
for path in $(browse_modules "$(get_scope ${1:-})" 'monitors-*.tf'); do
|
||||
module=$(dirname ${path})
|
||||
cd ${module}
|
||||
# get name of the monitors set directory
|
||||
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
|
||||
echo -e "\t- Generate modules.tf for module: ${module}"
|
||||
relative=""
|
||||
current="${PWD}"
|
||||
# iterate on path until we go back to root
|
||||
|
||||
@ -2,9 +2,11 @@
|
||||
|
||||
source "$(dirname $0)/utils.sh"
|
||||
init
|
||||
echo "Check best practices respect"
|
||||
|
||||
echo -e "\t- Check only one notify_no_data set to true per module"
|
||||
# loop over every monitors set
|
||||
for path in $(find "$(get_scope ${1:-})" -name 'monitors-*.tf' -print | sort -fdbi); do
|
||||
for path in $(browse_modules "$(get_scope ${1:-})" 'monitors-*.tf'); do
|
||||
# check if there is more than 1 notify_no_data parameter set to true per set of monitors
|
||||
if [[ $(grep -c notify_no_data.*true $path) -gt 1 ]]; then
|
||||
echo "More than one notify_no_data set to true on $path"
|
||||
|
||||
@ -2,12 +2,14 @@
|
||||
|
||||
source "$(dirname $0)/utils.sh"
|
||||
init
|
||||
echo "Check terraform CI"
|
||||
|
||||
provider_version=$(grep ^[[:space:]]*version[[:space:]]= README.md | awk '{print $3}')
|
||||
|
||||
for path in $(find "$(get_scope ${1:-})" -name 'inputs.tf' -print); do
|
||||
dir=$(dirname ${path})
|
||||
cat <<EOF > ${dir}/tmp.tf
|
||||
for path in $(browse_modules "$(get_scope ${1:-})" 'inputs.tf'); do
|
||||
module=$(dirname $path)
|
||||
echo -e "\t- Terraform validate on module: ${module}"
|
||||
cat <<EOF > ${module}/tmp.tf
|
||||
provider "datadog" {
|
||||
version = $provider_version
|
||||
|
||||
@ -26,13 +28,14 @@ variable "datadog_app_key" {
|
||||
}
|
||||
|
||||
EOF
|
||||
if [ -f ${dir}/test.tf.ci ]; then
|
||||
cat ${dir}/test.tf.ci >> ${dir}/tmp.tf
|
||||
if [ -f ${module}/test.tf.ci ]; then
|
||||
cat ${module}/test.tf.ci >> ${module}/tmp.tf
|
||||
fi
|
||||
terraform init ${dir}
|
||||
terraform validate ${dir}
|
||||
rm -f ${dir}/tmp.tf
|
||||
terraform init ${module} > /tmp/null
|
||||
terraform validate ${module}
|
||||
rm -f ${module}/tmp.tf
|
||||
done
|
||||
|
||||
echo -e "\t- Terraform fmt recursive"
|
||||
terraform fmt -recursive
|
||||
|
||||
|
||||
@ -51,3 +51,7 @@ function get_name() {
|
||||
echo $name
|
||||
return 0
|
||||
}
|
||||
|
||||
function browse_modules() {
|
||||
find "$1" -name "$2" -print | sort -fdbi
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user