-
Notifications
You must be signed in to change notification settings - Fork 523
/
acmpca_certificate_authority.go
131 lines (111 loc) 路 4.11 KB
/
acmpca_certificate_authority.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
package aws
import (
"strings"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/infracost/infracost/internal/usage"
"github.com/shopspring/decimal"
)
type ACMPCACertificateAuthority struct {
Address string
Region string
UsageMode string
MonthlyRequests *int64 `infracost_usage:"monthly_requests"`
}
func (r *ACMPCACertificateAuthority) CoreType() string {
return "ACMPCACertificateAuthority"
}
func (r *ACMPCACertificateAuthority) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "monthly_requests", ValueType: schema.Int64, DefaultValue: 0},
}
}
func (r *ACMPCACertificateAuthority) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *ACMPCACertificateAuthority) BuildResource() *schema.Resource {
costComponents := []*schema.CostComponent{
r.certificateAuthorityCostComponent(),
}
if r.MonthlyRequests != nil {
monthlyCertificatesRequests := decimal.NewFromInt(*r.MonthlyRequests)
if r.shortLived() {
costComponents = append(costComponents, r.certificateCostComponent("Certificates (short-lived)", "0", &monthlyCertificatesRequests))
} else {
certificateTierLimits := []int{1000, 9000}
certificateTiers := usage.CalculateTierBuckets(monthlyCertificatesRequests, certificateTierLimits)
if certificateTiers[0].GreaterThan(decimal.NewFromInt(0)) {
costComponents = append(costComponents, r.certificateCostComponent("Certificates (first 1K)", "0", &certificateTiers[0]))
}
if certificateTiers[1].GreaterThan(decimal.NewFromInt(0)) {
costComponents = append(costComponents, r.certificateCostComponent("Certificates (next 9K)", "1000", &certificateTiers[1]))
}
if certificateTiers[2].GreaterThan(decimal.NewFromInt(0)) {
costComponents = append(costComponents, r.certificateCostComponent("Certificates (over 10K)", "10000", &certificateTiers[2]))
}
}
} else {
var unknown *decimal.Decimal
if r.shortLived() {
costComponents = append(costComponents, r.certificateCostComponent("Certificates (short-lived)", "0", unknown))
} else {
costComponents = append(costComponents, r.certificateCostComponent("Certificates (first 1K)", "0", unknown))
}
}
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
UsageSchema: r.UsageSchema(),
}
}
func (r *ACMPCACertificateAuthority) shortLived() bool {
return strings.ToLower(r.UsageMode) == "short_lived_certificate"
}
func (r *ACMPCACertificateAuthority) certificateAuthorityCostComponent() *schema.CostComponent {
name := "Private certificate authority"
regex := "/-PaidPrivateCA/"
if r.shortLived() {
name = "Private certificate authority (short-lived certificate mode)"
regex = "/-ShortLivedCertificatePrivateCA/"
}
return &schema.CostComponent{
Name: name,
Unit: "months",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: decimalPtr(decimal.NewFromInt(1)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AWSCertificateManager"),
ProductFamily: strPtr("AWS Certificate Manager"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: ®ex},
},
},
}
}
func (r *ACMPCACertificateAuthority) certificateCostComponent(displayName string, usageTier string, monthlyQuantity *decimal.Decimal) *schema.CostComponent {
regex := "/-PrivateCertificatesIssued/"
if r.shortLived() {
regex = "/-ShortLivedCertificatesIssued/"
}
return &schema.CostComponent{
Name: displayName,
Unit: "requests",
UnitMultiplier: decimal.NewFromInt(1),
MonthlyQuantity: monthlyQuantity,
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AWSCertificateManager"),
ProductFamily: strPtr("AWS Certificate Manager"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: ®ex},
},
},
PriceFilter: &schema.PriceFilter{
StartUsageAmount: strPtr(usageTier),
},
UsageBased: true,
}
}