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