_terraform
37267 bytes
1#compdef terraform
2compdef _terraform terraform
3
4(( ${+functions[_terraform_commands]} )) || _terraform_commands() {
5 local -a _terraform_cmds
6 _terraform_cmds=(
7 'apply:Create or update infrastructure'
8 'console:Try Terraform expressions at an interactive command prompt'
9 'destroy:Destroy previously-created infrastructure'
10 'fmt:Reformat your configuration in the standard style'
11 'force-unlock:Release a stuck lock on the current workspace'
12 'get:Install or upgrade remote Terraform modules'
13 'graph:Generate a Graphviz graph of the steps in an operation'
14 'import:Associate existing infrastructure with a Terraform resource'
15 'init:Prepare your working directory for other commands'
16 'login:Obtain and save credentials for a remote host'
17 'logout:Remove locally-stored credentials for a remote host'
18 'metadata:Metadata related commands'
19 'output:Show output values from your root module'
20 'plan:Show changes required by the current configuration'
21 'providers:Show the providers required for this configuration'
22 'refresh:Update the state to match remote systems'
23 'show:Show the current state or a saved plan'
24 'state:Advanced state management'
25 'taint:Mark a resource instance as not fully functional'
26 'test:Execute integration tests for Terraform modules'
27 'untaint:Remove the '\''tainted'\'' state from a resource instance'
28 'validate:Check whether the configuration is valid'
29 'version:Show the current Terraform version'
30 'workspace:Workspace management'
31 )
32 if (( CURRENT == 1 )); then
33 _describe -t commands 'terraform commands' _terraform_cmds
34 return
35 fi
36
37 local curcontext="${curcontext}"
38 cmd="${${_terraform_cmds[(r)$words[1]:*]%%:*}}"
39 curcontext="${curcontext%:*:*}:terraform-${cmd}:"
40
41 local __chdir="${opt_args[-chdir]:-.}"
42
43 if (( ${+functions[_terraform_$cmd]} )); then
44 "_terraform_${cmd}"
45 else
46 _message "no more options"
47 fi
48}
49
50(( ${+functions[_terraform_apply]} )) || _terraform_apply() {
51 _arguments \
52 '-auto-approve[Skip interactive approval of plan before applying.]' \
53 '-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 -W __chdir -g "*.backup"' \
54 '-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.]' \
55 '-destroy[Destroy Terraform-managed infrastructure. The command "terraform destroy" is a convenience alias for this option.]' \
56 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
57 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
58 '-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
59 '-no-color[If specified, output won'\''t contain any color.]' \
60 '-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \
61 '-refresh=[(true) Skip checking for external changes to remote objects while creating the plan. This can potentially make planning faster, but at the expense of possibly planning against a stale record of the remote system state.]:refresh:(true false)' \
62 '*-replace=[(resource) Force replacement of a particular resource instance using its resource address. If applying would'\''ve normally produced an update or no-op action for this instance, Terraform will replace it instead. You can use this option multiple times to replace more than one object.]:resource:__terraform_state_resources' \
63 '-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -W __chdir -g "*.tfstate"' \
64 '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -W __chdir -g "*.tfstate"' \
65 '*-target=[(resource) Limit the operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \
66 '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
67 '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' \
68 ':plan:_files -W __chdir -'
69}
70
71(( ${+functions[_terraform_console]} )) || _terraform_console() {
72 _arguments \
73 '-state=[(terraform.tfstate) Legacy option for the local backend only. See the local backend'\''s documentation for more information.]:statefile:_files -W __chdir -g "*.tfstate"' \
74 '-plan[Create a new plan (as if running "terraform plan") and then evaluate expressions against its planned state, instead of evaluating against the current state. You can use this to inspect the effects of configuration changes that haven'\''t been applied yet.]' \
75 '*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]:var:' \
76 '*-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 -W __chdir -g "*.tfvars{,.json}"'
77}
78
79(( ${+functions[_terraform_destroy]} )) || _terraform_destroy() {
80 _arguments \
81 '-auto-approve[Skip interactive approval of plan before applying.]' \
82 '-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 -W __chdir -g "*.backup"' \
83 '-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.]' \
84 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
85 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
86 '-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
87 '-no-color[If specified, output won'\''t contain any color.]' \
88 '-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \
89 '-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]:refresh:(true false)' \
90 '-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -W __chdir -g "*.tfstate"' \
91 '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -W __chdir -g "*.tfstate"' \
92 '*-target=[(resource) Limit the operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \
93 '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
94 '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"'
95}
96
97(( ${+functions[_terraform_fmt]} )) || _terraform_fmt() {
98 _arguments \
99 '-list=[(true) Don'\''t list files whose formatting differs (always disabled if using STDIN)]:list:(true false)' \
100 '-write=[(true) Don'\''t write to source files (always disabled if using STDIN or -check)]:write:(true false)' \
101 '-diff[Display diffs of formatting changes]' \
102 '-check[Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.]' \
103 '-no-color[If specified, output won'\''t contain any color.]' \
104 '-recursive[Also process files in subdirectories. By default, only the given directory (or current directory) is processed.]' \
105 '*:targets:_files -W __chdir -'
106}
107
108(( ${+functions[_terraform_force-unlock]} )) || _terraform_force-unlock() {
109 _arguments \
110 '-force[Don'\''t ask for input for unlock confirmation.]' \
111 ':lock_id:'
112}
113
114(( ${+functions[_terraform_get]} )) || _terraform_get() {
115 _arguments \
116 '-update[Check already-downloaded modules for available updates and install the newest versions available.]' \
117 '-no-color[Disable text coloring in the output.]' \
118 '-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/'
119}
120
121(( ${+functions[_terraform_graph]} )) || _terraform_graph() {
122 _arguments \
123 '-draw-cycles[Highlight any cycles in the graph with colored edges. This helps when diagnosing cycle errors. This option is supported only when illustrating a real evaluation graph, selected using the -type=TYPE option.]' \
124 '-module-depth=[(-1) (deprecated) In prior versions of Terraform, specified the depth of modules to show in the output.]:module_depth:' \
125 '-plan=[Render graph using the specified plan file instead of the configuration in the current directory. Implies -type=apply.]:plan:_files -W __chdir -' \
126 '-type=[(plan) Type of operation graph to output. Can be: plan, plan-refresh-only, plan-destroy, or apply. By default Terraform just summarizes the relationships between the resources in your configuration, without any particular operation in mind. Full operation graphs are more detailed but therefore often harder to read.]:type:(plan plan-refresh-only plan-destroy apply)'
127}
128
129(( ${+functions[_terraform_import]} )) || _terraform_import() {
130 _arguments \
131 '-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 -W __chdir -g "*.backup"' \
132 '-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.]:config:_files -W __chdir -/' \
133 '-input=[(true) Disable interactive input prompts.]:input:(true false)' \
134 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
135 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
136 '-no-color[If specified, output will contain no color.]' \
137 '-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -g "*.tfstate"' \
138 '-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 -W __chdir -g "*.tfstate"' \
139 '*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times. This is only useful with the "-config" flag.]:var:' \
140 '*-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 -W __chdir -g "*.tfvars{,.json}"' \
141 ':addr:' \
142 ':id:'
143}
144
145(( ${+functions[_terraform_init]} )) || _terraform_init() {
146 _arguments \
147 '-backend=[(true) Disable backend or Terraform Cloud initialization for this configuration and use what was previously initialized instead.]:backend:(true false)' \
148 '-backend-config=[Configuration to be merged with what is in the configuration file'\''s '\''backend'\'' block. This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a '\''key=value'\'' format, and can be specified multiple times. The backend type must be in the configuration itself.]:backend_config:_files -W __chdir -' \
149 '-force-copy[Suppress prompts about copying state data. This is equivalent to providing a "yes" to all confirmation prompts.]' \
150 '-from-module=[Copy the contents of the given module into the target directory before initialization.]:from_module:_files -W __chdir -/' \
151 '-get=[(true) Disable downloading modules for this configuration.]:get:(true false)' \
152 '-input=[(true) Disable interactive prompts. Note that some actions may require interactive prompts and will error if input is disabled.]:input:(true false)' \
153 '-lock=[(true) Don'\''t hold a state lock during backend migration. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
154 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
155 '-no-color[If specified, output will contain no color.]' \
156 '-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 -W __chdir -/' \
157 '-reconfigure[Reconfigure the backend, ignoring any saved configuration.]' \
158 '-migrate-state[Reconfigure a backend, and attempt to migrate any existing state.]' \
159 '-upgrade[Install the latest module and provider versions allowed within configured constraints, overriding the default behavior of selecting exactly the version recorded in the dependency lockfile.]' \
160 '-lockfile=[Set a dependency lockfile mode. Currently only "readonly" is valid.]:lockfile:( readonly )' \
161 '-ignore-remote-version[A rare option used for Terraform Cloud and the remote backend only. Set this to ignore checking that the local and remote Terraform versions use compatible state representations, making an operation proceed even when there is a potential mismatch. See the documentation on configuring Terraform with Terraform Cloud for more information.]' \
162 '-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/'
163}
164
165(( ${+functions[_terraform_login]} )) || _terraform_login() {
166 _arguments \
167 ':hostname:'
168}
169
170(( ${+functions[_terraform_logout]} )) || _terraform_logout() {
171 _arguments \
172 ':hostname:'
173}
174
175(( ${+functions[_terraform_metadata]} )) || _terraform_metadata() {
176 _arguments \
177 '*::terraform metadata command:_terraform_metadata_commands'
178}
179
180(( ${+functions[_terraform_metadata_commands]} )) || _terraform_metadata_commands() {
181 local -a _metadata_cmds
182 _metadata_cmds=(
183 'functions:Show signatures and descriptions for the available functions'
184 )
185 if (( CURRENT == 1 )); then
186 _describe -t commands "terraform metadata commands" _metadata_cmds
187 return
188 fi
189
190 local curcontext="${curcontext}"
191 cmd="${${_metadata_cmds[(r)$words[1]:*]%%:*}}"
192 curcontext="${curcontext%:*:*}:terraform-metadata-${cmd}:"
193
194 if (( ${+functions[_terraform_metadata_$cmd]} )); then
195 "_terraform_metadata_${cmd}"
196 else
197 _message "no more options"
198 fi
199}
200
201(( ${+functions[_terraform_metadata_functions]} )) || _terraform_metadata_functions() {
202 _arguments \
203 '-json[]'
204}
205
206(( ${+functions[_terraform_output]} )) || _terraform_output() {
207 _arguments \
208 '-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate". Ignored when remote state is used.]:statefile:_files -W __chdir -g "*.tfstate"' \
209 '-no-color[If specified, output will contain no color.]' \
210 '-json[If specified, machine readable output will be printed in JSON format]' \
211 '-raw[For value types that can be automatically converted to a string, will print the raw string directly, rather than a human-oriented representation of the value.]' \
212 ':name:'
213}
214
215(( ${+functions[_terraform_plan]} )) || _terraform_plan() {
216 _arguments \
217 '-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.]' \
218 '-destroy[Select the "destroy" planning mode, which creates a plan to destroy all objects currently managed by this Terraform configuration instead of the usual behavior.]' \
219 '-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]' \
220 '-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
221 '-generate-config-out=[(path) (Experimental) If import blocks are present in configuration, instructs Terraform to generate HCL for any imported resources not already present. The configuration is written to a new file at PATH, which must not already exist. Terraform may still attempt to write configuration if the plan errors.]:generate_config_out:' \
222 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
223 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
224 '-no-color[If specified, output will contain no color.]' \
225 '-out=[(path) Write a plan file to the given path. This can be used as input to the "apply" command.]:out:' \
226 '-parallelism=[(10) Limit the number of concurrent operations.]:parallelism:' \
227 '-refresh=[(true) Skip checking for external changes to remote objects while creating the plan. This can potentially make planning faster, but at the expense of possibly planning against a stale record of the remote system state.]:refresh:(true false)' \
228 '-refresh-only[Select the "refresh only" planning mode, which checks whether remote objects still match the outcome of the most recent Terraform apply but does not propose any actions to undo any changes made outside of Terraform.]' \
229 '*-replace=[(resource) Force replacement of a particular resource instance using its resource address. If the plan would'\''ve normally produced an update or no-op action for this instance, Terraform will plan to replace it instead. You can use this option multiple times to replace more than one object.]:replace:__terraform_state_resources' \
230 '-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 -W __chdir -g "*.tfstate"' \
231 '*-target=[(resource) Limit the planning operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \
232 '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
233 '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"'
234}
235
236(( ${+functions[_terraform_providers]} )) || _terraform_providers() {
237 _arguments \
238 '-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \
239 '*::terraform providers command:_terraform_providers_commands'
240}
241
242(( ${+functions[_terraform_providers_commands]} )) || _terraform_providers_commands() {
243 local -a _providers_cmds
244 _providers_cmds=(
245 'lock:Write out dependency locks for the configured providers'
246 'mirror:Save local copies of all required provider plugins'
247 'schema:Show schemas for the providers used in the configuration'
248 )
249 if (( CURRENT == 1 )); then
250 _describe -t commands "terraform providers commands" _providers_cmds
251 return
252 fi
253
254 local curcontext="${curcontext}"
255 cmd="${${_providers_cmds[(r)$words[1]:*]%%:*}}"
256 curcontext="${curcontext%:*:*}:terraform-providers-${cmd}:"
257
258 if (( ${+functions[_terraform_providers_$cmd]} )); then
259 "_terraform_providers_${cmd}"
260 else
261 _message "no more options"
262 fi
263}
264
265(( ${+functions[_terraform_providers_lock]} )) || _terraform_providers_lock() {
266 _arguments \
267 '-fs-mirror=[(dir) Consult the given filesystem mirror directory instead of the origin registry for each of the given providers.]:fs_mirror:_files -W __chdir -/' \
268 '-net-mirror=[(url) Consult the given network mirror (given as a base URL) instead of the origin registry for each of the given providers.]:net_mirror:' \
269 '*-platform=[(os_arch) Choose a target platform to request package checksums for.]:platform:' \
270 '*:provider:'
271}
272
273(( ${+functions[_terraform_providers_mirror]} )) || _terraform_providers_mirror() {
274 _arguments \
275 '*-platform=[(os_arch) Choose which target platform to build a mirror for.]:platform:' \
276 '::' \
277 ':target_dir:_files -W __chdir -/'
278}
279
280(( ${+functions[_terraform_providers_schema]} )) || _terraform_providers_schema() {
281 _arguments \
282 '-json[]'
283}
284
285(( ${+functions[_terraform_refresh]} )) || _terraform_refresh() {
286 _arguments \
287 '-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 -W __chdir -g "*.backup"' \
288 '-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.]' \
289 '-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \
290 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
291 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
292 '-no-color[If specified, output will not contain any color.]' \
293 '-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \
294 '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \
295 '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -W __chdir -g "*.tfstate"' \
296 '*-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:__terraform_state_resources' \
297 '*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]:var:' \
298 '*-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 -W __chdir -g "*.tfvars{,.json}"'
299}
300
301(( ${+functions[_terraform_show]} )) || _terraform_show() {
302 _arguments \
303 '-json[If specified, output the Terraform plan or state in a machine-readable form.]' \
304 '-no-color[If specified, output will not contain any color.]' \
305 ':path:_files -W __chdir -g "*.tfstate"'
306}
307
308(( ${+functions[_terraform_state]} )) || _terraform_state() {
309 _arguments \
310 '*::terraform state command:_terraform_state_commands'
311}
312
313(( ${+functions[_terraform_state_commands]} )) || _terraform_state_commands() {
314 local -a _state_cmds
315 _state_cmds=(
316 'list:List resources in the state'
317 'mv:Move an item in the state'
318 'pull:Pull current state and output to stdout'
319 'push:Update remote state from a local state file'
320 'replace-provider:Replace provider in the state'
321 'rm:Remove instances from the state'
322 'show:Show a resource in the state'
323 )
324 if (( CURRENT == 1 )); then
325 _describe -t commands "terraform state commands" _state_cmds
326 return
327 fi
328
329 local curcontext="${curcontext}"
330 cmd="${${_state_cmds[(r)$words[1]:*]%%:*}}"
331 curcontext="${curcontext%:*:*}:terraform-state-${cmd}:"
332
333 if (( ${+functions[_terraform_state_$cmd]} )); then
334 "_terraform_state_${cmd}"
335 else
336 _message "no more options"
337 fi
338}
339
340(( ${+functions[_terraform_state_list]} )) || _terraform_state_list() {
341 _arguments \
342 '-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.]:statefile:_files -W __chdir -g "*.tfstate"' \
343 '-id=[(id) Filters the results to include only instances whose resource types have an attribute named id whose value equals the given id string.]:id:' \
344 '*:address:__terraform_state_resources'
345}
346
347(( ${+functions[_terraform_state_mv]} )) || _terraform_state_mv() {
348 _arguments \
349 '-dry-run[If set, prints out what would'\''ve been moved but doesn'\''t actually move anything.]' \
350 '-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 -W __chdir -g "*.backup"' \
351 '-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 -W __chdir -g "*.backup"' \
352 '-ignore-remote-version[A rare option used for the remote backend only. See the remote backend documentation for more information.]' \
353 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
354 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
355 '-state=[(path) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -g "*.tfstate"' \
356 '-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 -W __chdir -g "*.tfstate"' \
357 '::' \
358 ':source:__terraform_state_resources' \
359 ':destination: '
360}
361
362(( ${+functions[_terraform_state_push]} )) || _terraform_state_push() {
363 _arguments \
364 '-force[Write the state even if lineages don'\''t match or the remote serial is higher.]' \
365 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
366 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
367 '::' \
368 ':destination:_files'
369}
370
371(( ${+functions[_terraform_state_replace-provider]} )) || _terraform_state_replace-provider() {
372 _arguments \
373 '-auto-approve[Skip interactive approval.]' \
374 '-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 -W __chdir -g "*.backup"' \
375 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
376 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
377 '-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -g "*.tfstate"' \
378 '::' \
379 ':from_provider_fqn:' \
380 ':to_provider_fqn:'
381}
382
383(( ${+functions[_terraform_state_rm]} )) || _terraform_state_rm() {
384 _arguments \
385 '-dry-run[If set, prints out what would'\''ve been removed but doesn'\''t actually remove anything.]' \
386 '-backup=[(PATH) Path where Terraform should write the backup for the original state.]::backupfile:_files -W __chdir -g "*.backup"' \
387 '-ignore-remote-version[Continue even if remote and local Terraform versions are incompatible. This may result in an unusable workspace, and should be used with extreme caution.]' \
388 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
389 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
390 '-state=[(PATH) Path to the state file to update. Defaults to the current workspace state.]:statefile:_files -W __chdir -g "*.tfstate"' \
391 '*:address:__terraform_state_resources'
392}
393
394(( ${+functions[_terraform_state_show]} )) || _terraform_state_show() {
395 _arguments \
396 '-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 -W __chdir -g "*.tfstate"' \
397 "*:address:__terraform_state_resources"
398}
399
400(( ${+functions[__terraform_state_resources]} )) || __terraform_state_resources() {
401 local resource
402 local -a resources
403 terraform -chdir="${__chdir}" state list -state="${opt_args[-state]}" 2>/dev/null | while read -r resource; do
404 resources+=( "${resource}" )
405 done
406 compadd "${@}" - "${resources[@]}"
407}
408
409(( ${+functions[_terraform_taint]} )) || _terraform_taint() {
410 _arguments \
411 '-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
412 '-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 -W __chdir -g "*.backup"' \
413 '-ignore-remote-version[A rare option used for the remote backend only. See the remote backend documentation for more information.]' \
414 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
415 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
416 '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \
417 '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -W __chdir -g "*.tfstate"' \
418 '*:address:__terraform_state_resources'
419}
420
421(( ${+functions[_terraform_test]} )) || _terraform_test() {
422 _arguments \
423 '-cloud-run=[(source) If specified, Terraform will execute this test run remotely using Terraform Cloud. You must specify the source of a module registered in a private module registry as the argument to this flag. This allows Terraform to associate the cloud run with the correct Terraform Cloud module and organization.]:cloud_run:' \
424 '*-filter=[(testfile) If specified, Terraform will only execute the test files specified by this flag. You can use this option multiple times to execute more than one test file.]:testfile:_files -W __chdir -g "*.tftest.hcl"' \
425 '-json[If specified, machine readable output will be printed in JSON format]' \
426 '-no-color[If specified, machine readable output will be printed in JSON format]' \
427 '-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \
428 '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \
429 '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' \
430 '-verbose[Print the plan or state for each test run block as it executes.]' \
431}
432
433(( ${+functions[_terraform_untaint]} )) || _terraform_untaint() {
434 _arguments \
435 '-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
436 '-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 -W __chdir -g "*.backup"' \
437 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
438 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
439 '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \
440 '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -W __chdir -g "*.tfstate"' \
441 ':name:__terraform_state_resources'
442}
443
444(( ${+functions[_terraform_validate]} )) || _terraform_validate() {
445 _arguments \
446 '-json[Produce output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems.]' \
447 '-no-color[If specified, output will not contain any color.]' \
448 '-no-tests[If specified, Terraform will not validate test files.]' \
449 '-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \
450 ':dir:_files -W __chdir -/'
451}
452
453(( ${+functions[_terraform_version]} )) || _terraform_version() {
454 _arguments \
455 '-json[Output the version information as a JSON object.]' \
456 '::'
457}
458
459(( ${+functions[_terraform_workspace]} )) || _terraform_workspace() {
460 _arguments \
461 '*::terraform workspace command:_terraform_workspace_commands'
462}
463
464(( ${+functions[_terraform_workspace_commands]} )) || _terraform_workspace_commands() {
465 local -a _workspace_cmds
466 _workspace_cmds=(
467 'delete:Delete a workspace'
468 'list:List Workspaces'
469 'new:Create a new workspace'
470 'select:Select a workspace'
471 'show:Show the name of the current workspace'
472 )
473 if (( CURRENT == 1 )); then
474 _describe -t commands "terraform workspace commands" _workspace_cmds
475 return
476 fi
477
478 local curcontext="${curcontext}"
479 cmd="${${_workspace_cmds[(r)$words[1]:*]%%:*}}"
480 curcontext="${curcontext%:*:*}:terraform-workspace-${cmd}:"
481
482 if (( ${+functions[_terraform_workspace_$cmd]} )); then
483 "_terraform_workspace_${cmd}"
484 else
485 _message "no more options"
486 fi
487}
488
489(( ${+functions[_terraform_workspace_delete]} )) || _terraform_workspace_delete() {
490 _arguments \
491 '-force[Remove a workspace even if it is managing resources. Terraform can no longer track or manage the workspace'\''s infrastructure.]' \
492 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
493 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
494 '::' \
495 ':name:__terraform_workspaces'
496}
497
498(( ${+functions[_terraform_workspace_list]} )) || _terraform_workspace_list() {
499 _arguments
500}
501
502(( ${+functions[_terraform_workspace_new]} )) || _terraform_workspace_new() {
503 _arguments \
504 '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \
505 '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \
506 '-state=[(path) Copy an existing state file into the new workspace.]:statefile:_files -W __chdir -g "*.tfstate"' \
507 '::' \
508 ':name:'
509}
510
511(( ${+functions[_terraform_workspace_select]} )) || _terraform_workspace_select() {
512 _arguments \
513 '-or-create=[(false) Create the Terraform workspace if it doesn'\''t exist.]:or_create:(true false)' \
514 '::' \
515 ':name:__terraform_workspaces'
516}
517
518(( ${+functions[_terraform_workspace_show]} )) || _terraform_workspace_show() {
519 _arguments
520}
521
522(( ${+functions[__terraform_workspaces]} )) || __terraform_workspaces() {
523 local workspace
524 local -a workspaces
525 terraform -chdir="${__chdir}" workspace list | while read -r workspace; do
526 if [[ -z "${workspace}" ]]; then
527 continue
528 fi
529 workspaces+=( "${workspace#[ *] }" )
530 done
531 compadd "${@}" - "${workspaces[@]}"
532}
533
534_terraform() {
535 _arguments \
536 '-chdir=[(DIR) Switch to a different working directory before executing the given subcommand.]:chdir:_files -W __chdir -/' \
537 '-help[Show this help output, or the help for a specified subcommand.]' \
538 '-version[An alias for the "version" subcommand.]' \
539 '*::terraform command:_terraform_commands'
540}
541
542# don't run the completion function when being source-ed or eval-ed
543if [ "${funcstack[1]}" = '_terraform' ]; then
544 _terraform
545fi