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

Windows drive fix #220

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Conversation

JAPNITSINGH
Copy link
Contributor

This is a minor fix, could be critical in certain scenarios.

BUG:
I had created a project in D drvie of my PC with just one file (main.tf) with a minimalistic code as shown below.
When I launch VS code for the first time, I see the correct costs being displayed. However when I make changes to main.tf and save the file, I do not see the changes in the cost.

STEPS TO REPRODUCE:

  1. Create a folder in D drive. (I have used D:\Github_Projs\Dummy\01-hello-world-Terraform)
  2. Create a main.tf file with the following contents:
        # Configure the AWS provider
        provider "aws" {
          region = "eu-west-1"
        } 
        # Create an EC2 instance
        resource "aws_instance" "example" {
          ami           = "ami-785db401"
          instance_type = "t3.micro"
        }
  1. Open VS code (Make sure Terraform extension and Infracost are installed)
  2. Open main.tf and modify the instance_type ( change it to t2.micro for example)
  3. Observe that the shown cost doesn't change.

VIDEO OF THE BUG:

BUG.mp4

DEBUG LOGS:
debug_logs.txt

CAUSE OF THE PROBLEM:
The cause of the problem seems to be in workspace.ts in the method async fileChange() when comparing projectDir and dir(look at the valies on the left hand side)
projectDirString

This is happening because the cleanFilename() method in utils.ts isn't cleaning the path with all the drives( just the C drive)
cleanFileMaster

In short, if I have a terraform project placed in any drive apart from the C drive, the extension might not work as expectd. (Possible work-around would be to make changes to the file and re-open VS code)

FIX:
I have fixed this issue in this PR, ensuring that all windows drive paths are replaced correctly by modifying the cleanFilename()

VIDEO OF THE FIX:

FIX.mp4

Here is a ZIP file of the dummy project that I am using in case this is needed for reproducing the issue:
01-hello-world-Terraform.zip

@CLAassistant
Copy link

CLAassistant commented Jul 12, 2024

CLA assistant check
All committers have signed the CLA.

@hugorut hugorut requested a review from owenrumney July 12, 2024 08:07
@hugorut hugorut added the bug Something isn't working label Jul 12, 2024
@hugorut
Copy link
Collaborator

hugorut commented Jul 12, 2024

Thanks @JAPNITSINGH for raising this. @owenrumney I'm assigning this to you as you are the person who most recently worked on the windows specifics for the extension.

@owenrumney
Copy link
Member

Thanks for this @JAPNITSINGH - I've run it on Windows/Linux and MacOS and it's all good. 👍

Copy link
Member

@owenrumney owenrumney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@owenrumney owenrumney merged commit b6e4aa5 into infracost:master Jul 12, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants