-
Notifications
You must be signed in to change notification settings - Fork 523
/
lightsail_instance.go
90 lines (76 loc) 路 2.23 KB
/
lightsail_instance.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
package aws
import (
"fmt"
"strings"
"github.com/infracost/infracost/internal/logging"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
"github.com/shopspring/decimal"
)
type LightsailInstance struct {
Address string
Region string
BundleID string
}
func (r *LightsailInstance) CoreType() string {
return "LightsailInstance"
}
func (r *LightsailInstance) UsageSchema() []*schema.UsageItem {
return []*schema.UsageItem{}
}
func (r *LightsailInstance) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(r, u)
}
func (r *LightsailInstance) BuildResource() *schema.Resource {
type bundleSpecs struct {
vcpu string
memory string
}
bundlePrefixMappings := map[string]bundleSpecs{
"nano": {"2", "0.5GB"},
"micro": {"2", "1GB"},
"small": {"2", "2GB"},
"medium": {"2", "4GB"},
"large": {"2", "8GB"},
"xlarge": {"4", "16GB"},
"2xlarge": {"8", "32GB"},
}
operatingSystem := "Linux"
operatingSystemLabel := "Linux/UNIX"
if strings.Contains(strings.ToLower(r.BundleID), "_win_") {
operatingSystem = "Windows"
operatingSystemLabel = "Windows"
}
bundlePrefix := strings.Split(strings.ToLower(r.BundleID), "_")[0]
specs, ok := bundlePrefixMappings[bundlePrefix]
if !ok {
logging.Logger.Warn().Msgf("Skipping resource %s. Unrecognized bundle_id %s", r.Address, r.BundleID)
return nil
}
return &schema.Resource{
Name: r.Address,
CostComponents: []*schema.CostComponent{
{
Name: fmt.Sprintf("Virtual server (%s)", operatingSystemLabel),
Unit: "hours",
UnitMultiplier: decimal.NewFromInt(1),
HourlyQuantity: decimalPtr(decimal.NewFromInt(1)),
ProductFilter: &schema.ProductFilter{
VendorName: strPtr("aws"),
Region: strPtr(r.Region),
Service: strPtr("AmazonLightsail"),
ProductFamily: strPtr("Lightsail Instance"),
AttributeFilters: []*schema.AttributeFilter{
{Key: "operatingSystem", Value: strPtr(operatingSystem)},
{Key: "vcpu", Value: strPtr(specs.vcpu)},
{Key: "memory", Value: strPtr(specs.memory)},
},
},
PriceFilter: &schema.PriceFilter{
EndUsageAmount: strPtr("Inf"),
},
},
},
UsageSchema: r.UsageSchema(),
}
}