-
Notifications
You must be signed in to change notification settings - Fork 523
/
ssm_parameter.go
132 lines (111 loc) 路 3.85 KB
/
ssm_parameter.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
package aws
import (
"github.com/infracost/infracost/internal/logging"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"fmt"
"strings"
"github.com/shopspring/decimal"
)
type SSMParameter struct {
Address string
Tier string
Region string
ParameterStorageHrs *int64 `infracost_usage:"parameter_storage_hrs"`
APIThroughputLimit *string `infracost_usage:"api_throughput_limit"`
MonthlyAPIInteractions *int64 `infracost_usage:"monthly_api_interactions"`
}
func (r *SSMParameter) CoreType() string {
return "SSMParameter"
}
func (r *SSMParameter) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "parameter_storage_hrs", ValueType: schema.Int64, DefaultValue: 0},
{Key: "api_throughput_limit", ValueType: schema.String, DefaultValue: "standard"},
{Key: "monthly_api_interactions", ValueType: schema.Int64, DefaultValue: 0},
}
}
func (r *SSMParameter) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *SSMParameter) BuildResource() *schema.Resource {
costComponents := make([]*schema.CostComponent, 0)
throughputLimit := ""
if r.APIThroughputLimit != nil {
throughputLimit = strings.ToLower(*r.APIThroughputLimit)
if throughputLimit != "standard" && throughputLimit != "advanced" && throughputLimit != "higher" {
logging.Logger.Warn().Msgf("Skipping resource %s. Unrecognized api_throughput_limit %s, expecting standard, advanced or higher", r.Address, *r.APIThroughputLimit)
return nil
}
}
if throughputLimit == "" {
throughputLimit = r.tierValue()
}
if r.tierValue() != "standard" {
costComponents = append(costComponents, r.parameterStorageCostComponent())
costComponents = append(costComponents, r.apiThroughputCostComponent(throughputLimit))
}
if len(costComponents) == 0 {
return &schema.Resource{
Name: r.Address,
NoPrice: true,
IsSkipped: true,
UsageSchema: r.UsageSchema(),
}
}
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
UsageSchema: r.UsageSchema(),
}
}
func (r *SSMParameter) tierValue() string {
if r.Tier == "" {
return "standard"
}
return strings.ToLower(r.Tier)
}
func (r *SSMParameter) parameterStorageCostComponent() *schema.CostComponent {
parameterStorageHours := decimal.NewFromInt(730)
if r.ParameterStorageHrs != nil {
parameterStorageHours = decimal.NewFromInt(*r.ParameterStorageHrs)
}
return &schema.CostComponent{
Name: "Parameter storage (advanced)",
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: ¶meterStorageHours,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AWSSystemsManager"),
ProductFamily: strPtr("AWS Systems Manager"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/PS-Advanced-Param-Tier1/")},
},
},
UsageBased: true,
}
}
func (r *SSMParameter) apiThroughputCostComponent(throughputLimit string) *schema.CostComponent {
var monthlyAPIInteractions *decimal.Decimal
if r.MonthlyAPIInteractions != nil {
monthlyAPIInteractions = decimalPtr(decimal.NewFromInt(*r.MonthlyAPIInteractions))
}
return &schema.CostComponent{
Name: fmt.Sprintf("API interactions (%s)", throughputLimit),
Unit: "10k interactions",
UnitMultiplier: decimal.NewFromInt(10000),
MonthlyQuantity: monthlyAPIInteractions,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AWSSystemsManager"),
ProductFamily: strPtr("API Request"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/PS-Param-Processed-Tier2/")},
},
},
UsageBased: true,
}
}