Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always save terraform credentials #3785

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/cdktf-cli/src/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,24 +424,22 @@ export async function login(argv: { tfeHostname: string }) {
let token = "";
try {
token = await readStreamAsString(process.stdin);
token = token.replace(/\n/g, "");
} catch (e) {
logger.debug(`No TTY stream passed to login`);
}

const sanitizedToken = token.replace(/\n/g, "");

// If we get a token through stdin, we don't need to ask for credentials, we just validate and set it
// This is useful for programmatically authenticating, e.g. a CI server
if (token) {
await terraformLogin.saveTerraformCredentials(sanitizedToken);
} else {
if (!token) {
token = await terraformLogin.askToLogin(false);
if (token === "") {
throw Errors.Usage(`No Terraform Cloud token was provided.`);
}
}

await showUserDetails(sanitizedToken || token);
await terraformLogin.saveTerraformCredentials(token);
await showUserDetails(token);
}

export async function synth(argv: any) {
Expand Down
Loading