Log in to Terraform Cloud from the CLI
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.
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.
Click Create API token to generate the authentication token.
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.
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.