Debian Codegraph @

README.md

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