-
Notifications
You must be signed in to change notification settings - Fork 523
/
elasticache_replication_group.go
100 lines (86 loc) 路 3.08 KB
/
elasticache_replication_group.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
package aws
import (
"strings"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
)
type ElastiCacheReplicationGroup struct {
Address string
Region string
NodeType string
Engine string
CacheClusters int64
ClusterNodeGroups int64
ClusterReplicasPerNodeGroup int64
SnapshotRetentionLimit int64
SnapshotStorageSizeGB *float64 `infracost_usage:"snapshot_storage_size_gb"`
ReservedInstanceTerm *string `infracost_usage:"reserved_instance_term"`
ReservedInstancePaymentOption *string `infracost_usage:"reserved_instance_payment_option"`
AppAutoscalingTarget []*AppAutoscalingTarget
}
func (r *ElastiCacheReplicationGroup) CoreType() string {
return "ElastiCacheReplicationGroup"
}
func (r *ElastiCacheReplicationGroup) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{
{Key: "snapshot_storage_size_gb", ValueType: schema.Float64, DefaultValue: 0},
{Key: "reserved_instance_term", DefaultValue: "", ValueType: schema.String},
{Key: "reserved_instance_payment_option", DefaultValue: "", ValueType: schema.String},
}
}
func (r *ElastiCacheReplicationGroup) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *ElastiCacheReplicationGroup) BuildResource() *schema.Resource {
engine := r.Engine
if engine == "" {
engine = "redis"
}
var autoscaling bool
nodeGroups := r.ClusterNodeGroups
replicasPerNodeGroup := r.ClusterReplicasPerNodeGroup
for _, target := range r.AppAutoscalingTarget {
switch target.ScalableDimension {
case "elasticache:replication-group:NodeGroups":
autoscaling = true
if target.Capacity != nil {
nodeGroups = *target.Capacity
} else {
nodeGroups = target.MinCapacity
}
case "elasticache:replication-group:Replicas":
autoscaling = true
if target.Capacity != nil {
replicasPerNodeGroup = *target.Capacity
} else {
replicasPerNodeGroup = target.MinCapacity
}
}
}
cacheNodes := r.CacheClusters
if nodeGroups > 0 {
// CacheClusters is mutually exclusive with ClusterNodeGroups/ClusterReplicasPerNodeGroup
cacheNodes = (nodeGroups * replicasPerNodeGroup) + nodeGroups
}
cluster := &ElastiCacheCluster{
Region: r.Region,
NodeType: r.NodeType,
Engine: engine,
CacheNodes: cacheNodes,
SnapshotRetentionLimit: r.SnapshotRetentionLimit,
SnapshotStorageSizeGB: r.SnapshotStorageSizeGB,
ReservedInstanceTerm: r.ReservedInstanceTerm,
ReservedInstancePaymentOption: r.ReservedInstancePaymentOption,
}
costComponents := []*schema.CostComponent{
cluster.elastiCacheCostComponent(autoscaling),
}
if strings.ToLower(engine) == "redis" && r.SnapshotRetentionLimit > 1 {
costComponents = append(costComponents, cluster.backupStorageCostComponent())
}
return &schema.Resource{
Name: r.Address,
CostComponents: costComponents,
UsageSchema: r.UsageSchema(),
}
}