-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.cbmd
48 lines (36 loc) · 1.77 KB
/
README.cbmd
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
# terraform-generate-snippets
The source of [yasnippet-terraform](https://github.com/staticaland/yasnippet-terraform).
This script generates YASnippet snippets based on Terraform provider schemas. It
works by parsing [`terraform providers schema
-json`](https://www.terraform.io/docs/commands/providers/schema.html) and
creates snippet files based on the JSON.
`generate_snippets.py make_provider_dirs` looks up all the providers from the
[Terraform registry API](https://registry.terraform.io/v2/providers) and creates
folders and Terraform files for all of them (every Terraform file in the
`providers` directory).
Once you have a bunch of provider folders, `generate_snippets.py
generate_snippets` will loop through all of them and run `terraform providers
schema -json` (and `terraform init` if needed). It will take quite a lot of disk
space and time to do the initial run. Subsequent runs should be fast as the
latest schema version is saved to disk.
It should be fairly trivial to extend this to support multiple snippet systems.
## Flow
```{.mermaid loc=img format=png filename=snippets width=400}
graph TD
B[generate_snippets.py] -->|Loop for every provider| C{Do we have the schema saved?}
C -->|No| D{Do we have the provider plugin?}
C -->|Yes| G{Load JSON}
D -->|Yes| E[Run `terraform providers schema -json`]
D -->|No| F[Run `terraform init`]
F --> E
E -->|Save schema| G
G --> H[Template and save snippet]
```
## `generate_snippets.py -h`
```{.bash .cb.run show=stdout:verbatim}
poetry run python generate_snippets.py -h
```
## Other
Snippet documentation for various editors:
- [YASnippet](https://joaotavora.github.io/yasnippet/snippet-development.html)
- [VSCode](https://code.visualstudio.com/docs/editor/userdefinedsnippets) follows the TextMate snippet syntax