]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/terraform/_terraform
6258345635a22bb069efbfaae610608aa8580c1d
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / terraform / _terraform
1 #compdef terraform
2
3 local -a _terraform_cmds opt_args
4 _terraform_cmds=(
5     'apply:Builds or changes infrastructure'
6     'console:Interactive console for Terraform interpolations'
7     'destroy:Destroy Terraform-managed infrastructure'
8     'fmt:Rewrites config files to canonical format'
9     'force-unlock:Manually unlock the terraform state'
10     'get:Download and install modules for the configuration'
11     'graph:Create a visual graph of Terraform resources'
12     'import:Import existing infrastructure into Terraform'
13     'init:Initialize a Terraform working directory'
14     'login:Obtain and save credentials for a remote host'
15     'logout:Remove locally-stored credentials for a remote host'
16     'output:Read an output from a state file'
17     'plan:Generate and show an execution plan'
18     'providers:Prints a tree of the providers used in the configuration'
19     'refresh:Update local state file against real resources'
20     'show:Inspect Terraform state or plan'
21     'state:Advanced state management'
22     'taint:Manually mark a resource for recreation'
23     'untaint:Manually unmark a resource as tainted'
24     'validate:Validates the Terraform files'
25     'version:Prints the Terraform version'
26     'workspace:Workspace management'
27     '0.12upgrade:Rewrites pre-0.12 module source code for v0.12'
28     '0.13upgrade:Rewrites pre-0.13 module source code for v0.13'
29 )
30
31 __012upgrade() {
32   _arguments \
33     '-yes[Skip the initial introduction messages and interactive confirmation. This can be used to run this command in batch from a script.]' \
34     '-force[ Override the heuristic that attempts to detect if a configuration is already written for v0.12 or later.  Some of the transformations made by this command are not idempotent, so re-running against the same module may change the meanings expressions in the module.]'
35 }
36
37 __013upgrade() {
38   _arguments \
39     '-yes[Skip the initial introduction messages and interactive confirmation. This can be used to run this command in batch from a script.]'
40 }
41
42 __apply() {
43     _arguments \
44         '-auto-approve[Skip interactive approval of plan before applying.]' \
45         '-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
46         '-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
47         '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
48         '-lock-timeout=[(0s) Duration to retry a state lock.]' \
49         '-input=[(true) Ask for input for variables if not directly set.]' \
50         '-no-color[If specified, output will be colorless.]' \
51         '-parallelism=[(10) Limit the number of parallel resource operations.]' \
52         '-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
53         '-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \
54         '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
55         '*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
56         '*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
57         '*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
58 }
59
60 __console() {
61     _arguments \
62         '-state=[(terraform.tfstate) Path to read state.]' \
63         '*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
64         '*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
65 }
66
67 __destroy() {
68     _arguments \
69         '-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
70         '-auto-approve[Skip interactive approval before destroying.]' \
71         '-force[Deprecated: same as auto-approve.]' \
72         '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
73         '-lock-timeout=[(0s) Duration to retry a state lock.]' \
74         '-no-color[If specified, output will contain no color.]' \
75         '-parallelism=[(10) Limit the number of concurrent operations.]' \
76         '-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
77         '-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \
78         '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
79         '*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
80         '*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
81         '*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
82 }
83
84 __fmt() {
85     _arguments \
86         '-list=[(true) List files whose formatting differs (always false if using STDIN)]' \
87         '-write=[(true) Write result to source file instead of STDOUT (always false if using STDIN or -check)]' \
88         '-diff=[(false) Display diffs of formatting changes]' \
89         '-check=[(false) Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.]' \
90         '-recursive=[(false) Also process files in subdirectories. By default, only the given directory (or current directory) is processed.]'
91 }
92
93 __force_unlock() {
94     _arguments \
95         "-force[Don't ask for input for unlock confirmation.]"
96 }
97
98 __get() {
99     _arguments \
100         '-update=[(false) If true, modules already downloaded will be checked for updates and updated if necessary.]' \
101         '-no-color[Disable text coloring in the output.]'
102 }
103
104 __graph() {
105     _arguments \
106         '-draw-cycles[Highlight any cycles in the graph with colored edges. This helps when diagnosing cycle errors.]' \
107         '-type=[(plan) Type of graph to output. Can be: plan, plan-destroy, apply, validate, input, refresh.]'
108 }
109
110 __import() {
111     _arguments \
112         '-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
113         '-config=[(path) Path to a directory of Terraform configuration files to use to configure the provider. Defaults to pwd. If no config files are present, they must be provided via the input prompts or env vars.]' \
114         '-allow-missing-config[Allow import when no resource configuration block exists.]' \
115         '-input=[(true) Ask for input for variables if not directly set.]' \
116         '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
117         '-lock-timeout=[(0s) Duration to retry a state lock.]' \
118         '-no-color[If specified, output will contain no color.]' \
119         '-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
120         '-state-out=[(PATH) Path to the destination state file to write to. If this is not specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -g "*.tfstate"' \
121         '*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times. This is only useful with the "-config" flag.]' \
122         '*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
123 }
124
125 __init() {
126     _arguments \
127         '-backend=[(true) Configure the backend for this configuration.]' \
128         '-backend-config=[This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a 'key=value' format. This is merged with what is in the configuration file. This can be specified multiple times. The backend type must be in the configuration itself.]' \
129         '-force-copy[Suppress prompts about copying state data. This is equivalent to providing a "yes" to all confirmation prompts.]' \
130         '-from-module=[(SOURCE) Copy the contents of the given module into the target directory before initialization.]' \
131         '-get=[(true) Download any modules for this configuration.]' \
132         '-get-plugins=[(true) Download any missing plugins for this configuration.]' \
133         '-input=[(true) Ask for input if necessary. If false, will error if input was required.]' \
134         '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
135         '-lock-timeout=[(0s) Duration to retry a state lock.]' \
136         '-no-color[If specified, output will contain no color.]' \
137         '-plugin-dir[Directory containing plugin binaries. This overrides all default search paths for plugins, and prevents the automatic installation of plugins. This flag can be used multiple times.]:plugin_dir:_files -/' \
138         '-reconfigure[Reconfigure the backend, ignoring any saved configuration.]' \
139         '-upgrade=[(false) If installing modules (-get) or plugins (-get-plugins), ignore previously-downloaded objects and install the latest version allowed within configured constraints.]' \
140         '-verify-plugins=[(true) Verify the authenticity and integrity of automatically downloaded plugins.]'
141 }
142
143 __login() {
144     _arguments \
145
146 }
147
148 __logout() {
149     _arguments \
150
151 }
152
153 __output() {
154     _arguments \
155         '-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
156         '-no-color[If specified, output will contain no color.]' \
157         '-json[If specified, machine readable output will be printed in JSON format]'
158 }
159
160 __plan() {
161     _arguments \
162         '-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
163         '-destroy[If set, a plan will be generated to destroy all resources managed by the given configuration and state.]' \
164         '-detailed-exitcode[() Return detailed exit codes when the command exits. This will change the meaning of exit codes to: 0 - Succeeded, diff is empty (no changes); 1 - Errored, 2 - Succeeded; there is a diff]' \
165         '-input=[(true) Ask for input for variables if not directly set.]' \
166         '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
167         '-lock-timeout=[(0s) Duration to retry a state lock.]' \
168         '-no-color[() If specified, output will contain no color.]' \
169         '-out=[(path) Write a plan file to the given path. This can be used as input to the "apply" command.]' \
170         '-parallelism=[(10) Limit the number of concurrent operations.]' \
171         '-refresh=[(true) Update state prior to checking for differences.]' \
172         '-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -g "*.tfstate"' \
173         '*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
174         '*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
175         '*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
176 }
177
178 __providers() {
179     local -a __providers_cmds
180     __providers_cmds=(
181       'mirror:Mirrors the provider plugins needed for the current configuration'
182       'schema:Prints the schemas of the providers used in the configuration'
183     )
184     _describe -t providers "providers commands" __providers_cmds
185
186 }
187
188 __providers_mirror() {
189     _arguments \
190       '-platform=[(os_arch) Choose which target platform to build a mirror for.]' \
191       "*:target_dir:_files -/"
192 }
193
194 __providers_schema() {
195     _arguments \
196       '-json[]' \
197       '::'
198 }
199
200 __refresh() {
201     _arguments \
202         '-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]::backupfile:_files -g "*.backup"' \
203         '-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \
204         '-input=[(true) Ask for input for variables if not directly set.]' \
205         '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
206         '-lock-timeout=[(0s) Duration to retry a state lock.]' \
207         '-no-color[If specified, output will not contain any color.]' \
208         '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
209         '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \
210         '*-target=[(resource) A Resource Address to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \
211         '*-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
212         '*-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]:file:_files -g "*.tfvars{,.json}"'
213 }
214
215 __show() {
216     _arguments \
217         '-json[If specified, output the Terraform plan or state in a machine-readable form.]' \
218         '-no-color[If specified, output will not contain any color.]'
219 }
220
221 __state() {
222     local -a __state_cmds
223     __state_cmds=(
224       'list:List resources in the state'
225       'mv:Move an item in the state'
226       'pull:Pull current state and output to stdout'
227       'push:Update remote state from a local state file'
228       'replace-provider:Replace provider for resources in the Terraform state'
229       'rm:Remove instances from the state' 
230       'show:Show a resource in the state'
231     )
232     _describe -t state "state commands" __state_cmds
233 }
234
235 __state_list() {
236   _arguments \
237     '-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default, Terraform will consult the state of the currently-selected workspace.]' \
238     '-id=[(id) Filters the results to include only instances whose resource types have an attribute named id whose value equals the given id string.]' \
239     "*:address:__statelist" 
240 }
241
242 __state_mv() {
243   _arguments \
244     "-dry-run[If set, prints out what would've been moved but doesn't actually move anything.]" \
245     '-backup=[(PATH) Path where Terraform should write the backup for the original state. This can"t be disabled. If not set, Terraform will write it to the same path as the statefile with a ".backup" extension.]:backupfile:_files -g "*.backup"' \
246     '-backup-out=[(PATH) Path where Terraform should write the backup for the destination state. This can"t be disabled. If not set, Terraform will write it to the same path as the destination state file with a backup extension. This only needs to be specified if -state-out is set to a different path than -state.]:backupfile:_files -g "*.backup"' \
247     "-lock=[(true) Lock the state files when locking is supported.]:lock:(true false)" \
248     "-lock-timeout=[(0s) Duration to retry a state lock.]" \
249     '-state=[(path) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
250     '-state-out=[(path) Path to the destination state file to write to. If this isn"t specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -g "*.tfstate"' \
251     "::" \
252     ":source:__statelist" \
253     ":destination: " 
254 }
255
256 __state_push() {
257   _arguments \
258     "-force[Write the state even if lineages don't match or the remote serial is higher.]" \
259     '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
260     "-lock-timeout=[(0s) Duration to retry a state lock.]" \
261     "::" \
262     ":destination:_files"
263 }
264
265 __state_replace_provider() {
266   _arguments \
267     '-auto-approve[Skip interactive approval.]' \
268     '-backup=[(PATH) Path where Terraform should write the backup for the state file. This can"t be disabled. If not set, Terraform will write it to the same path as the state file with a ".backup" extension.]:backupfile:_files -g "*.backup"' \
269     "-lock=[(true) Lock the state files when locking is supported.]:lock:(true false)" \
270     "-lock-timeout=[(0s) Duration to retry a state lock.]" \
271     '-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \
272     ":from_provider_fqn:" \
273     ":to_provider_fqn:"
274 }
275
276 __state_rm() {
277   _arguments \
278     "-dry-run[If set, prints out what would've been removed but doesn't actually remove anything.]" \
279     '-backup=[(PATH) Path where Terraform should write the backup for the original state.]::backupfile:_files -g "*.backup"' \
280     "-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)" \
281     "-lock-timeout=[(0s) Duration to retry a state lock.]" \
282     '-state=[(PATH) Path to the state file to update. Defaults to the current workspace state.]:statefile:_files -g "*.tfstate"' \
283     "*:address:__statelist" 
284 }
285
286
287 __state_show() {
288   _arguments \
289     '-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]:statefile:_files -g "*.tfstate"' \
290     "*:address:__statelist" 
291 }
292
293 __statelist() {
294   compadd $(terraform state list $opt_args[-state])
295 }
296
297 __taint() {
298     _arguments \
299         '-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
300         '-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
301         '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
302         '-lock-timeout=[(0s) Duration to retry a state lock.]' \
303         '-module=[(path)  The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules).]' \
304         '-state=[(path) Path to read and save state (unless state-out is  specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
305         '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"' \
306         "*:address:__statelist" 
307 }
308
309 __untaint() {
310     _arguments \
311     '-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
312     '-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]:backupfile:_files -g "*.backup"' \
313     '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \
314     '-lock-timeout=[(0s) Duration to retry a state lock.]' \
315     '-module=[(path)  The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules).]' \
316     '-state=[(path) Path to read and save state (unless state-out is  specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \
317     '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"'
318 }
319
320 __validate() {
321     _arguments \
322     '-no-color[If specified, output will not contain any color.]' \
323     '-json[Produce output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems.]' \
324     ':dir:_files -/'
325 }
326
327 __version() {
328     _arguments \
329     '-json[Output the version information as a JSON object.]'
330 }
331
332 __workspace() {
333     local -a __workspace_cmds
334     __workspace_cmds=(
335         'delete:Delete a workspace'
336         'list:List Workspaces'
337         'new:Create a new workspace'
338         'select:Select a workspace'
339         'show:Show the name of the current workspace'
340     )
341     _describe -t workspace "workspace commands" __workspace_cmds
342 }
343
344 _arguments '*:: :->command'
345
346 if (( CURRENT == 1 )); then
347   _describe -t commands "terraform command" _terraform_cmds
348   return
349 fi
350
351 local -a _command_args
352 case "$words[1]" in
353   0.12upgrade)
354     __012upgrade ;;
355   0.13upgrade)
356     __013upgrade ;;
357   apply)
358     __apply ;;
359   console)
360     __console;;
361   destroy)
362     __destroy ;;
363   fmt)
364     __fmt;;
365   force-unlock)
366     __force_unlock;;
367   get)
368     __get ;;
369   graph)
370     __graph ;;
371   import)
372     __import;;
373   init)
374     __init ;;
375   login)
376     __login ;;
377   logout)
378     __logout ;;
379   output)
380     __output ;;
381   plan)
382     __plan ;;
383   providers)
384     test $CURRENT -lt 3 && __providers
385     [[ $words[2] = "mirror" ]] && __providers_mirror
386     [[ $words[2] = "schema" ]] && __providers_schema
387     ;;
388   refresh)
389     __refresh ;;
390   show)
391     __show ;;
392   state)
393     test $CURRENT -lt 3 && __state
394     [[ $words[2] = "list" ]] && __state_list
395     [[ $words[2] = "mv" ]] && __state_mv
396     [[ $words[2] = "push" ]] && __state_push
397     [[ $words[2] = "replace-provider" ]] && __state_replace_provider
398     [[ $words[2] = "rm" ]] && __state_rm
399     [[ $words[2] = "show" ]] && __state_show
400     ;;
401   taint)
402     __taint ;;
403   untaint)
404     __untaint ;;
405   validate)
406     __validate ;;
407   version)
408     __version ;;
409   workspace)
410     test $CURRENT -lt 3 && __workspace ;;
411 esac