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