Title
#contributors
Johannes Grumböck

Johannes Grumböck

10/14/2022, 8:02 AM
Hi all, How do I fix “multiple prices”-problem in golden tests? I wanted to contribute for Hacktoberfest and did https://github.com/infracost/infracost/pull/2090 So, I thought it would be an easy fix (what it was actually), but now I’m stuck with the following error running the tests locally:
❯ INFRACOST_LOG_LEVEL=debug go test -v -cover ./internal/providers/terraform/aws/fsx_windows_file_system_test.go
=== RUN TestFSXWindowsFS
=== PAUSE TestFSXWindowsFS
=== CONT TestFSXWindowsFS
=== RUN TestFSXWindowsFS/HCL
level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_file_system_ssd SSD storage, using the first product”
testutil.go:202: Unexpected log write. To capture logs remove t.Parallel and use GoldenFileOptions { CaptureLogs = true }: level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_file_system_ssd SSD storage, using the first product”
level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_system_ssd SSD storage, using the first product”
testutil.go:202: Unexpected log write. To capture logs remove t.Parallel and use GoldenFileOptions { CaptureLogs = true }: level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_system_ssd SSD storage, using the first product”
=== RUN TestFSXWindowsFS/Terraform_CLI
level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_file_system_ssd SSD storage, using the first product”
testutil.go:202: Unexpected log write. To capture logs remove t.Parallel and use GoldenFileOptions { CaptureLogs = true }: level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_file_system_ssd SSD storage, using the first product”
level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_system_ssd SSD storage, using the first product”
testutil.go:202: Unexpected log write. To capture logs remove t.Parallel and use GoldenFileOptions { CaptureLogs = true }: level=warning msg=“Multiple products with prices found for aws_fsx_windows_file_system.my_system_ssd SSD storage, using the first product”
--- FAIL: TestFSXWindowsFS (6.62s)
--- FAIL: TestFSXWindowsFS/HCL (0.65s)
--- FAIL: TestFSXWindowsFS/Terraform_CLI (5.97s)
FAIL
coverage: [no statements]
FAIL command-line-arguments 7.180s
FAIL
Where would I need to start debugging that? Thanks, Johannes
Hugo (Infracost)

Hugo (Infracost)

10/14/2022, 8:53 AM
Hey @Johannes Grumböck, a multiple price warning normally means that the product filter sent to the cloud pricing API is too broad an is not retrieving a single product entry. In the example you’ve given this is most likely because there are multiple products with an attribute
SSD
for the
AmazonFSx
service. So the key is to modify the storageCapacityComponent:
func (r *FSxWindowsFileSystem) storageCapacityCostComponent() *schema.CostComponent {
	deploymentOption := r.deploymentOptionValue()
	storageType := r.storageTypeValue()

	return &schema.CostComponent{
		Name:            fmt.Sprintf("%v storage", storageType),
		Unit:            "GB",
		UnitMultiplier:  decimal.NewFromInt(1),
		MonthlyQuantity: decimalPtr(decimal.NewFromInt(r.StorageCapacityGB)),
		ProductFilter: &schema.ProductFilter{
			VendorName:    strPtr("aws"),
			Region:        strPtr(r.Region),
			Service:       strPtr("AmazonFSx"),
			ProductFamily: strPtr("Storage"),
			AttributeFilters: []*schema.AttributeFilter{
				{Key: "deploymentOption", Value: strPtr(deploymentOption)},
				{Key: "storageType", Value: strPtr(storageType)},
			},
		},
	}
}
AttributeFilters
to target only a single product entry. The easiest way to find the product your targeting is to boot up the cloud pricing db locally and do some queries. You can find out more about this here: https://github.com/infracost/infracost/blob/master/contributing/add_new_resource_guide.md#price-search
8:53 AM
let me know if you have any other questions
Johannes Grumböck

Johannes Grumböck

10/14/2022, 9:00 AM
Thanks, that’s already a good guidance. 👍 I’ll let you know when I’m get lost in the 🌲🌲🌲🌲
Hugo (Infracost)

Hugo (Infracost)

10/14/2022, 9:00 AM
you got it
Johannes Grumböck

Johannes Grumböck

10/14/2022, 9:45 AM
@Hugo (Infracost) time for quick help?
Hugo (Infracost)

Hugo (Infracost)

10/14/2022, 9:45 AM
give me 15 mins
Johannes Grumböck

Johannes Grumböck

10/14/2022, 9:45 AM
👍
9:47 AM
Pause - think I got it.
10:10 AM
PS: Would ❤️ to get a
hacktoberfest-accepted
label on this PR after review 😉
Hugo (Infracost)

Hugo (Infracost)

10/14/2022, 10:10 AM
nice work
10:11 AM
@Johannes Grumböck of course
10:12 AM