-
Notifications
You must be signed in to change notification settings - Fork 523
/
s3_bucket_inventory.go
55 lines (47 loc) 路 1.46 KB
/
s3_bucket_inventory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package aws
import (
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)
type S3BucketInventory struct {
Address string
Region string
MonthlyListedObjects *int64 `infracost_usage:"monthly_listed_objects"`
}
func (r *S3BucketInventory) CoreType() string {
return "S3BucketInventory"
}
func (r *S3BucketInventory) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{{Key: "monthly_listed_objects", ValueType: schema.Int64, DefaultValue: 0}}
}
func (r *S3BucketInventory) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *S3BucketInventory) BuildResource() *schema.Resource {
var listedObj *decimal.Decimal
if r.MonthlyListedObjects != nil {
listedObj = decimalPtr(decimal.NewFromInt(*r.MonthlyListedObjects))
}
return &schema.Resource{
Name: r.Address,
CostComponents: []*schema.CostComponent{
{
Name: "Objects listed",
Unit: "1M objects",
UnitMultiplier: decimal.NewFromInt(1000000),
MonthlyQuantity: listedObj,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonS3"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/Inventory-ObjectsListed/")},
},
},
UsageBased: true,
},
},
UsageSchema: r.UsageSchema(),
}
}