_terraform 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #compdef terraform
  2. local -a _terraform_cmds
  3. _terraform_cmds=(
  4. 'apply:Builds or changes infrastructure'
  5. 'destroy:Destroy Terraform-managed infrastructure'
  6. 'get:Download and install modules for the configuration'
  7. 'graph:Create a visual graph of Terraform resources'
  8. 'init:Initializes Terraform configuration from a module'
  9. 'output:Read an output from a state file'
  10. 'plan:Generate and show an execution plan'
  11. 'pull:Refreshes the local state copy from the remote server'
  12. 'push:Uploads the local state to the remote server'
  13. 'refresh:Update local state file against real resources'
  14. 'remote:Configures remote state management'
  15. 'taint:Manually forcing a destroy and recreate on the next plan/apply'
  16. 'show:Inspect Terraform state or plan'
  17. 'version:Prints the Terraform version'
  18. )
  19. __apply() {
  20. _arguments \
  21. '-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.]' \
  22. '-input=[(true) Ask for input for variables if not directly set.]' \
  23. '-no-color[If specified, output will not contain any color.]' \
  24. '-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
  25. '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
  26. '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]' \
  27. '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
  28. '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
  29. }
  30. __destroy() {
  31. _arguments \
  32. '-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.]' \
  33. '-force[Do not ask for input for destroy confirmation.]' \
  34. '-no-color[If specified, output will not contain any color.]' \
  35. '-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
  36. '-state=[Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
  37. '-state-out=[Path to write state to that is different than "-state". This can be used to preserve the old state.]' \
  38. '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
  39. '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
  40. }
  41. __get() {
  42. _arguments \
  43. '-update=[(false) If true, modules already downloaded will be checked for updates and updated if necessary.]'
  44. }
  45. __graph() {
  46. _arguments \
  47. '-module-depth=[(n) The maximum depth to expand modules. By default this is zero, which will not expand modules at all.]'
  48. }
  49. __init() {
  50. _arguments \
  51. '-address=[(url) URL of the remote storage server. Required for HTTP backend, optional for Atlas and Consul.]' \
  52. '-access-token=[(token) Authentication token for state storage server. Required for Atlas backend, optional for Consul.]' \
  53. '-backend=[(atlas) Specifies the type of remote backend. Must be one of Atlas, Consul, or HTTP. Defaults to atlas.]' \
  54. '-name=[(name) Name of the state file in the state storage server. Required for Atlas backend.]' \
  55. '-path=[(path) Path of the remote state in Consul. Required for the Consul backend.]'
  56. }
  57. __output() {
  58. _arguments \
  59. '-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate".]'
  60. }
  61. __plan() {
  62. _arguments \
  63. '-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.]' \
  64. '-destroy[If set, a plan will be generated to destroy all resources managed by the given configuration and state.]' \
  65. '-input=[(true) Ask for input for variables if not directly set.]' \
  66. '-module-depth=[(n) Specifies the depth of modules to show in the output. This does not affect the plan itself, only the output shown. By default, this is zero. -1 will expand all.]' \
  67. '-no-color[If specified, output will not contain any color.]' \
  68. '-out=[(path) Write a plan file to the given path. This can be used as input to the "apply" command.]' \
  69. '-refresh=[(true) Update state prior to checking for differences.]' \
  70. '-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.]' \
  71. '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
  72. '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
  73. }
  74. __push() {
  75. _arguments \
  76. '-force[Forces the upload of the local state, ignoring any conflicts. This should be used carefully, as force pushing can cause remote state information to be lost.]'
  77. }
  78. __refresh() {
  79. _arguments \
  80. '-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.]' \
  81. '-input=[(true) Ask for input for variables if not directly set.]' \
  82. '-no-color[If specified, output will not contain any color.]' \
  83. '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
  84. '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]' \
  85. '-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
  86. '-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
  87. }
  88. __taint() {
  89. _arguments \
  90. '-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
  91. '-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.]' \
  92. '-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).]' \
  93. '-no-color[If specified, output will not contain any color.]' \
  94. '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
  95. '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]'
  96. }
  97. __remote() {
  98. _arguments \
  99. '-address=[(url) URL of the remote storage server. Required for HTTP backend, optional for Atlas and Consul.]' \
  100. '-access-token=[(token) Authentication token for state storage server. Required for Atlas backend, optional for Consul.]' \
  101. '-backend=[(atlas) Specifies the type of remote backend. Must be one of Atlas, Consul, or HTTP. Defaults to atlas.]' \
  102. '-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.]' \
  103. '-disable[Disables remote state management and migrates the state to the -state path.]' \
  104. '-name=[(name) Name of the state file in the state storage server. Required for Atlas backend.]' \
  105. '-path=[(path) Path of the remote state in Consul. Required for the Consul backend.]' \
  106. '-pull=[(true) Controls if the remote state is pulled before disabling. This defaults to true to ensure the latest state is cached before disabling.]' \
  107. '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]'
  108. }
  109. __show() {
  110. _arguments \
  111. '-module-depth=[(n) The maximum depth to expand modules. By default this is zero, which will not expand modules at all.]' \
  112. '-no-color[If specified, output will not contain any color.]'
  113. }
  114. _arguments '*:: :->command'
  115. if (( CURRENT == 1 )); then
  116. _describe -t commands "terraform command" _terraform_cmds
  117. return
  118. fi
  119. local -a _command_args
  120. case "$words[1]" in
  121. apply)
  122. __apply ;;
  123. destroy)
  124. __destroy ;;
  125. get)
  126. __get ;;
  127. graph)
  128. __graph ;;
  129. init)
  130. __init ;;
  131. output)
  132. __output ;;
  133. plan)
  134. __plan ;;
  135. push)
  136. __push ;;
  137. refresh)
  138. __refresh ;;
  139. remote)
  140. __remote ;;
  141. show)
  142. __show ;;
  143. taint)
  144. __taint ;;
  145. esac