From 36e320dd0b858c8ba3c5eaa3661fb7bc79144aa7 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Mon, 15 Apr 2024 10:09:05 -0400 Subject: [PATCH] Fix finding TF credential file on windows (#1735) This corrects the getTerraformCLIToken method to correctly find the TF credential file on Windows. Co-authored-by: Enrico PANETTA --- src/providers/authenticationProvider.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/providers/authenticationProvider.ts b/src/providers/authenticationProvider.ts index 20bba3800a..3d05b70e98 100644 --- a/src/providers/authenticationProvider.ts +++ b/src/providers/authenticationProvider.ts @@ -314,8 +314,14 @@ export class TerraformCloudAuthenticationProvider implements vscode.Authenticati private async getTerraformCLIToken() { // detect if stored auth token is present + // On windows: + // ~/AppData/Roaming/terraform.d/credentials.tfrc.json + // On others: // ~/.terraform.d/credentials.tfrc.json - const credFilePath = path.join(os.homedir(), '.terraform.d', 'credentials.tfrc.json'); + const credFilePath = + process.platform === 'win32' + ? path.join(os.homedir(), 'AppData', 'Roaming', 'terraform.d', 'credentials.tfrc.json') + : path.join(os.homedir(), '.terraform.d', 'credentials.tfrc.json'); if ((await this.pathExists(credFilePath)) === false) { vscode.window.showErrorMessage( 'Terraform credential file not found. Please login using the Terraform CLI and try again.',