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.
Tip: If you are using an older version of Terraform, set up a CLI configuration file to authenticate to Terraform Cloud.
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
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,
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.
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!
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.