Skip to content

Commit

Permalink
Fix finding TF credential file on windows (#1735)
Browse files Browse the repository at this point in the history
This corrects the getTerraformCLIToken method to correctly find the TF credential file on Windows.

Co-authored-by: Enrico PANETTA <enrico.panetta@outlook.com>
  • Loading branch information
jpogran and Convez authored Apr 15, 2024
1 parent 7ffd6c7 commit 36e320d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/providers/authenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit 36e320d

Please sign in to comment.