• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H09-Feb-2021-

tfconfig/H09-Feb-2021-

CODEOWNERSH A D09-Feb-202196

LICENSEH A D09-Feb-202115.6 KiB

README.mdH A D09-Feb-20214 KiB

go.modH A D09-Feb-2021514

go.sumH A D09-Feb-20215.8 KiB

main.goH A D09-Feb-2021956

README.md

1# terraform-config-inspect
2
3This repository contains a helper library for extracting high-level metadata
4about Terraform modules from their source code. It processes only a subset
5of the information Terraform itself would process, and in return it's able
6to be broadly compatible with modules written for many different versions of
7Terraform.
8
9```
10$ go get github.com/hashicorp/terraform-config-inspect
11```
12
13```go
14import "github.com/hashicorp/terraform-config-inspect/tfconfig"
15
16// ...
17
18module, diags := tfconfig.LoadModule(dir)
19
20// ...
21```
22
23There are not yet any formal compatibility promises for the Terraform
24configuration file format, so this tool can't yet promise to be compatible
25with unknown future extensions to the format. However, it *should* be capable
26of parsing valid configurations targeting Terraform versions between 0.10
27and 0.12.
28
29## Command Line Tool
30
31The primary way to use this repository is as a Go library, but as a convenience
32it also contains a CLI tool called `terraform-config-inspect`, installed
33automatically by the `go get` command above, that allows viewing module
34information in either a Markdown-like format or in JSON format.
35
36```sh
37$ terraform-config-inspect path/to/module
38```
39```markdown
40# Module `path/to/module`
41
42Provider Requirements:
43* **null:** (any version)
44
45## Input Variables
46* `a` (default `"a default"`)
47* `b` (required): The b variable
48
49## Output Values
50* `a`
51* `b`: I am B
52
53## Managed Resources
54* `null_resource.a` from `null`
55* `null_resource.b` from `null`
56```
57
58```sh
59$ terraform-config-inspect --json path/to/module
60```
61```json
62{
63  "path": "path/to/module",
64  "variables": {
65    "A": {
66      "name": "A",
67      "default": "A default",
68      "pos": {
69        "filename": "path/to/module/basics.tf",
70        "line": 1
71      }
72    },
73    "B": {
74      "name": "B",
75      "description": "The B variable",
76      "pos": {
77        "filename": "path/to/module/basics.tf",
78        "line": 5
79      }
80    }
81  },
82  "outputs": {
83    "A": {
84      "name": "A",
85      "pos": {
86        "filename": "path/to/module/basics.tf",
87        "line": 9
88      }
89    },
90    "B": {
91      "name": "B",
92      "description": "I am B",
93      "pos": {
94        "filename": "path/to/module/basics.tf",
95        "line": 13
96      }
97    }
98  },
99  "required_providers": {
100    "null": []
101  },
102  "managed_resources": {
103    "null_resource.A": {
104      "mode": "managed",
105      "type": "null_resource",
106      "name": "A",
107      "provider": {
108        "name": "null"
109      },
110      "pos": {
111        "filename": "path/to/module/basics.tf",
112        "line": 18
113      }
114    },
115    "null_resource.B": {
116      "mode": "managed",
117      "type": "null_resource",
118      "name": "B",
119      "provider": {
120        "name": "null"
121      },
122      "pos": {
123        "filename": "path/to/module/basics.tf",
124        "line": 19
125      }
126    }
127  },
128  "data_resources": {},
129  "module_calls": {}
130}
131```
132
133## Contributing
134
135This library and tool are intentionally focused on only extracting simple
136top-level metadata about a single Terraform module. This is to reduce the
137maintenance burden of keeping this codebase synchronized with changes to
138Terraform itself: the features extracted by this package are unlikely to change
139significantly in future versions.
140
141For that reason, **we cannot accept external PRs for this codebase that add support for additional Terraform language features**.
142
143Furthermore, we consider this package feature-complete; if there is a feature
144you wish to see added, please open a GitHub issue first so we can discuss the
145feasability and design before submitting a pull request. We are unlikely to
146accept PRs that add features without discussion first.
147
148We would be happy to review PRs to fix bugs in existing functionality or to
149improve the usability of the Go package API, however. We will be hesitant about
150any breaking changes to the API, since this library is used by a number of
151existing tools and systems.
152
153To work on this codebase you will need a recent version of Go installed. Please
154ensure all files match the formatting rules applied by `go fmt` and that all
155unit tests are passing.
156