-
-
Notifications
You must be signed in to change notification settings - Fork 550
/
Copy pathterraform_docs_replace.py
56 lines (49 loc) · 1.78 KB
/
terraform_docs_replace.py
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
45
46
47
48
49
50
51
52
53
54
55
56
import argparse
import os
import subprocess
import sys
def main(argv=None):
parser = argparse.ArgumentParser(
description="""Run terraform-docs on a set of files. Follows the standard convention of
pulling the documentation from main.tf in order to replace the entire
README.md file each time."""
)
parser.add_argument(
'--dest', dest='dest', default='README.md',
)
parser.add_argument(
'--sort-inputs-by-required', dest='sort', action='store_true',
help='[deprecated] use --sort-by-required instead',
)
parser.add_argument(
'--sort-by-required', dest='sort', action='store_true',
)
parser.add_argument(
'--with-aggregate-type-defaults', dest='aggregate', action='store_true',
help='[deprecated]',
)
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
args = parser.parse_args(argv)
dirs = []
for filename in args.filenames:
if (os.path.realpath(filename) not in dirs and
(filename.endswith(".tf") or filename.endswith(".tfvars"))):
dirs.append(os.path.dirname(filename))
retval = 0
for dir in dirs:
try:
procArgs = []
procArgs.append('terraform-docs')
if args.sort:
procArgs.append('--sort-by-required')
procArgs.append('md')
procArgs.append("./{dir}".format(dir=dir))
procArgs.append('>')
procArgs.append("./{dir}/{dest}".format(dir=dir, dest=args.dest))
subprocess.check_call(" ".join(procArgs), shell=True)
except subprocess.CalledProcessError as e:
print(e)
retval = 1
return retval
if __name__ == '__main__':
sys.exit(main())