github.com/hugorut/terraform@v1.1.3/website/docs/cli/config/config-file.mdx (about)

     1  ---
     2  page_title: CLI Configuration
     3  description: >-
     4    Learn to use the CLI configuration file to customize your CLI settings,
     5    including credentials, plugin caching, provider installation methods, etc.
     6  ---
     7  
     8  # CLI Configuration File (`.terraformrc` or `terraform.rc`)
     9  
    10  The CLI configuration file configures per-user settings for CLI behaviors,
    11  which apply across all Terraform working directories. This is separate from
    12  [your infrastructure configuration](/language).
    13  
    14  ## Locations
    15  
    16  The configuration can be placed in a single file whose location depends
    17  on the host operating system:
    18  
    19  * On Windows, the file must be named `terraform.rc` and placed
    20    in the relevant user's `%APPDATA%` directory. The physical location
    21    of this directory depends on your Windows version and system configuration;
    22    use `$env:APPDATA` in PowerShell to find its location on your system.
    23  * On all other systems, the file must be named `.terraformrc` (note
    24    the leading period) and placed directly in the home directory
    25    of the relevant user.
    26  
    27  On Windows, beware of Windows Explorer's default behavior of hiding filename
    28  extensions. Terraform will not recognize a file named `terraform.rc.txt` as a
    29  CLI configuration file, even though Windows Explorer may _display_ its name
    30  as just `terraform.rc`. Use `dir` from PowerShell or Command Prompt to
    31  confirm the filename.
    32  
    33  The location of the Terraform CLI configuration file can also be specified
    34  using the `TF_CLI_CONFIG_FILE` [environment variable](/cli/config/environment-variables).
    35  Any such file should follow the naming pattern `*.tfrc`.
    36  
    37  ## Configuration File Syntax
    38  
    39  The configuration file uses the same _HCL_ syntax as `.tf` files, but with
    40  different attributes and blocks. The following example illustrates the
    41  general syntax; see the following section for information on the meaning
    42  of each of these settings:
    43  
    44  ```hcl
    45  plugin_cache_dir   = "$HOME/.terraform.d/plugin-cache"
    46  disable_checkpoint = true
    47  ```
    48  
    49  ## Available Settings
    50  
    51  The following settings can be set in the CLI configuration file:
    52  
    53  * `credentials` - configures credentials for use with Terraform Cloud or
    54    Terraform Enterprise. See [Credentials](#credentials) below for more
    55    information.
    56  
    57  * `credentials_helper` - configures an external helper program for the storage
    58    and retrieval of credentials for Terraform Cloud or Terraform Enterprise.
    59    See [Credentials Helpers](#credentials-helpers) below for more information.
    60  
    61  * `disable_checkpoint` — when set to `true`, disables
    62    [upgrade and security bulletin checks](/cli/commands#upgrade-and-security-bulletin-checks)
    63    that require reaching out to HashiCorp-provided network services.
    64  
    65  * `disable_checkpoint_signature` — when set to `true`, allows the upgrade and
    66    security bulletin checks described above but disables the use of an anonymous
    67    id used to de-duplicate warning messages.
    68  
    69  * `plugin_cache_dir` — enables
    70    [plugin caching](#provider-plugin-cache)
    71    and specifies, as a string, the location of the plugin cache directory.
    72  
    73  * `provider_installation` - customizes the installation methods used by
    74    `terraform init` when installing provider plugins. See
    75    [Provider Installation](#provider-installation) below for more information.
    76  
    77  ## Credentials
    78  
    79  [Terraform Cloud](/cloud) provides a number of remote network
    80  services for use with Terraform, and
    81  [Terraform Enterprise](/enterprise) allows hosting those
    82  services inside your own infrastructure. For example, these systems offer both
    83  [remote operations](/cloud-docs/run/cli) and a
    84  [private module registry](/cloud-docs/registry).
    85  
    86  When interacting with Terraform-specific network services, Terraform expects
    87  to find API tokens in CLI configuration files in `credentials` blocks:
    88  
    89  ```hcl
    90  credentials "app.terraform.io" {
    91    token = "xxxxxx.atlasv1.zzzzzzzzzzzzz"
    92  }
    93  ```
    94  
    95  If you are running the Terraform CLI interactively on a computer with a web browser, you can use [the `terraform login` command](/cli/commands/login)
    96  to get credentials and automatically save them in the CLI configuration. If
    97  not, you can manually write `credentials` blocks.
    98  
    99  You can have multiple `credentials` blocks if you regularly use services from
   100  multiple hosts. Many users will configure only one, for either
   101  Terraform Cloud (at `app.terraform.io`) or for their organization's own
   102  Terraform Enterprise host. Each `credentials` block contains a `token` argument
   103  giving the API token to use for that host.
   104  
   105  ~> **Important:** If you are using Terraform Cloud or Terraform Enterprise,
   106  the token provided must be either a
   107  [user token](/cloud-docs/users-teams-organizations/users#api-tokens)
   108  or a
   109  [team token](/cloud-docs/users-teams-organizations/api-tokens#team-api-tokens);
   110  organization tokens cannot be used for command-line Terraform actions.
   111  
   112  -> **Note:** The credentials hostname must match the hostname in your module
   113  sources and/or backend configuration. If your Terraform Enterprise instance
   114  is available at multiple hostnames, use only one of them consistently.
   115  Terraform Cloud responds to API calls at both its current hostname
   116  `app.terraform.io`, and its historical hostname `atlas.hashicorp.com`.
   117  
   118  ### Credentials Helpers
   119  
   120  If you would prefer not to store your API tokens directly in the CLI
   121  configuration as described in the previous section, you can optionally instruct
   122  Terraform to use a different credentials storage mechanism by configuring a
   123  special kind of plugin program called a _credentials helper_.
   124  
   125  ```hcl
   126  credentials_helper "example" {
   127    args = []
   128  }
   129  ```
   130  
   131  `credentials_helper` is a configuration block that can appear at most once
   132  in the CLI configuration. Its label (`"example"` above) is the name of the
   133  credentials helper to use. The `args` argument is optional and allows passing
   134  additional arguments to the helper program, for example if it needs to be
   135  configured with the address of a remote host to access for credentials.
   136  
   137  A configured credentials helper will be consulted only to retrieve credentials
   138  for hosts that are _not_ explicitly configured in a `credentials` block as
   139  described in the previous section.
   140  Conversely, this means you can override the credentials returned by the helper
   141  for a specific hostname by writing a `credentials` block alongside the
   142  `credentials_helper` block.
   143  
   144  Terraform does not include any credentials helpers in the main distribution.
   145  To learn how to write and install your own credentials helpers to integrate
   146  with existing in-house credentials management systems, see
   147  [the guide to Credentials Helper internals](/internals/credentials-helpers).
   148  
   149  ## Provider Installation
   150  
   151  The default way to install provider plugins is from a provider registry. The
   152  origin registry for a provider is encoded in the provider's source address,
   153  like `registry.terraform.io/hashicorp/aws`. For convenience in the common case,
   154  Terraform allows omitting the hostname portion for providers on
   155  `registry.terraform.io`, so you can write shorter public provider addresses like
   156  `hashicorp/aws`.
   157  
   158  Downloading a plugin directly from its origin registry is not always
   159  appropriate, though. For example, the system where you are running Terraform
   160  may not be able to access an origin registry due to firewall restrictions
   161  within your organization or your locality.
   162  
   163  To allow using Terraform providers in these situations, there are some
   164  alternative options for making provider plugins available to Terraform which
   165  we'll describe in the following sections.
   166  
   167  ### Explicit Installation Method Configuration
   168  
   169  A `provider_installation` block in the CLI configuration allows overriding
   170  Terraform's default installation behaviors, so you can force Terraform to use
   171  a local mirror for some or all of the providers you intend to use.
   172  
   173  The general structure of a `provider_installation` block is as follows:
   174  
   175  ```hcl
   176  provider_installation {
   177    filesystem_mirror {
   178      path    = "/usr/share/terraform/providers"
   179      include = ["example.com/*/*"]
   180    }
   181    direct {
   182      exclude = ["example.com/*/*"]
   183    }
   184  }
   185  ```
   186  
   187  Each of the nested blocks inside the `provider_installation` block specifies
   188  one installation method. Each installation method can take both `include`
   189  and `exclude` patterns that specify which providers a particular installation
   190  method can be used for. In the example above, we specify that any provider
   191  whose origin registry is at `example.com` can be installed only from the
   192  filesystem mirror at `/usr/share/terraform/providers`, while all other
   193  providers can be installed only directly from their origin registries.
   194  
   195  If you set both `include` and `exclude` for a particular installation
   196  method, the exclusion patterns take priority. For example, including
   197  `registry.terraform.io/hashicorp/*` but also excluding
   198  `registry.terraform.io/hashicorp/dns` will make that installation method apply
   199  to everything in the `hashicorp` namespace with the exception of
   200  `hashicorp/dns`.
   201  
   202  As with provider source addresses in the main configuration, you can omit
   203  the `registry.terraform.io/` prefix for providers distributed through the
   204  public Terraform registry, even when using wildcards. For example,
   205  `registry.terraform.io/hashicorp/*` and `hashicorp/*` are equivalent.
   206  `*/*` is a shorthand for `registry.terraform.io/*/*`, not for
   207  `*/*/*`.
   208  
   209  The following are the two supported installation method types:
   210  
   211  * `direct`: request information about the provider directly from its origin
   212    registry and download over the network from the location that registry
   213    indicates. This method expects no additional arguments.
   214  
   215  * `filesystem_mirror`: consult a directory on the local disk for copies of
   216    providers. This method requires the additional argument `path` to indicate
   217    which directory to look in.
   218  
   219    Terraform expects the given directory to contain a nested directory structure
   220    where the path segments together provide metadata about the available
   221    providers. The following two directory structures are supported:
   222  
   223    * Packed layout: `HOSTNAME/NAMESPACE/TYPE/terraform-provider-TYPE_VERSION_TARGET.zip`
   224      is the distribution zip file obtained from the provider's origin registry.
   225    * Unpacked layout: `HOSTNAME/NAMESPACE/TYPE/VERSION/TARGET` is a directory
   226      containing the result of extracting the provider's distribution zip file.
   227  
   228    In both layouts, the `VERSION` is a string like `2.0.0` and the `TARGET`
   229    specifies a particular target platform using a format like `darwin_amd64`,
   230    `linux_arm`, `windows_amd64`, etc.
   231  
   232    If you use the unpacked layout, Terraform will attempt to create a symbolic
   233    link to the mirror directory when installing the provider, rather than
   234    creating a deep copy of the directory. The packed layout prevents this
   235    because Terraform must extract the zip file during installation.
   236  
   237    You can include multiple `filesystem_mirror` blocks in order to specify
   238    several different directories to search.
   239  
   240  * `network_mirror`: consult a particular HTTPS server for copies of providers,
   241    regardless of which registry host they belong to. This method requires the
   242    additional argument `url` to indicate the mirror base URL, which should
   243    use the `https:` scheme and end with a trailing slash.
   244  
   245    Terraform expects the given URL to be a base URL for an implementation of
   246    [the provider network mirror protocol](/internals/provider-network-mirror-protocol),
   247    which is designed to be relatively easy to implement using typical static
   248    website hosting mechanisms.
   249  
   250  ~> **Warning:** Don't configure `network_mirror` URLs that you do not trust.
   251  Provider mirror servers are subject to TLS certificate checks to verify
   252  identity, but a network mirror with a TLS certificate can potentially serve
   253  modified copies of upstream providers with malicious content.
   254  
   255  Terraform will try all of the specified methods whose include and exclude
   256  patterns match a given provider, and select the newest version available across
   257  all of those methods that matches the version constraint given in each
   258  Terraform configuration. If you have a local mirror of a particular provider
   259  and intend Terraform to use that local mirror exclusively, you must either
   260  remove the `direct` installation method altogether or use its `exclude`
   261  argument to disable its use for specific providers.
   262  
   263  ### Implied Local Mirror Directories
   264  
   265  If your CLI configuration does not include a `provider_installation` block at
   266  all, Terraform produces an _implied_ configuration. The implied configuration
   267  includes a selection of `filesystem_mirror` methods and then the `direct`
   268  method.
   269  
   270  The set of directories Terraform can select as filesystem mirrors depends on
   271  the operating system where you are running Terraform:
   272  
   273  * **Windows:** `%APPDATA%/terraform.d/plugins` and `%APPDATA%/HashiCorp/Terraform/plugins`
   274  * **Mac OS X:** `$HOME/.terraform.d/plugins`,
   275    `~/Library/Application Support/io.terraform/plugins`, and
   276    `/Library/Application Support/io.terraform/plugins`
   277  * **Linux and other Unix-like systems**:`$HOME/.terraform.d/plugins` and
   278    `terraform/plugins` located within a valid
   279    [XDG Base Directory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
   280    data directory such as `$XDG_DATA_HOME/terraform/plugins`.
   281    Without any XDG environment variables set, Terraform will use
   282    `~/.local/share/terraform/plugins`,
   283    `/usr/local/share/terraform/plugins`, and `/usr/share/terraform/plugins`.
   284  
   285  If a `terraform.d/plugins` directory exists in the current working directory
   286  then Terraform will also include that directory, regardless of your operating
   287  system.
   288  
   289  Terraform will check each of the paths above to see if it exists, and if so
   290  treat it as a filesystem mirror. The directory structure inside each one must
   291  therefore match one of the two structures described for `filesystem_mirror`
   292  blocks in [Explicit Installation Method Configuration](#explicit-installation-method-configuration).
   293  
   294  In addition to the zero or more implied `filesystem_mirror` blocks, Terraform
   295  also creates an implied `direct` block. Terraform will scan all of the
   296  filesystem mirror directories to see which providers are placed there and
   297  automatically exclude all of those providers from the implied `direct` block.
   298  (This automatic `exclude` behavior applies only to _implicit_ `direct` blocks;
   299  if you use explicit `provider_installation` you will need to write the intended
   300  exclusions out yourself.)
   301  
   302  ### Provider Plugin Cache
   303  
   304  By default, `terraform init` downloads plugins into a subdirectory of the
   305  working directory so that each working directory is self-contained. As a
   306  consequence, if you have multiple configurations that use the same provider
   307  then a separate copy of its plugin will be downloaded for each configuration.
   308  
   309  Given that provider plugins can be quite large (on the order of hundreds of
   310  megabytes), this default behavior can be inconvenient for those with slow
   311  or metered Internet connections. Therefore Terraform optionally allows the
   312  use of a local directory as a shared plugin cache, which then allows each
   313  distinct plugin binary to be downloaded only once.
   314  
   315  To enable the plugin cache, use the `plugin_cache_dir` setting in
   316  the CLI configuration file. For example:
   317  
   318  ```hcl
   319  plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
   320  ```
   321  
   322  This directory must already exist before Terraform will cache plugins;
   323  Terraform will not create the directory itself.
   324  
   325  Please note that on Windows it is necessary to use forward slash separators
   326  (`/`) rather than the conventional backslash (`\`) since the configuration
   327  file parser considers a backslash to begin an escape sequence.
   328  
   329  Setting this in the configuration file is the recommended approach for a
   330  persistent setting. Alternatively, the `TF_PLUGIN_CACHE_DIR` environment
   331  variable can be used to enable caching or to override an existing cache
   332  directory within a particular shell session:
   333  
   334  ```bash
   335  export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache"
   336  ```
   337  
   338  When a plugin cache directory is enabled, the `terraform init` command will
   339  still use the configured or implied installation methods to obtain metadata
   340  about which plugins are available, but once a suitable version has been
   341  selected it will first check to see if the chosen plugin is already available
   342  in the cache directory. If so, Terraform will use the previously-downloaded
   343  copy.
   344  
   345  If the selected plugin is not already in the cache, Terraform will download
   346  it into the cache first and then copy it from there into the correct location
   347  under your current working directory. When possible Terraform will use
   348  symbolic links to avoid storing a separate copy of a cached plugin in multiple
   349  directories.
   350  
   351  The plugin cache directory _must not_ also be one of the configured or implied
   352  filesystem mirror directories, since the cache management logic conflicts with
   353  the filesystem mirror logic when operating on the same directory.
   354  
   355  Terraform will never itself delete a plugin from the plugin cache once it has
   356  been placed there. Over time, as plugins are upgraded, the cache directory may
   357  grow to contain several unused versions which you must delete manually.
   358  
   359  -> **Note:** The plugin cache directory is not guaranteed to be concurrency
   360  safe. The provider installer's behavior in environments with multiple `terraform
   361  init` calls is undefined.
   362  
   363  ### Development Overrides for Provider Developers
   364  
   365  -> **Note:** Development overrides work only in Terraform v0.14 and later.
   366  Using a `dev_overrides` block in your CLI configuration will cause Terraform
   367  v0.13 to reject the configuration as invalid.
   368  
   369  Normally Terraform verifies version selections and checksums for providers
   370  in order to help ensure that all operations are made with the intended version
   371  of a provider, and that authors can gradually upgrade to newer provider versions
   372  in a controlled manner.
   373  
   374  These version and checksum rules are inconvenient when developing a provider
   375  though, because we often want to try a test configuration against a development
   376  build of a provider that doesn't even have an associated version number yet,
   377  and doesn't have an official set of checksums listed in a provider registry.
   378  
   379  As a convenience for provider development, Terraform supports a special
   380  additional block `dev_overrides` in `provider_installation` blocks. The contents
   381  of this block effectively override all of the other configured installation
   382  methods, so a block of this type must always appear first in the sequence:
   383  
   384  ```hcl
   385  provider_installation {
   386  
   387    # Use /home/developer/tmp/terraform-null as an overridden package directory
   388    # for the hashicorp/null provider. This disables the version and checksum
   389    # verifications for this provider and forces Terraform to look for the
   390    # null provider plugin in the given directory.
   391    dev_overrides {
   392      "hashicorp/null" = "/home/developer/tmp/terraform-null"
   393    }
   394  
   395    # For all other providers, install them directly from their origin provider
   396    # registries as normal. If you omit this, Terraform will _only_ use
   397    # the dev_overrides block, and so no other providers will be available.
   398    direct {}
   399  }
   400  ```
   401  
   402  With development overrides in effect, the `terraform init` command will still
   403  attempt to select a suitable published version of your provider to install and
   404  record in
   405  [the dependency lock file](/language/files/dependency-lock)
   406  for future use, but other commands like
   407  `terraform apply` will disregard the lock file's entry for `hashicorp/null` and
   408  will use the given directory instead. Once your new changes are included in a
   409  published release of the provider, you can use `terraform init -upgrade` to
   410  select the new version in the dependency lock file and remove your development
   411  override.
   412  
   413  The override path for a particular provider should be a directory similar to
   414  what would be included in a `.zip` file when distributing the provider. At
   415  minimum that includes an executable file named with a prefix like
   416  `terraform-provider-null`, where `null` is the provider type. If your provider
   417  makes use of other files in its distribution package then you can copy those
   418  files into the override directory too.
   419  
   420  You may wish to enable a development override only for shell sessions where
   421  you are actively working on provider development. If so, you can write a
   422  local CLI configuration file with content like the above in your development
   423  directory, perhaps called `dev.tfrc` for the sake of example, and then use the
   424  `TF_CLI_CONFIG_FILE` environment variable to instruct Terraform to use that
   425  localized CLI configuration instead of the default one:
   426  
   427  ```
   428  export TF_CLI_CONFIG_FILE=/home/developer/tmp/dev.tfrc
   429  ```
   430  
   431  Development overrides are not intended for general use as a way to have
   432  Terraform look for providers on the local filesystem. If you wish to put
   433  copies of _released_ providers in your local filesystem, see
   434  [Implied Local Mirror Directories](#implied-local-mirror-directories)
   435  or
   436  [Explicit Installation Method Configuration](#explicit-installation-method-configuration)
   437  instead.
   438  
   439  This development overrides mechanism is intended as a pragmatic way to enable
   440  smoother provider development. The details of how it behaves, how to
   441  configure it, and how it interacts with the dependency lock file may all evolve
   442  in future Terraform releases, including possible breaking changes. We therefore
   443  recommend using development overrides only temporarily during provider
   444  development work.
   445  
   446  ## Removed Settings
   447  
   448  The following settings are supported in Terraform 0.12 and earlier but are
   449  no longer recommended for use:
   450  
   451  * `providers` - a configuration block that allows specifying the locations of
   452    specific plugins for each named provider. This mechanism is deprecated
   453    because it is unable to specify a version number and source for each provider.
   454    See [Provider Installation](#provider-installation) above for the replacement
   455    of this setting in Terraform 0.13 and later.