Log in to HCP Terraform from the CLI
HCP Terraform 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 HCP Terraform 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 HCP Terraform.
Prerequisites
- The Terraform CLI (version 1.1.0+) installed locally
- An HCP Terraform account
Tip
If you are using an older version of Terraform, set up a CLI configuration file to authenticate to HCP Terraform.
Start the login
flow
In order to authenticate with HCP Terraform, 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 HCP Terraform 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 HCP Terraform 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 HCP Terraform, you are ready to perform remote operations. Continue to the next tutorial to create a new HCP Terraform variable set.
Discover more remote operations to perform with a logged in CLI in the HCP Terraform CLI-driven Runs documentation.