-
Notifications
You must be signed in to change notification settings - Fork 523
/
fsx_openzfs_file_system.go
168 lines (153 loc) 路 5.29 KB
/
fsx_openzfs_file_system.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package aws
import (
"fmt"
"math"
"strings"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)
type FSxOpenZFSFileSystem struct {
Address string
StorageType string
ThroughputCapacity int64
ProvisionedIOPS int64
ProvisionedIOPSMode string
StorageCapacityGB int64
Region string
DeploymentType string
DataCompression string
CompressionSavingsPercent *float64 `infracost_usage:"compression_savings_percent"`
BackupStorageGB *float64 `infracost_usage:"backup_storage_gb"`
}
func (r *FSxOpenZFSFileSystem) CoreType() string {
return "FSxOpenZFSFileSystem"
}
func (r *FSxOpenZFSFileSystem) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "backup_storage_gb", ValueType: schema.Float64, DefaultValue: 0},
}
}
func (r *FSxOpenZFSFileSystem) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *FSxOpenZFSFileSystem) BuildResource() *schema.Resource {
return &schema.Resource{
Name: r.Address,
CostComponents: []*schema.CostComponent{
r.throughputCapacityCostComponent(),
r.provisionedIOPSCapacityCostComponent(),
r.storageCapacityCostComponent(),
r.backupGBCostComponent(),
},
UsageSchema: r.UsageSchema(),
}
}
func (r *FSxOpenZFSFileSystem) throughputCapacityCostComponent() *schema.CostComponent {
return &schema.CostComponent{
Name: "Throughput capacity",
Unit: "MBps",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: decimalPtr(decimal.NewFromInt(r.ThroughputCapacity)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonFSx"),
ProductFamily: strPtr("Provisioned Throughput"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "deploymentOption", Value: strPtr("Single-AZ")},
{Key: "fileSystemType", Value: strPtr("OpenZFS")},
},
},
}
}
func (r *FSxOpenZFSFileSystem) provisionedIOPSCapacityCostComponent() *schema.CostComponent {
var provisionedIOPS = decimalPtr(decimal.NewFromInt(0))
if r.ProvisionedIOPSMode == "USER_PROVISIONED" {
provisionedIOPS = decimalPtr(decimal.NewFromFloat(math.Max(0, float64(r.ProvisionedIOPS-(3*r.StorageCapacityGB)))))
}
return &schema.CostComponent{
Name: "Provisioned IOPS",
Unit: "IOPS",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: provisionedIOPS,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonFSx"),
ProductFamily: strPtr("Provisioned IOPS"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "deploymentOption", Value: strPtr("Single-AZ")},
{Key: "fileSystemType", Value: strPtr("OpenZFS")},
},
},
}
}
func (r *FSxOpenZFSFileSystem) storageCapacityCostComponent() *schema.CostComponent {
var storageCapacity *decimal.Decimal
var compressionEnabled = ""
var compressionSavingsPercent float64
if r.DataCompression != "" && r.DataCompression != "NONE" {
if r.CompressionSavingsPercent != nil {
compressionSavingsPercent = *r.CompressionSavingsPercent
} else {
compressionSavingsPercent = 50
}
compressionEnabled = fmt.Sprintf(" (%s compression, %.0f%%)", r.DataCompression, compressionSavingsPercent)
storageCapacity = decimalPtr(decimal.NewFromFloat(math.Ceil(float64(r.StorageCapacityGB) * (1 - compressionSavingsPercent/100))))
} else {
storageCapacity = decimalPtr(decimal.NewFromInt(r.StorageCapacityGB))
}
return &schema.CostComponent{
Name: fmt.Sprintf("SSD storage%s", compressionEnabled),
Unit: "GB",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: storageCapacity,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonFSx"),
ProductFamily: strPtr("Storage"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "deploymentOption", Value: strPtr("Single-AZ")},
{Key: "fileSystemType", Value: strPtr("OpenZFS")},
{Key: "storageType", Value: strPtr("SSD")},
},
},
}
}
func (r *FSxOpenZFSFileSystem) backupGBCostComponent() *schema.CostComponent {
var backupStorage *decimal.Decimal
if r.BackupStorageGB != nil {
backupStorage = decimalPtr(decimal.NewFromFloat(*r.BackupStorageGB))
}
filters := []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/BackupUsage/")},
{Key: "fileSystemType", Value: strPtr("OpenZFS")},
}
if strings.Contains(strings.ToLower(r.DeploymentType), "multi") {
filters = append(filters, &schema.AttributeFilter{
Key: "deploymentOption",
Value: strPtr("Multi-AZ"),
})
} else {
filters = append(filters, &schema.AttributeFilter{
Key: "deploymentOption",
Value: strPtr("N/A"),
})
}
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("AmazonFSx"),
ProductFamily: strPtr("Storage"),
AttributeFilters: filters,
},
UsageBased: true,
}
}