-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathterraform.ts
419 lines (411 loc) · 11.1 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// If you edit commands or options, please copy our changes on to the terragrunt spec
const workspaceList: Fig.Generator = {
script: ["terraform", "workspace", "list"],
postProcess: function (out) {
return out.split("\n").map((workspace) => {
return {
name: workspace.replace("* ", "").trim(),
icon: "https://www.terraform.io/favicon.ico",
description: "Workspace",
};
});
},
};
const addressList: Fig.Generator = {
script: ["terraform", "state", "list"],
postProcess: function (out) {
if (out.includes("No state file was found!") || out.includes("Error")) {
return [];
}
return out.split("\n").map((addresses) => {
return {
name: addresses.replace("* ", "").trim(),
icon: "https://www.terraform.io/favicon.ico",
description: "Address",
};
});
},
};
const generalSubCommandOptions: Fig.Option[] = [
{
name: "-lock",
requiresSeparator: true,
description:
"Lock the state file when locking is supported. Defaults to true",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-force",
requiresSeparator: true,
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",
requiresSeparator: true,
description: "Duration to retry a state lock. Default 0s",
args: {
name: "seconds",
},
},
{
name: "-input",
requiresSeparator: true,
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",
requiresSeparator: true,
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",
requiresSeparator: true,
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",
requiresSeparator: true,
description: "Update the state prior to checking for differences",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-state",
requiresSeparator: true,
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",
isRepeatable: true,
},
{
name: "-var",
insertValue: "-var {cursor}",
description:
"Set a variable in the Terraform configuration. This flag can be set multiple times",
isRepeatable: true,
args: {
name: "foo=bar",
},
},
{
name: "-var-file",
requiresSeparator: true,
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: [
{
name: "-allow-missing",
description:
"If specified, the command will succeed (exit code 0) even if the resource is missing. The command might still return an error for other situations, such as if there is a problem reading or writing the state",
},
{
name: "-lock",
requiresSeparator: true,
description:
"Disables Terraform's default behavior of attempting to take a read/write lock on the state for the duration of the operation if set to false. Defaults to true",
args: {
name: "true or false",
suggestions: ["true", "false"],
},
},
{
name: "-lock-timeout",
requiresSeparator: true,
description:
"Unless locking is disabled with -lock=false, instructs Terraform to retry acquiring a lock for a period of time before returning an error. The duration syntax is a number followed by a time unit letter, such as 3s for three seconds",
args: {
name: "seconds",
},
},
{
name: "-ignore-remote-version",
description:
"When using the enhanced remote backend with Terraform Cloud, continue even if remote and local Terraform versions differ. This may result in an unusable Terraform Cloud workspace, and should be used with extreme caution",
args: {
name: "seconds",
},
},
...globalOptions,
],
args: {
generators: addressList,
name: "address",
},
},
{
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",
requiresSeparator: true,
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",
},
];
const completionSpec: Fig.Spec = {
name: "terraform",
description: "Terraform CLI",
options: globalOptions,
parserDirectives: {
flagsArePosixNoncompliant: true,
},
subcommands: [...mainCommands, ...otherCommands, ...extraCommands],
};
export default completionSpec;