-
Notifications
You must be signed in to change notification settings - Fork 523
/
eip.go
64 lines (56 loc) 路 1.54 KB
/
eip.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
package aws
import (
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)
type EIP struct {
Address string
Region string
Allocated bool
}
func (r *EIP) CoreType() string {
return "EIP"
}
func (r *EIP) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{}
}
func (r *EIP) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *EIP) BuildResource() *schema.Resource {
// The EIP is free if allocated. AWS does this to encourage efficient use of Elastic IPs
// and discourage users from leaving unused EIPs lying around in their AWS account.
if r.Allocated {
return &schema.Resource{
Name: r.Address,
NoPrice: true,
IsSkipped: true,
UsageSchema: r.UsageSchema(),
}
}
return &schema.Resource{
Name: r.Address,
CostComponents: []*schema.CostComponent{
{
Name: "IP address (if unused)",
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: decimalPtr(decimal.NewFromInt(1)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonEC2"),
ProductFamily: strPtr("IP Address"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "usagetype", ValueRegex: strPtr("/ElasticIP:IdleAddress/")},
},
},
PriceFilter: &schema.PriceFilter{
StartUsageAmount: strPtr("1"),
},
},
},
UsageSchema: r.UsageSchema(),
}
}