Command: login
Theterraform login command can be used to automatically obtain and save an API token for HCP Terraform, Terraform Enterprise, or any other host that offers Terraform services.
Usage
app.terraform.io, to log in to HCP Terraform.
This command interactively helps you log in to HCP Terraform or a Terraform Enterprise instance. Terraform uses the token to authenticate when you run other commands that access state, such as terraform plan and terraform apply.
This command is only necessary when using HCP Terraform or Terraform Enterprise for state storage or remote operations. It is not needed for typical Terraform workflows with local state.
Credentials Storage
By default, Terraform will obtain an API token and save it in a local CLI configuration file calledcredentials.tfrc.json. The default location of this file is:
- On Linux and macOS:
~/.terraform.d/credentials.tfrc.json - On Windows:
%APPDATA%\terraform.d\credentials.tfrc.json
Interactive Login Process
When you runterraform login, Terraform will:
- Ask for your consent to open a web browser
- Open your web browser to the login page for the specified host
- Wait for you to log in and authorize the token creation
- Receive the token from the host
- Save the token to your local credentials file