Skip to content

Commit 2b30f7c

Browse files
committed
Fix pre TF 0.12 generators
1 parent 09d8cbd commit 2b30f7c

File tree

4 files changed

+11
-23
lines changed

4 files changed

+11
-23
lines changed

data/docker-entrypoint-0.11.sh

+11-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ if [ "${#}" -ge "1" ]; then
111111
# Remove first argument "replace"
112112
shift;
113113
mkdir -p /tmp-012
114-
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"
114+
awk -f /terraform-docs.awk -- "$(dirname "${MY_FILE}")/"*.tf > "/tmp-012/tmp.tf"
115115
# Get terraform-docs output
116116
>&2 echo "terraform-docs-012 ${*} $(dirname "${MY_FILE}")"
117117
if ! DOCS="$(terraform-docs "${@}" "/tmp-012")"; then
@@ -141,19 +141,25 @@ if [ "${#}" -ge "1" ]; then
141141

142142
# Terraform < 0.12
143143
if [ "${1}" = "terraform-docs" ]; then
144+
>&2 echo "${*}"
144145
exec "${@}"
145146

146147
# Terraform >= 0.12
147148
else
148-
mkdir -p /tmp-012
149-
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"
150149

151-
# Remove last argument (path)
150+
# Store and Remove last argument (filename)
151+
eval MY_DIR="\${$#}" # store last argument
152152
args="$(trim_last_arg "${@}")" # get all the args except the last arg
153153
eval "set -- ${args}" # update the shell's arguments with the new value
154-
# Remove first argument (terraform-docs-012)
154+
155+
mkdir -p /tmp-012
156+
awk -f /terraform-docs.awk -- "${MY_DIR}/"*.tf > "/tmp-012/tmp.tf"
157+
158+
# Remove first argument
155159
shift
160+
156161
# Execute
162+
>&2 echo "terraform-docs ${*} ${MY_DIR}"
157163
if ! terraform-docs "${@}" "/tmp-012/"; then
158164
cat -n "/tmp-012/tmp.tf" >&2
159165
exit 1

tests/output/generate/0.12/TEST-0.1.1.md

-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Test
2-
3-
Stuff before terraform-docs
4-
5-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
61

72
## Inputs
83

@@ -144,6 +139,3 @@ test
144139
| this_security_group_owner_id | The owner ID |
145140
| this_security_group_vpc_id | The VPC ID |
146141

147-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
148-
149-
Stuff after terraform-docs
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
21

32
## Inputs
43

54
| Name | Description | Type | Default | Required |
65
|------|-------------|:----:|:-----:|:-----:|
76
| test | test description | string | - | yes |
87

9-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

tests/output/generate/default/TEST-0.1.1.md

-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Test
2-
3-
Stuff before terraform-docs
4-
5-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
61

72
## Inputs
83

@@ -89,6 +84,3 @@ Stuff before terraform-docs
8984
| this_db_subnet_group_arn | The ARN of the db subnet group |
9085
| this_db_subnet_group_id | The db subnet group id |
9186

92-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
93-
94-
Stuff after terraform-docs

0 commit comments

Comments
 (0)