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

Feat/add currency conversion #914

Merged
merged 19 commits into from
Aug 25, 2021
Merged

Conversation

tim775
Copy link
Member

@tim775 tim775 commented Aug 19, 2021

No description provided.

@tim775 tim775 requested a review from aliscott August 19, 2021 18:48
Copy link
Member

@alikhajeh1 alikhajeh1 left a comment

Choose a reason for hiding this comment

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

LGTM - I added my suggestions. We should update https://www.infracost.io/docs/multi_project/report to include the currency in the JOSN output.

I'm not sure we need the "$ CAD" on every line as it clutters the output in the table and the HTML outputs:

Project: infracost/infracost/examples/terraform

 Name                                                          Monthly Qty  Unit                      Monthly Cost

 aws_instance.web_app
 ├─ Instance usage (Linux/UNIX, on-demand, m5.4xlarge)                 730  hours                        $0.00 CAD
 ├─ root_block_device
 │  └─ Storage (general purpose SSD, gp2)                               50  GB                           $0.00 CAD
 └─ ebs_block_device[0]
    ├─ Storage (provisioned IOPS SSD, io1)                           1,000  GB                           $0.00 CAD
    └─ Provisioned IOPS                                                800  IOPS                         $0.00 CAD

 aws_lambda_function.hello_world
 ├─ Requests                                            Monthly cost depends on usage: $0.00 CAD per 1M requests
 └─ Duration                                            Monthly cost depends on usage: $0.00 CAD per GB-seconds

 OVERALL TOTAL                                                                                           $0.00 CAD

How about we only include it in the OVERALL TOTAL, or maybe only in the headings: "Price (CAD)", "Hourly Cost (CAD)" and "Monthly Cost (CAD)"?

Project: infracost/infracost/examples/terraform

 Name                                                          Monthly Qty  Unit                      Monthly Cost (CAD)

 aws_instance.web_app
 ├─ Instance usage (Linux/UNIX, on-demand, m5.4xlarge)                 730  hours                        $0.00
 ├─ root_block_device
 │  └─ Storage (general purpose SSD, gp2)                               50  GB                           $0.00
 └─ ebs_block_device[0]
    ├─ Storage (provisioned IOPS SSD, io1)                           1,000  GB                           $0.00
    └─ Provisioned IOPS                                                800  IOPS                         $0.00

 aws_lambda_function.hello_world
 ├─ Requests                                            Monthly cost depends on usage: $0.00 per 1M requests
 └─ Duration                                            Monthly cost depends on usage: $0.00 per GB-seconds

 OVERALL TOTAL                                                                                           $0.00

For the diff output, we could include it in the project diff total:

Monthly cost change for infracost/infracost/examples/terraform
Amount:  $0.00 CAD ($0.00 -> $0.00)

cmd/infracost/configure.go Outdated Show resolved Hide resolved
cmd/infracost/configure.go Outdated Show resolved Hide resolved
cmd/infracost/configure.go Outdated Show resolved Hide resolved
cmd/infracost/run.go Outdated Show resolved Hide resolved
internal/config/configuration.go Show resolved Hide resolved
@tim775 tim775 force-pushed the feat/add-currency-conversion branch from 212c2f2 to 2c4fefb Compare August 23, 2021 15:27
@tim775 tim775 requested a review from alikhajeh1 August 23, 2021 16:07
@alikhajeh1
Copy link
Member

Thanks @tim775 - this is looking awesome. The HTML format (./build/infracost breakdown --path examples/terraform --format html > test.html) doesn't show the currency code in the heading or overall total. We try to keep the formats consistent where possible but if that's not possible in this case, it's ok.

There seems to be a bug in the way infracost output handles currency: it uses the global config but assume the values in the JSON file were USD. Repro steps:

  1. ./build/infracost configure set currency EUR
  2. ./build/infracost breakdown --path examples/terraform --format json > test.json
  3. test.json now holds values in EUR (overall total = 632.25)
  4. ./build/infracost configure set currency GBP
  5. ./build/infracost output --path test.json shows the same overall total (632.25) as step 3 but the table heading shows GBP.

Expected behavior: the simplest thing is probably to have infracost output use the currency in the JSON file (i.e. ignore the global config and the INFRACOST_CURRENCY env var). There might be users in large organizations with multiple currencies, where the JSON file was generated with currency A, and users want currency B - we don't need to handle that.

@tim775 tim775 force-pushed the feat/add-currency-conversion branch from 7f09f61 to 53f89be Compare August 24, 2021 13:35
@tim775 tim775 requested a review from alikhajeh1 August 24, 2021 19:39
@alikhajeh1 alikhajeh1 merged commit 8a338d6 into master Aug 25, 2021
@alikhajeh1 alikhajeh1 deleted the feat/add-currency-conversion branch August 25, 2021 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants