Skip to content

Commit

Permalink
fix(azure): Consumption legacy usage details (#11242)
Browse files Browse the repository at this point in the history
Fixes cloudquery/cloudquery-issues#565

This fix ignores all returned types except `LegacyUsageDetail` from the API call (which can sometimes include `ModernUsageDetail` for some undocumented reason, to our understanding) but since we have another resource listing those (`azure_consumption_billing_account_modern_usage_details`) we don't want them here.

```go
// UsageDetailClassification provides polymorphic access to related types.
// Call the interface's GetUsageDetail() method to access the common type.
// Use a type switch to determine the concrete type.  The possible types are:
// - *LegacyUsageDetail, *ModernUsageDetail, *UsageDetail
type UsageDetailClassification interface {
	// GetUsageDetail returns the UsageDetail content of the underlying type.
	GetUsageDetail() *UsageDetail
}
```
  • Loading branch information
disq committed Jun 6, 2023
1 parent 47a5a69 commit 8da78c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func fetchSubscriptionLegacyUsageDetails(ctx context.Context, meta schema.Client
return err
}
for _, v := range p.Value {
res <- v.(*armconsumption.LegacyUsageDetail)
lud, ok := v.(*armconsumption.LegacyUsageDetail)
if !ok {
continue // skip
}
res <- lud
}
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package consumption
import (
"encoding/json"
"net/http"

"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
Expand All @@ -14,16 +13,24 @@ import (
)

func createSubscriptionLegacyUsageDetails(router *mux.Router) error {
var item armconsumption.LegacyUsageDetail
if err := faker.FakeObject(&item); err != nil {
var (
item1 armconsumption.LegacyUsageDetail
item2 armconsumption.ModernUsageDetail
)
if err := faker.FakeObject(&item1); err != nil {
return err
}
item1.Kind = to.Ptr(armconsumption.UsageDetailsKindLegacy)

if err := faker.FakeObject(&item2); err != nil {
return err
}
item.Kind = to.Ptr(armconsumption.UsageDetailsKindLegacy)
item2.Kind = to.Ptr(armconsumption.UsageDetailsKindModern) // will be skipped, but API seems to return both

resp := armconsumption.UsageDetailsClientListResponse{
UsageDetailsListResult: armconsumption.UsageDetailsListResult{
// Value is an interface{} so we can't mock it directly
Value: []armconsumption.UsageDetailClassification{&item},
Value: []armconsumption.UsageDetailClassification{&item1, &item2},
},
}
resp.NextLink = to.Ptr("")
Expand Down

0 comments on commit 8da78c6

Please sign in to comment.