github.com/pulumi/terraform@v1.4.0/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    metadata      Metadata related commands
    47    output        Show output values from your root module
    48    providers     Show the providers required for this configuration
    49    refresh       Update the state to match remote systems
    50    show          Show the current state or a saved plan
    51    state         Advanced state management
    52    taint         Mark a resource instance as not fully functional
    53    untaint       Remove the 'tainted' state from a resource instance
    54    version       Show the current Terraform version
    55    workspace     Workspace management
    56  
    57  Global options (use these before the subcommand, if any):
    58    -chdir=DIR    Switch to a different working directory before executing the
    59                  given subcommand.
    60    -help         Show this help output, or the help for a specified subcommand.
    61    -version      An alias for the "version" subcommand.
    62  ```
    63  
    64  (The output from your current Terraform version may be different than the
    65  above example.)
    66  
    67  To get specific help for any specific command, use the `-help` option with the
    68  relevant subcommand. For example, to see help about the "validate" subcommand
    69  you can run `terraform validate -help`.
    70  
    71  The inline help built in to Terraform CLI describes the most important
    72  characteristics of each command. For more detailed information, refer to each
    73  command's page for details.
    74  
    75  ## Switching working directory with `-chdir`
    76  
    77  The usual way to run Terraform is to first switch to the directory containing
    78  the `.tf` files for your root module (for example, using the `cd` command), so
    79  that Terraform will find those files automatically without any extra arguments.
    80  
    81  In some cases though — particularly when wrapping Terraform in automation
    82  scripts — it can be convenient to run Terraform from a different directory than
    83  the root module directory. To allow that, Terraform supports a global option
    84  `-chdir=...` which you can include before the name of the subcommand you intend
    85  to run:
    86  
    87  ```
    88  terraform -chdir=environments/production apply
    89  ```
    90  
    91  The `chdir` option instructs Terraform to change its working directory to the
    92  given directory before running the given subcommand. This means that any files
    93  that Terraform would normally read or write in the current working directory
    94  will be read or written in the given directory instead.
    95  
    96  There are two exceptions where Terraform will use the original working directory
    97  even when you specify `-chdir=...`:
    98  
    99  * Settings in the [CLI Configuration](/cli/config/config-file) are not for a specific
   100    subcommand and Terraform processes them before acting on the `-chdir`
   101    option.
   102  
   103  * In case you need to use files from the original working directory as part
   104    of your configuration, a reference to `path.cwd` in the configuration will
   105    produce the original working directory instead of the overridden working
   106    directory. Use `path.root` to get the root module directory.
   107  
   108  ## Shell Tab-completion
   109  
   110  If you use either `bash` or `zsh` as your command shell, Terraform can provide
   111  tab-completion support for all command names and some command 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  ## Upgrade and Security Bulletin Checks
   130  
   131  The Terraform CLI commands interact with the HashiCorp service
   132  [Checkpoint](https://checkpoint.hashicorp.com/) to check for the availability
   133  of new versions and for critical security bulletins about the current version.
   134  
   135  One place where the effect of this can be seen is in `terraform version`, where
   136  it is used by default to indicate in the output when a newer version is
   137  available.
   138  
   139  Only anonymous information, which cannot be used to identify the user or host,
   140  is sent to Checkpoint. An anonymous ID is sent which helps de-duplicate warning
   141  messages. Both the anonymous id and the use of checkpoint itself are completely
   142  optional and can be disabled.
   143  
   144  Checkpoint itself can be entirely disabled for all HashiCorp products by
   145  setting the environment variable `CHECKPOINT_DISABLE` to any non-empty value.
   146  
   147  Alternatively, settings in
   148  [the CLI configuration file](/cli/config/config-file) can be used to
   149  disable checkpoint features. The following checkpoint-related settings are
   150  supported in this file:
   151  
   152  * `disable_checkpoint` - set to `true` to disable checkpoint calls
   153    entirely. This is similar to the `CHECKPOINT_DISABLE` environment variable
   154    described above.
   155  
   156  * `disable_checkpoint_signature` - set to `true` to disable the use of an
   157    anonymous signature in checkpoint requests. This allows Terraform to check
   158    for security bulletins but does not send the anonymous signature in these
   159    requests.
   160  
   161  [The Checkpoint client code](https://github.com/hashicorp/go-checkpoint) used
   162  by Terraform is available for review by any interested party.