diff --git a/test/terraform/input-descriptions.bats b/test/terraform/input-descriptions.bats index bcadb17..a6fc48b 100644 --- a/test/terraform/input-descriptions.bats +++ b/test/terraform/input-descriptions.bats @@ -10,7 +10,7 @@ function teardown() { @test "check if terraform inputs have descriptions" { skip_unless_terraform - terraform_docs json . > $TMPFILE + terraform-docs json . > $TMPFILE run bash -c "jq -rS '.inputs[] | select (.description == \"\" or .description == null) | .name + \" is missing a description\"' < $TMPFILE" log "$output" [ -z "$output" ] diff --git a/test/terraform/lib.bash b/test/terraform/lib.bash index cb868c2..9bd3fe7 100644 --- a/test/terraform/lib.bash +++ b/test/terraform/lib.bash @@ -40,10 +40,3 @@ function clean() { function skip_unless_terraform() { [[ -n $(echo *.tf) ]] || skip "no *.tf files" } - -function terraform_docs() { - which awk 2>&1 >/dev/null || ( echo "awk not available"; exit 1) - which terraform 2>&1 >/dev/null || ( echo "terraform not available"; exit 1) - which terraform-docs 2>&1 >/dev/null || ( echo "terraform-docs not available"; exit 1) - terraform-docs --no-providers --no-header $1 $2 -} diff --git a/test/terraform/output-descriptions.bats b/test/terraform/output-descriptions.bats index effdbfe..8457647 100644 --- a/test/terraform/output-descriptions.bats +++ b/test/terraform/output-descriptions.bats @@ -10,7 +10,7 @@ function teardown() { @test "check if terraform outputs have descriptions" { skip_unless_terraform - terraform_docs json . > $TMPFILE + terraform-docs json . > $TMPFILE run bash -c "jq -rS '.outputs[] | select (.description == \"\" or .description == null) | .name + \" is missing a description\"' < $TMPFILE" log "$output" [ -z "$output" ] diff --git a/test/terraform/terraform-docs.awk b/test/terraform/terraform-docs.awk deleted file mode 100644 index 5896464..0000000 --- a/test/terraform/terraform-docs.awk +++ /dev/null @@ -1,85 +0,0 @@ -# This script converts Terraform 0.12 variables/outputs to something suitable for `terraform-docs` -# As of terraform-docs v0.6.0, HCL2 is not supported. This script is a *dirty hack* to get around it. -# https://github.com/segmentio/terraform-docs/ -# https://github.com/segmentio/terraform-docs/issues/62 - -{ - if ( $0 ~ /\{/ ) { - braceCnt++ - } - - if ( $0 ~ /\}/ ) { - braceCnt-- - } - - # [START] variable or output block started - if ($0 ~ /^[[:space:]]*(variable|output)[[:space:]][[:space:]]*"(.*?)"/) { - # Normalize the braceCnt (should be 1 now) - braceCnt = 1 - # [CLOSE] "default" block - if (blockDefCnt > 0) { - blockDefCnt = 0 - } - blockCnt++ - print $0 - } - - # [START] multiline default statement started - if (blockCnt > 0) { - if ($0 ~ /^[[:space:]][[:space:]]*(default)[[:space:]][[:space:]]*=/) { - if ($3 ~ "null") { - print " default = \"null\"" - } else { - print $0 - blockDefCnt++ - blockDefStart=1 - } - } - } - - # [PRINT] single line "description" - if (blockCnt > 0) { - if (blockDefCnt == 0) { - if ($0 ~ /^[[:space:]][[:space:]]*description[[:space:]][[:space:]]*=/) { - # [CLOSE] "default" block - if (blockDefCnt > 0) { - blockDefCnt = 0 - } - print $0 - } - } - } - - # [PRINT] single line "type" - if (blockCnt > 0) { - if ($0 ~ /^[[:space:]][[:space:]]*type[[:space:]][[:space:]]*=/ ) { - # [CLOSE] "default" block - if (blockDefCnt > 0) { - blockDefCnt = 0 - } - type=$3 - if (type ~ "object") { - print " type = \"object\"" - } else { - print " type = \"" $3 "\"" - } - } - } - - # [CLOSE] variable/output block - if (blockCnt > 0) { - if (braceCnt == 0 && blockCnt > 0) { - blockCnt-- - print $0 - } - } - - # [PRINT] Multiline "default" statement - if (blockCnt > 0 && blockDefCnt > 0) { - if (blockDefStart == 1) { - blockDefStart = 0 - } else { - print $0 - } - } -}