-
Notifications
You must be signed in to change notification settings - Fork 524
/
launch_configuration.go
101 lines (86 loc) 路 3.4 KB
/
launch_configuration.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
package aws
import (
"strings"
"github.com/shopspring/decimal"
"github.com/infracost/infracost/internal/logging"
"github.com/infracost/infracost/internal/resources"
"github.com/infracost/infracost/internal/schema"
)
type LaunchConfiguration struct {
// "required" args that can't really be missing.
Address string
Region string
Tenancy string
PurchaseOption string
AMI string
InstanceType string
EBSOptimized bool
EnableMonitoring bool
CPUCredits string
// "optional" args, that may be empty depending on the resource config
ElasticInferenceAcceleratorType *string
RootBlockDevice *EBSVolume
EBSBlockDevices []*EBSVolume
// "usage" args
// These are populated from the Autoscaling Group resource
InstanceCount *int64 `infracost_usage:"instances"`
OperatingSystem *string `infracost_usage:"operating_system"`
ReservedInstanceType *string `infracost_usage:"reserved_instance_type"`
ReservedInstanceTerm *string `infracost_usage:"reserved_instance_term"`
ReservedInstancePaymentOption *string `infracost_usage:"reserved_instance_payment_option"`
MonthlyCPUCreditHours *int64 `infracost_usage:"monthly_cpu_credit_hrs"`
VCPUCount *int64 `infracost_usage:"vcpu_count"`
}
var LaunchConfigurationUsageSchema = InstanceUsageSchema
func (r *LaunchConfiguration) CoreType() string {
return "LaunchConfiguration"
}
func (r *LaunchConfiguration) UsageSchema() []*schema.UsageItem {
return LaunchConfigurationUsageSchema
}
func (a *LaunchConfiguration) PopulateUsage(u *schema.UsageData) {
resources.PopulateArgsWithUsage(a, u)
}
func (a *LaunchConfiguration) BuildResource() *schema.Resource {
if strings.ToLower(a.Tenancy) == "host" {
logging.Logger.Warn().Msgf("Skipping resource %s. Infracost currently does not support host tenancy for AWS Launch Configurations", a.Address)
return nil
} else if strings.ToLower(a.Tenancy) == "dedicated" {
a.Tenancy = "Dedicated"
} else {
a.Tenancy = "Shared"
}
instance := &Instance{
Region: a.Region,
Tenancy: a.Tenancy,
PurchaseOption: a.PurchaseOption,
AMI: a.AMI,
InstanceType: a.InstanceType,
EBSOptimized: a.EBSOptimized,
EnableMonitoring: a.EnableMonitoring,
CPUCredits: a.CPUCredits,
ElasticInferenceAcceleratorType: a.ElasticInferenceAcceleratorType,
OperatingSystem: a.OperatingSystem,
RootBlockDevice: a.RootBlockDevice,
EBSBlockDevices: a.EBSBlockDevices,
ReservedInstanceType: a.ReservedInstanceType,
ReservedInstanceTerm: a.ReservedInstanceTerm,
ReservedInstancePaymentOption: a.ReservedInstancePaymentOption,
MonthlyCPUCreditHours: a.MonthlyCPUCreditHours,
VCPUCount: a.VCPUCount,
}
instanceResource := instance.BuildResource()
r := &schema.Resource{
Name: a.Address,
UsageSchema: a.UsageSchema(),
CostComponents: instanceResource.CostComponents,
SubResources: instanceResource.SubResources,
EstimateUsage: instanceResource.EstimateUsage,
}
qty := int64(1)
if a.InstanceCount != nil {
qty = *a.InstanceCount
}
schema.MultiplyQuantities(r, decimal.NewFromInt(qty))
return r
}