• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Terraform
  • Install
  • Tutorials
    • About the Docs
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • CDK for Terraform
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
  • Registry(opens in new tab)
  • Try Cloud(opens in new tab)
  • Sign up
0.13 Release

Skip to main content
5 tutorials
  • Manage Similar Resources with Count
  • Manage Similar Resources with For Each
  • Log in to Terraform Cloud from the CLI
  • Create Resource Dependencies
  • Perform CRUD Operations with Providers

  • Resources

  • Tutorial Library
  • Certifications
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  • Terraform Registry
    (opens in new tab)
  1. Developer
  2. Terraform
  3. Tutorials
  4. 0.13 Release
  5. Log in to Terraform Cloud from the CLI

Log in to Terraform Cloud from the CLI

  • 3min

  • Terraform CloudTerraform Cloud
  • TerraformTerraform

Terraform Cloud runs Terraform operations and stores state remotely, so you can use Terraform without worrying about the stability of your local machine, or the security of your state file.

To use Terraform Cloud from the command line, you must log in. Logging in allows you to trigger remote plans and runs, migrate state to the cloud, and perform other remote operations on configurations with Terraform Cloud.

Prerequisites

  • The Terraform CLI (version 1.1.0+) installed locally
  • A Terraform Cloud account

Tip: If you are using an older version of Terraform, set up a CLI configuration file to authenticate to Terraform Cloud.

Start the login flow

In order to authenticate with Terraform Cloud, run the terraform login subcommand. Respond yes to the prompt to confirm that you want to authenticate.

$ terraform login
Terraform will request an API token for app.terraform.io using your browser.

If login is successful, Terraform will store the token in plain text in
the following file for use by subsequent commands:
    /Users/redacted/.terraform.d/credentials.tfrc.json

Do you want to proceed?
  Only 'yes' will be accepted to confirm.

  Enter a value: yes

Generate a token

A browser window will automatically open to the Terraform Cloud login screen. Enter a token name in the web UI, or leave the default name, terraform login.

Tip: If your browser does not open automatically, navigate to the URL output in your terminal or click here to go to the token creation UI.

Modal window in Terraform Cloud titled "Create API token". There is a text box to set a name for the token.

Click Create API token to generate the authentication token.

Modal window in Terraform Cloud titled "Create API token". The window contains a token value.

Save a copy of the token in a secure location. It provides access to your Terraform Cloud organization. Terraform will also store your token locally at the file path specified in the command output.

Add the token to the CLI

When the Terraform CLI prompts you, paste the user token exactly once into your terminal. Terraform will hide the token for security when you paste it into your terminal. Press Enter to complete the authentication process.

Terraform must now open a web browser to the tokens page for app.terraform.io.

If a browser does not open this automatically, open the following URL to proceed:
    https://app.terraform.io/app/settings/tokens?source=terraform-login


---------------------------------------------------------------------------------

Generate a token using your browser, and copy-paste it into this prompt.

Terraform will store the token in plain text in the following file
for use by subsequent commands:
    /Users/redacted/.terraform.d/credentials.tfrc.json

Token for app.terraform.io:
  Enter a value:


Retrieved token for user redacted

Welcome to Terraform Cloud!

Next Steps

Once you have authenticated to Terraform Cloud, you are ready to perform remote operations. Continue to the next tutorial to create a new Terraform Cloud variable set.

Discover more remote operations to perform with a logged in CLI in the Terraform Cloud CLI-driven Runs documentation.

 Previous
 Next

This tutorial also appears in:

  •  
    38 tutorials
    Associate Tutorial List (003)
    Study for the Terraform Associate (003) exam by following these tutorials. Login to Learn and bookmark them to track your progress. Study the complete list of study materials (including docs) in the Certification Prep guides.
    • Terraform
  •  
    23 tutorials
    Collaborate using Terraform Cloud
    Collaborate on infrastructure with Terraform Cloud. Follow these tutorials to migrate state from local storage and take a deeper look at Terraform Cloud operations, including VCS integration, workspace configuration, and remote runs.
    • Terraform
  •  
    10 tutorials
    Get Started - Terraform Cloud
    Collaborate on version-controlled configuration using Terraform Cloud. Follow this track to build, change, and destroy infrastructure using remote runs and state.
    • Terraform
  •  
    16 tutorials
    Use the Command Line Interface
    Use the Terraform Command Line Interface (CLI) to manage infrastructure, and interact with Terraform state, providers, configuration files, and Terraform Cloud.
    • Terraform
  •  
    25 tutorials
    Associate Tutorial List (002)
    Study for the Terraform Associate (002) exam by following these tutorials. Login to Learn and bookmark them to track your progress. Study the complete list of study materials (including docs) in the Certification Prep guides.
    • Terraform

On this page

  1. Log in to Terraform Cloud from the CLI
  2. Prerequisites
  3. Start the login flow
  4. Generate a token
  5. Add the token to the CLI
  6. Next Steps
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)