github.com/jaredpalmer/terraform@v1.1.0-alpha20210908.0.20210911170307-88705c943a03/website/docs/cli/commands/index.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Basic CLI Features" 4 sidebar_current: "docs-commands" 5 description: "An introduction to the terraform command and its available subcommands." 6 --- 7 8 # Basic CLI Features 9 10 > **Hands-on:** Try the [Terraform: Get Started](https://learn.hashicorp.com/collections/terraform/aws-get-started?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) collection on HashiCorp Learn. 11 12 The command line interface to Terraform is via the `terraform` command, which 13 accepts a variety of subcommands such as `terraform init` or `terraform plan`. 14 A full list of all of the supported subcommands is in the navigation section 15 of this page. 16 17 We refer to the `terraform` command line tool as "Terraform CLI" elsewhere 18 in the documentation. This terminology is often used to distinguish it from 19 other components you might use in the Terraform product family, such as 20 [Terraform Cloud](/docs/cloud/) or 21 the various [Terraform providers](/docs/language/providers/index.html), which 22 are developed and released separately from Terraform CLI. 23 24 To view a list of the commands available in your current Terraform version, 25 run `terraform` with no additional arguments: 26 27 ```text 28 Usage: terraform [global options] <subcommand> [args] 29 30 The available commands for execution are listed below. 31 The primary workflow commands are given first, followed by 32 less common or more advanced commands. 33 34 Main commands: 35 init Prepare your working directory for other commands 36 validate Check whether the configuration is valid 37 plan Show changes required by the current configuration 38 apply Create or update infrastructure 39 destroy Destroy previously-created infrastructure 40 41 All other commands: 42 add Generate a resource configuration template 43 console Try Terraform expressions at an interactive command prompt 44 fmt Reformat your configuration in the standard style 45 force-unlock Release a stuck lock on the current workspace 46 get Install or upgrade remote Terraform modules 47 graph Generate a Graphviz graph of the steps in an operation 48 import Associate existing infrastructure with a Terraform resource 49 login Obtain and save credentials for a remote host 50 logout Remove locally-stored credentials for a remote host 51 output Show output values from your root module 52 providers Show the providers required for this configuration 53 refresh Update the state to match remote systems 54 show Show the current state or a saved plan 55 state Advanced state management 56 taint Mark a resource instance as not fully functional 57 untaint Remove the 'tainted' state from a resource instance 58 version Show the current Terraform version 59 workspace Workspace management 60 61 Global options (use these before the subcommand, if any): 62 -chdir=DIR Switch to a different working directory before executing the 63 given subcommand. 64 -help Show this help output, or the help for a specified subcommand. 65 -version An alias for the "version" subcommand. 66 ``` 67 68 (The output from your current Terraform version may be different than the 69 above example.) 70 71 To get specific help for any specific command, use the `-help` option with the 72 relevant subcommand. For example, to see help about the "validate" subcommand 73 you can run `terraform validate -help`. 74 75 The inline help built in to Terraform CLI describes the most important 76 characteristics of each command. For more detailed information, refer to each 77 command's section of this documentation, available in the navigation 78 section of this page. 79 80 ## Switching working directory with `-chdir` 81 82 The usual way to run Terraform is to first switch to the directory containing 83 the `.tf` files for your root module (for example, using the `cd` command), so 84 that Terraform will find those files automatically without any extra arguments. 85 86 In some cases though — particularly when wrapping Terraform in automation 87 scripts — it can be convenient to run Terraform from a different directory than 88 the root module directory. To allow that, Terraform supports a global option 89 `-chdir=...` which you can include before the name of the subcommand you intend 90 to run: 91 92 ``` 93 terraform -chdir=environments/production apply 94 ``` 95 96 The `chdir` option instructs Terraform to change its working directory to the 97 given directory before running the given subcommand. This means that any files 98 that Terraform would normally read or write in the current working directory 99 will be read or written in the given directory instead. 100 101 There are two exceptions where Terraform will use the original working directory 102 even when you specify `-chdir=...`: 103 104 * Settings in the [CLI Configuration](/docs/cli/config/config-file.html) are not for a specific 105 subcommand and Terraform processes them before acting on the `-chdir` 106 option. 107 108 * In case you need to use files from the original working directory as part 109 of your configuration, a reference to `path.cwd` in the configuration will 110 produce the original working directory instead of the overridden working 111 directory. Use `path.root` to get the root module directory. 112 113 ## Shell Tab-completion 114 115 If you use either `bash` or `zsh` as your command shell, Terraform can provide 116 tab-completion support for all command names and (at this time) _some_ command 117 arguments. 118 119 To add the necessary commands to your shell profile, run the following command: 120 121 ```bash 122 terraform -install-autocomplete 123 ``` 124 125 After installation, it is necessary to restart your shell or to re-read its 126 profile script before completion will be activated. 127 128 To uninstall the completion hook, assuming that it has not been modified 129 manually in the shell profile, run the following command: 130 131 ```bash 132 terraform -uninstall-autocomplete 133 ``` 134 135 Currently not all of Terraform's subcommands have full tab-completion support 136 for all arguments. We plan to improve tab-completion coverage over time. 137 138 ## Upgrade and Security Bulletin Checks 139 140 The Terraform CLI commands interact with the HashiCorp service 141 [Checkpoint](https://checkpoint.hashicorp.com/) to check for the availability 142 of new versions and for critical security bulletins about the current version. 143 144 One place where the effect of this can be seen is in `terraform version`, where 145 it is used by default to indicate in the output when a newer version is 146 available. 147 148 Only anonymous information, which cannot be used to identify the user or host, 149 is sent to Checkpoint. An anonymous ID is sent which helps de-duplicate warning 150 messages. Both the anonymous id and the use of checkpoint itself are completely 151 optional and can be disabled. 152 153 Checkpoint itself can be entirely disabled for all HashiCorp products by 154 setting the environment variable `CHECKPOINT_DISABLE` to any non-empty value. 155 156 Alternatively, settings in 157 [the CLI configuration file](/docs/cli/config/config-file.html) can be used to 158 disable checkpoint features. The following checkpoint-related settings are 159 supported in this file: 160 161 * `disable_checkpoint` - set to `true` to disable checkpoint calls 162 entirely. This is similar to the `CHECKPOINT_DISABLE` environment variable 163 described above. 164 165 * `disable_checkpoint_signature` - set to `true` to disable the use of an 166 anonymous signature in checkpoint requests. This allows Terraform to check 167 for security bulletins but does not send the anonymous signature in these 168 requests. 169 170 [The Checkpoint client code](https://github.com/hashicorp/go-checkpoint) used 171 by Terraform is available for review by any interested party.