Skip to content

Commit 9813e65

Browse files
DanielMSchmidtxiehan
authored andcommitted
fix: always save terraform credentials
1 parent 0a7abd9 commit 9813e65

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/cdktf-cli/src/bin/cmds/handlers.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,24 +424,22 @@ export async function login(argv: { tfeHostname: string }) {
424424
let token = "";
425425
try {
426426
token = await readStreamAsString(process.stdin);
427+
token = token.replace(/\n/g, "");
427428
} catch (e) {
428429
logger.debug(`No TTY stream passed to login`);
429430
}
430431

431-
const sanitizedToken = token.replace(/\n/g, "");
432-
433432
// If we get a token through stdin, we don't need to ask for credentials, we just validate and set it
434433
// This is useful for programmatically authenticating, e.g. a CI server
435-
if (token) {
436-
await terraformLogin.saveTerraformCredentials(sanitizedToken);
437-
} else {
434+
if (!token) {
438435
token = await terraformLogin.askToLogin(false);
439436
if (token === "") {
440437
throw Errors.Usage(`No Terraform Cloud token was provided.`);
441438
}
442439
}
443440

444-
await showUserDetails(sanitizedToken || token);
441+
await terraformLogin.saveTerraformCredentials(token);
442+
await showUserDetails(token);
445443
}
446444

447445
export async function synth(argv: any) {

0 commit comments

Comments
 (0)