-
Notifications
You must be signed in to change notification settings - Fork 523
/
kms_key.go
99 lines (86 loc) 路 2.65 KB
/
kms_key.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
package aws
import (
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)
type KMSKey struct {
Address string
Region string
CustomerMasterKeySpec string
}
func (r *KMSKey) CoreType() string {
return "KMSKey"
}
func (r *KMSKey) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{}
}
func (r *KMSKey) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *KMSKey) BuildResource() *schema.Resource {
costComponents := []*schema.CostComponent{
r.customerMasterKeyCostComponent(),
}
costComponents = append(costComponents, r.requestsCostComponents()...)
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
UsageSchema: r.UsageSchema(),
}
}
func (r *KMSKey) customerMasterKeyCostComponent() *schema.CostComponent {
return &schema.CostComponent{
Name: "Customer master key",
Unit: "months",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: decimalPtr(decimal.NewFromInt(1)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("awskms"),
ProductFamily: strPtr("Encryption Key"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/KMS-Keys/")},
},
},
}
}
func (r *KMSKey) requestsCostComponents() []*schema.CostComponent {
switch r.CustomerMasterKeySpec {
case "RSA_2048":
return []*schema.CostComponent{
r.requestsCostComponent("Requests (RSA 2048)", "/KMS-Requests-Asymmetric-RSA_2048/"),
}
case
"RSA_3072",
"RSA_4096",
"ECC_NIST_P256",
"ECC_NIST_P384",
"ECC_NIST_P521",
"ECC_SECG_P256K1":
return []*schema.CostComponent{
r.requestsCostComponent("Requests (asymmetric)", "/KMS-Requests-Asymmetric$/"),
}
}
return []*schema.CostComponent{
r.requestsCostComponent("Requests", "/KMS-Requests$/"),
r.requestsCostComponent("ECC GenerateDataKeyPair requests", "/KMS-Requests-GenerateDatakeyPair-ECC/"),
r.requestsCostComponent("RSA GenerateDataKeyPair requests", "/KMS-Requests-GenerateDatakeyPair-ECC/"),
}
}
func (r *KMSKey) requestsCostComponent(name string, usagetype string) *schema.CostComponent {
return &schema.CostComponent{
Name: name,
Unit: "10k requests",
UnitMultiplier: decimal.NewFromInt(10000),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("awskms"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr(usagetype)},
},
},
}
}