-
Notifications
You must be signed in to change notification settings - Fork 523
/
kinesis_firehose_delivery_stream.go
160 lines (139 loc) 路 5.19 KB
/
kinesis_firehose_delivery_stream.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
package aws
import (
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"fmt"
"github.com/shopspring/decimal"
"github.com/infracost/infracost/internal/usage"
)
type KinesisFirehoseDeliveryStream struct {
Address string
Region string
DataFormatConversionEnabled bool
VPCDeliveryEnabled bool
VPCDeliveryAZs int64
MonthlyDataIngestedGB *float64 `infracost_usage:"monthly_data_ingested_gb"`
}
func (r *KinesisFirehoseDeliveryStream) CoreType() string {
return "KinesisFirehoseDeliveryStream"
}
func (r *KinesisFirehoseDeliveryStream) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "monthly_data_ingested_gb", ValueType: schema.Float64, DefaultValue: 0},
}
}
func (r *KinesisFirehoseDeliveryStream) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *KinesisFirehoseDeliveryStream) BuildResource() *schema.Resource {
costComponents := make([]*schema.CostComponent, 0)
if r.MonthlyDataIngestedGB != nil {
tierLimits := []int{512_000, 1_536_000}
result := usage.CalculateTierBuckets(decimal.NewFromFloat(*r.MonthlyDataIngestedGB), tierLimits)
if result[0].GreaterThan(decimal.Zero) {
costComponents = append(costComponents, r.dataIngestedCostComponent("first 500TB", "0", "512000", &result[0]))
}
if result[1].GreaterThan(decimal.Zero) {
costComponents = append(costComponents, r.dataIngestedCostComponent("next 1.5PB", "512000", "2048000", &result[1]))
}
if result[2].GreaterThan(decimal.Zero) {
costComponents = append(costComponents, r.dataIngestedCostComponent("next 3PB", "2048000", "Inf", &result[2]))
}
} else {
costComponents = append(costComponents, r.dataIngestedCostComponent("first 500TB", "0", "512000", nil))
}
if r.DataFormatConversionEnabled {
costComponents = append(costComponents, r.formatConversionCostComponent())
}
if r.VPCDeliveryEnabled {
costComponents = append(costComponents, r.vpcDataCostComponent())
costComponents = append(costComponents, r.vpcDeliveryCostComponent())
}
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
UsageSchema: r.UsageSchema(),
}
}
func (r *KinesisFirehoseDeliveryStream) dataIngestedCostComponent(tier, startUsageAmount, endUsageAmount string, quantity *decimal.Decimal) *schema.CostComponent {
return &schema.CostComponent{
Name: fmt.Sprintf("Data ingested (%s)", tier),
Unit: "GB",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: quantity,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonKinesisFirehose"),
ProductFamily: strPtr("Kinesis Firehose"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "group", Value: strPtr("Event-by-Event Processing")},
{Key: "sourcetype", Value: strPtr("")},
},
},
PriceFilter: &schema.PriceFilter{
StartUsageAmount: strPtr(startUsageAmount),
EndUsageAmount: strPtr(endUsageAmount),
},
UsageBased: true,
}
}
func (r *KinesisFirehoseDeliveryStream) formatConversionCostComponent() *schema.CostComponent {
var monthlyDataIngestedGB *decimal.Decimal
if r.MonthlyDataIngestedGB != nil {
monthlyDataIngestedGB = decimalPtr(decimal.NewFromFloat(*r.MonthlyDataIngestedGB))
}
return &schema.CostComponent{
Name: "Format conversion",
Unit: "GB",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: monthlyDataIngestedGB,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonKinesisFirehose"),
ProductFamily: strPtr("Kinesis Firehose"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "operation", Value: strPtr("DataFormatConversion")},
},
},
}
}
func (r *KinesisFirehoseDeliveryStream) vpcDataCostComponent() *schema.CostComponent {
var monthlyDataIngestedGB *decimal.Decimal
if r.MonthlyDataIngestedGB != nil {
monthlyDataIngestedGB = decimalPtr(decimal.NewFromFloat(*r.MonthlyDataIngestedGB))
}
return &schema.CostComponent{
Name: "VPC data",
Unit: "GB",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: monthlyDataIngestedGB,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonKinesisFirehose"),
ProductFamily: strPtr("Kinesis Firehose"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "operation", Value: strPtr("VpcBandwidth")},
},
},
}
}
func (r *KinesisFirehoseDeliveryStream) vpcDeliveryCostComponent() *schema.CostComponent {
return &schema.CostComponent{
Name: "VPC AZ delivery",
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: decimalPtr(decimal.NewFromInt(r.VPCDeliveryAZs)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonKinesisFirehose"),
ProductFamily: strPtr("Kinesis Firehose"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "operation", Value: strPtr("RunVpcInstance")},
},
},
}
}