diff --git a/cmd/multi_service_helpers.go b/cmd/multi_service_helpers.go index 19b69e469..b26f96212 100644 --- a/cmd/multi_service_helpers.go +++ b/cmd/multi_service_helpers.go @@ -540,7 +540,6 @@ func fetchRecommendationsForRegion( } params := common.RecommendationParams{ Service: service, - Region: region, PaymentOption: cfg.PaymentOption, Term: termStr, LookbackPeriod: lookback, @@ -548,6 +547,13 @@ func fetchRecommendationsForRegion( IncludeSPTypes: cfg.IncludeSPTypes, ExcludeSPTypes: cfg.ExcludeSPTypes, } + // For Savings Plans, region is only the endpoint the account-level call is + // signed in (spAPIRegion), not a filter. The provider folds params.Region + // into its include-region set, which would drop every EC2 Instance plan + // recommended outside that endpoint region. + if !common.IsSavingsPlan(service) { + params.Region = region + } recs, err := recClient.GetRecommendations(ctx, ¶ms) var incomplete *recommendations.IncompleteRecommendationsError diff --git a/cmd/savings_plan_purchase_test.go b/cmd/savings_plan_purchase_test.go index e8b3ce291..d2b804c8e 100644 --- a/cmd/savings_plan_purchase_test.go +++ b/cmd/savings_plan_purchase_test.go @@ -15,6 +15,7 @@ import ( "github.com/LeanerCloud/cloud-commitments-go/pkg/common" "github.com/aws/aws-sdk-go-v2/aws" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -401,3 +402,26 @@ func TestProcessCSVRegionPurchases_SavingsPlanRowFromWrittenCSV(t *testing.T) { assert.NotContains(t, results[0].Error.Error(), "Details", "details must reach the client") assert.Contains(t, stub.paths(), "/DescribeSavingsPlansOfferings") } + +func TestFetchRecommendationsForRegion_SavingsPlanDoesNotFilterOnEndpointRegion(t *testing.T) { + captureAppLog(t) + for _, tc := range []struct { + service common.ServiceType + wantRegion string + }{ + {common.ServiceSavingsPlansEC2Instance, ""}, + {common.ServiceSavingsPlansCompute, ""}, + {common.ServiceRDS, spAPIRegion}, + } { + client := &MockRecommendationsClient{} + var got *common.RecommendationParams + client.On("GetRecommendations", mock.Anything, mock.Anything). + Run(func(args mock.Arguments) { got = args.Get(1).(*common.RecommendationParams) }). + Return([]common.Recommendation{}, nil) + + fetchRecommendationsForRegion(context.Background(), client, tc.service, spAPIRegion, Config{TermYears: 1}) + + require.NotNil(t, got, tc.service) + assert.Equal(t, tc.wantRegion, got.Region, tc.service) + } +}