Hi all, How do I fix “multiple prices”-problem in...
# contributors
s
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.go202 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.go202 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.go202 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.go202 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
m
Hey @stocky-salesmen-15167, 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`:
Copy code
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
let me know if you have any other questions
s
Thanks, that’s already a good guidance. 👍 I’ll let you know when I’m get lost in the 🌲🌲🌲🌲
m
you got it
s
@mysterious-teacher-68276 time for quick help?
m
give me 15 mins
s
👍
Pause - think I got it.
PS: Would ❤️ to get a
hacktoberfest-accepted
label on this PR after review 😉
m
nice work
@stocky-salesmen-15167 of course