diff --git a/bin/terraform-docs.awk b/bin/terraform-docs.awk index 43e735ed..1c48a70d 100644 --- a/bin/terraform-docs.awk +++ b/bin/terraform-docs.awk @@ -4,42 +4,76 @@ # https://github.com/segmentio/terraform-docs/issues/62 { - if ( /\{/ ) { - braceCnt++ + if ( /\{/ ) { + braceCnt++ } - if ( /\}/ ) { - braceCnt-- + if ( /\}/ ) { + braceCnt-- } + # [START] variable or output block started if ($0 ~ /(variable|output) "(.*?)"/) { + # [CLOSE] "default" block + if (blockDefCnt > 0) { + blockDefCnt = 0 + } blockCnt++ print $0 } - if ($1 == "description") { - print $0 + # [START] multiline default statement started + if (blockCnt > 0) { + if ($1 == "default") { + print $0 + if ($NF ~ /[\[\(\{]/) { + blockDefCnt++ + blockDefStart=1 + } + } } - if ($1 == "default") { - if (braceCnt > 1) { - print " default = {}" - } else { + # [PRINT] single line "description" + if (blockDefCnt == 0) { + if ($1 == "description") { + # [CLOSE] "default" block + if (blockDefCnt > 0) { + blockDefCnt = 0 + } print $0 } } - if ($1 == "type" ) { - type=$3 - if (type ~ "object") { - print " type = \"object\"" - } else { - print " type = \"" $3 "\"" + # [PRINT] single line "type" + if (blockCnt > 0) { + if ($1 == "type" ) { + # [CLOSE] "default" block + if (blockDefCnt > 0) { + blockDefCnt = 0 + } + type=$3 + if (type ~ "object") { + print " type = \"object\"" + } else { + print " type = \"" $3 "\"" + } } } - if (braceCnt == 0 && blockCnt > 0) { - blockCnt-- - print $0 + # [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 + } } }