-
Notifications
You must be signed in to change notification settings - Fork 523
/
neptune_cluster_instance.go
108 lines (92 loc) 路 3.12 KB
/
neptune_cluster_instance.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package aws
import (
"fmt"
"strings"
"github.com/shopspring/decimal"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
)
type NeptuneClusterInstance struct {
Address string
Region string
InstanceClass string
IOOptimized bool
Count *int64
MonthlyCPUCreditHrs *int64 `infracost_usage:"monthly_cpu_credit_hrs"`
}
func (r *NeptuneClusterInstance) CoreType() string {
return "NeptuneClusterInstance"
}
func (r *NeptuneClusterInstance) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "monthly_cpu_credit_hrs", ValueType: schema.Int64, DefaultValue: 0},
}
}
func (r *NeptuneClusterInstance) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *NeptuneClusterInstance) BuildResource() *schema.Resource {
hourlyQuantity := 1
if r.Count != nil {
hourlyQuantity = int(*r.Count)
}
var monthlyCPUCreditHrs *decimal.Decimal
if r.MonthlyCPUCreditHrs != nil {
monthlyCPUCreditHrs = decimalPtr(decimal.NewFromInt(*r.MonthlyCPUCreditHrs))
}
costComponents := []*schema.CostComponent{
r.dbInstanceCostComponent(hourlyQuantity),
}
if instanceFamily := getBurstableInstanceFamily([]string{"db.t3", "db.t4g"}, r.InstanceClass); instanceFamily != "" {
costComponents = append(costComponents, r.cpuCreditsCostComponent(monthlyCPUCreditHrs, instanceFamily))
}
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
UsageSchema: r.UsageSchema(),
}
}
func (r *NeptuneClusterInstance) dbInstanceCostComponent(quantity int) *schema.CostComponent {
usageTypePrefix := "InstanceUsage:"
if r.IOOptimized {
usageTypePrefix = "InstanceUsageIOOptimized:"
}
return &schema.CostComponent{
Name: fmt.Sprintf("Database instance (on-demand, %s)", r.InstanceClass),
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: decimalPtr(decimal.NewFromInt(int64(quantity))),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonNeptune"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "instanceType", Value: strPtr(strings.ToLower(r.InstanceClass))},
{Key: "usagetype", ValueRegex: regexPtr(fmt.Sprintf("%s%s$", usageTypePrefix, strings.ToLower(r.InstanceClass)))},
},
},
PriceFilter: &schema.PriceFilter{
PurchaseOption: strPtr("on_demand"),
},
}
}
func (r *NeptuneClusterInstance) cpuCreditsCostComponent(quantity *decimal.Decimal, instanceFamily string) *schema.CostComponent {
return &schema.CostComponent{
Name: "CPU credits",
Unit: "vCPU-hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: quantity,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonNeptune"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: regexPtr("CPUCredits:" + instanceFamily + "$")},
},
},
PriceFilter: &schema.PriceFilter{
PurchaseOption: strPtr("on_demand"),
},
UsageBased: true,
}
}