forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terraform.ts
362 lines (355 loc) · 9.12 KB
/
terraform.ts
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
const workspaceList: Fig.Generator = {
script: "terraform workspace list",
postProcess: function (out) {
// debug only
//console.log("this is out list: ", out);
return out.split("\n").map((workspace) => {
return {
name: workspace.replace("* ", "").trim(),
// UPDATE: Update this after the Icons API is available publicly!
icon: "fig:https://icon?type=terraform",
description: "workspace",
};
});
},
};
const generalSubCommandOptions: Fig.Option[] = [
{
name: "-lock",
insertValue: "-lock=",
description:
"Lock the state file when locking is supported. Defaults to true",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-force",
insertValue: "-force=",
description:
"Delete the workspace even if its state is not empty. Defaults to false.",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-lock-timeout",
insertValue: "-lock-timeout=",
description: "Duration to retry a state lock. Default 0s.",
args: {
name: "seconds",
},
},
{
name: "-input",
insertValue: "-input=",
description: "Ask for input for variables if not directly set.",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-no-color",
description: "Disables output with coloring.",
},
];
const globalOptions: Fig.Option[] = [
{
name: "-help",
description:
"Show this help output, or the help for a specified subcommand.",
},
{
name: "-chdir",
description:
"Switch to a different working directory before executing the given subcommand.",
insertValue: "-chdir=",
args: {
template: "filepaths",
},
},
{
name: "-version",
description: "Show the current Terraform version",
},
];
const mainCommands: Fig.Subcommand[] = [
{
name: "init",
description: "Prepare your working directory for other commands",
options: [
{
name: "-upgrade",
description:
"Opt to upgrade modules and plugins as part of their respective installation steps.",
},
...generalSubCommandOptions,
...globalOptions,
],
},
{
name: "validate",
description: "Check whether the configuration is valid",
options: [...globalOptions],
},
{
name: "plan",
description: "Show changes required by the current configuration",
options: [
{
name: "-compact-warnings",
description:
"If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.",
},
{
name: "-destroy",
description:
"If set, generates a plan to destroy all the known resources.",
},
{
name: "-detailed-exitcode",
description: "Return a detailed exit code when the command exits.",
},
{
name: "-out",
insertValue: "-out=",
description: "The path to save the generated execution plan.",
},
{
name: "-parallelism",
description:
"Limit the number of concurrent operation as Terraform walks the graph. Defaults to 10.",
args: {
name: "number",
},
},
{
name: "-refresh",
insertValue: "-refresh=",
description: "Update the state prior to checking for differences.",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-state",
insertValue: "-state=",
description:
"Path to the state file. Defaults to 'terraform.tfstate'. Ignored when remote state is used.",
args: {
template: "filepaths",
},
},
{
name: "-target",
displayName: "-target=resource",
description:
"A Resource Address to target. This flag can be used multiple times.",
},
{
name: "-var",
insertValue: "-var {cursor}",
description:
"Set a variable in the Terraform configuration. This flag can be set multiple times.",
args: {
name: "foo=bar",
},
},
{
name: "-var-file",
insertValue: "-var-file=",
description:
"Set variables in the Terraform configuration from a variable file.",
args: {
template: "filepaths",
},
},
...generalSubCommandOptions,
...globalOptions,
],
},
{
name: "apply",
description: "Create or update infrastructure",
options: [...globalOptions],
},
{
name: "destroy",
description: "Destroy previously-created infrastructure",
options: [...globalOptions],
},
];
const otherCommands: Fig.Subcommand[] = [
{
name: "console",
description: "Try Terraform expressions at an interactive command prompt",
options: [...globalOptions],
},
{
name: "fmt",
description: "Reformat your configuration in the standard style",
options: [...globalOptions],
},
{
name: "force-unlock",
description: "Release a stuck lock on the current workspace",
options: [...globalOptions],
},
{
name: "get",
description: "Install or upgrade remote Terraform modules",
options: [
{
name: "-update",
description:
"If specified, modules that are already downloaded will be checked for updates and the updates will be downloaded if present.",
},
...globalOptions,
],
},
{
name: "graph",
description: "Generate a Graphviz graph of the steps in an operation",
options: [...globalOptions],
},
{
name: "import",
description: "Associate existing infrastructure with a Terraform resource",
options: [...globalOptions],
},
{
name: "login",
description: "Obtain and save credentials for a remote hos",
options: [...globalOptions],
},
{
name: "logout",
description: "Remove locally-stored credentials for a remote host",
options: [...globalOptions],
},
{
name: "output",
description: "Show output values from your root module",
options: [...globalOptions],
},
{
name: "providers",
description: "Show the providers required for this configuration",
options: [...globalOptions],
},
{
name: "refresh",
description: "Update the state to match remote systems",
options: [...globalOptions],
},
{
name: "show",
description: "Show the current state or a saved plan",
options: [...globalOptions],
},
{
name: "state",
description: "Advanced state management",
},
{
name: "taint",
description: "Mark a resource instance as not fully functional",
options: [...globalOptions],
},
{
name: "untaint",
description: "Remove the 'tainted' state from a resource instance",
options: [...globalOptions],
},
{
name: "workspace",
description: "Workspace management",
options: [...globalOptions],
subcommands: [
{
name: "new",
insertValue: "new '{cursor}'",
description: "create a new workspace",
args: {
name: "workspace name",
},
options: [
{
name: "-lock",
description:
"Lock the state file when locking is supported. Defaults to true",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-lock-timeout",
description: "Duration to retry a stae lock. Default 0s.",
args: {
name: "seconds",
},
},
{
name: "-state",
insertValue: "-state=",
description:
"Path to an existing state file to initialize the state of this environment.",
args: {
name: "path",
template: "filepaths",
},
},
],
...globalOptions,
},
{
name: "show",
description: "display the current workspace",
options: [...globalOptions],
},
{
name: "list",
description: "list the workspace",
options: [...globalOptions],
},
{
name: "delete",
description: "delete the specified workspace.",
args: {
generators: workspaceList,
name: "workspace name",
},
options: [...generalSubCommandOptions],
},
{
name: "select",
description: "change the current working workspace",
args: {
generators: workspaceList,
},
},
],
},
];
const extraCommands: Fig.Subcommand[] = [
{
name: "-install-autocomplete",
description: "Install bash/zsh tab completion",
},
{
name: "-uninstall-autocomplete",
description: "Uninstall bash/zsh tab completion",
},
];
export const completionSpec: Fig.Spec = {
name: "terraform",
description: "Terraform CLI",
options: globalOptions,
posixNoncompliantFlags: true,
subcommands: [...mainCommands, ...otherCommands, ...extraCommands],
};