-
Notifications
You must be signed in to change notification settings - Fork 523
/
ebs_snapshot.go
151 lines (135 loc) 路 5.02 KB
/
ebs_snapshot.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package aws
import (
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)
type EBSSnapshot struct {
Address string
Region string
SizeGB *float64
MonthlyListBlockRequests *int64 `infracost_usage:"monthly_list_block_requests"`
MonthlyGetBlockRequests *int64 `infracost_usage:"monthly_get_block_requests"`
MonthlyPutBlockRequests *int64 `infracost_usage:"monthly_put_block_requests"`
FastSnapshotRestoreHours *int64 `infracost_usage:"fast_snapshot_restore_hours"`
}
func (r *EBSSnapshot) CoreType() string {
return "EBSSnapshot"
}
func (r *EBSSnapshot) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{{Key: "monthly_list_block_requests", ValueType: schema.Int64, DefaultValue: 0}, {Key: "monthly_get_block_requests", ValueType: schema.Int64, DefaultValue: 0}, {Key: "monthly_put_block_requests", ValueType: schema.Int64, DefaultValue: 0}, {Key: "fast_snapshot_restore_hours", ValueType: schema.Int64, DefaultValue: 0}}
}
func (r *EBSSnapshot) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *EBSSnapshot) BuildResource() *schema.Resource {
region := r.Region
gbVal := decimal.NewFromFloat(float64(defaultVolumeSize))
if r.SizeGB != nil {
gbVal = decimal.NewFromFloat(*r.SizeGB)
}
var listBlockRequests *decimal.Decimal
if r.MonthlyListBlockRequests != nil {
listBlockRequests = decimalPtr(decimal.NewFromInt(*r.MonthlyListBlockRequests))
}
var getSnapshotBlockRequests *decimal.Decimal
if r.MonthlyGetBlockRequests != nil {
getSnapshotBlockRequests = decimalPtr(decimal.NewFromInt(*r.MonthlyGetBlockRequests))
}
var putSnapshotBlockRequests *decimal.Decimal
if r.MonthlyPutBlockRequests != nil {
putSnapshotBlockRequests = decimalPtr(decimal.NewFromInt(*r.MonthlyPutBlockRequests))
}
var fastSnapshotRestoreHours *decimal.Decimal
if r.MonthlyPutBlockRequests != nil {
fastSnapshotRestoreHours = decimalPtr(decimal.NewFromInt(*r.FastSnapshotRestoreHours))
}
costComponents := []*schema.CostComponent{
ebsSnapshotCostComponent(region, gbVal),
{
Name: "Fast snapshot restore",
Unit: "DSU-hours",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: fastSnapshotRestoreHours,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(region),
Service: strPtr("AmazonEC2"),
ProductFamily: strPtr("Fast Snapshot Restore"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/EBS:FastSnapshotRestore$/")},
},
},
UsageBased: true,
},
{
Name: "ListChangedBlocks & ListSnapshotBlocks API requests",
Unit: "1k requests",
UnitMultiplier: decimal.NewFromInt(1000),
MonthlyQuantity: listBlockRequests,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(region),
Service: strPtr("AmazonEC2"),
ProductFamily: strPtr("EBS direct API Requests"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/EBS:directAPI.snapshot.List$/")},
},
},
UsageBased: true,
},
{
Name: "GetSnapshotBlock API requests",
Unit: "1k SnapshotAPIUnits",
UnitMultiplier: decimal.NewFromInt(1000),
MonthlyQuantity: getSnapshotBlockRequests,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(region),
Service: strPtr("AmazonEC2"),
ProductFamily: strPtr("EBS direct API Requests"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/EBS:directAPI.snapshot.Get$/")},
},
},
UsageBased: true,
},
{
Name: "PutSnapshotBlock API requests",
Unit: "1k SnapshotAPIUnits",
UnitMultiplier: decimal.NewFromInt(1000),
MonthlyQuantity: putSnapshotBlockRequests,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(region),
Service: strPtr("AmazonEC2"),
ProductFamily: strPtr("EBS direct API Requests"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/EBS:directAPI.snapshot.Put$/")},
},
},
UsageBased: true,
}}
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents, UsageSchema: r.UsageSchema(),
}
}
func ebsSnapshotCostComponent(region string, gbVal decimal.Decimal) *schema.CostComponent {
return &schema.CostComponent{
Name: "EBS snapshot storage",
Unit: "GB",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: &gbVal,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(region),
Service: strPtr("AmazonEC2"),
ProductFamily: strPtr("Storage Snapshot"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/EBS:SnapshotUsage$/")},
},
},
UsageBased: true,
}
}