Problem
While attempting to run terraform login
from the command line to log into Terraform Enterprise (TFE) or Terraform Cloud (TFC) and after inserting a token when prompted, an error displays Error: Token is invalid: unauthorized
Causes
- When the SAML authentication process occurs, TFE and TFC record the date/time that the action occurred and uses that when determining if the token needs to be locked based on the API token timeout. Re-doing the SAML process resets that time and the token will unlock.
- The token that is inserted directly in the prompt is not being received.
Solutions:
-
Solution number 1
-
Re-doing the SAML process resets that time and the token will unlock. Signing out of the SAML session and signing back in, refreshes the token.
-
- Solution number 2
- Copy the token to a text editor first, then from the text editor to the login screen when prompted.