-
Notifications
You must be signed in to change notification settings - Fork 523
/
docdb_cluster.go
68 lines (58 loc) 路 1.86 KB
/
docdb_cluster.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
56
57
58
59
60
61
62
63
64
65
66
67
68
package aws
import (
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)
type DocDBCluster struct {
Address string
Region string
BackupRetentionPeriod int64
BackupStorageGB *float64 `infracost_usage:"backup_storage_gb"`
}
func (r *DocDBCluster) CoreType() string {
return "DocDBCluster"
}
func (r *DocDBCluster) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "backup_storage_gb", ValueType: schema.Float64, DefaultValue: 0},
}
}
func (r *DocDBCluster) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *DocDBCluster) BuildResource() *schema.Resource {
costComponents := []*schema.CostComponent{}
if r.BackupRetentionPeriod > 1 {
var backupStorage *decimal.Decimal
if r.BackupStorageGB != nil {
backupStorage = decimalPtr(decimal.NewFromFloat(*r.BackupStorageGB))
}
costComponents = append(costComponents, r.backupStorageCostComponent(backupStorage))
} else {
costComponents = append(costComponents, r.backupStorageCostComponent(nil))
}
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
UsageSchema: r.UsageSchema(),
}
}
func (r *DocDBCluster) backupStorageCostComponent(backupStorage *decimal.Decimal) *schema.CostComponent {
return &schema.CostComponent{
Name: "Backup storage",
Unit: "GB",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: backupStorage,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonDocDB"),
ProductFamily: strPtr("Storage Snapshot"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: regexPtr("(^|-)BackupUsage$")},
},
},
UsageBased: true,
}
}