Documentation ¶
Overview ¶
Package cost defines structures that represent cloud resources and states in a cloud-agnostic, as well as tool-agnostic way. The hierarchy of structs is as follows:
- Component is the lowest level, it describes the cost of a single cloud entity (e.g. storage space or compute time).
- Resource is a collection of components and directly correlates to cloud resources (e.g. VM instance).
- State is a collection of resources that exist (or are planned to exist) at any given moment across one or multiple cloud providers.
- Plan is a difference between two states. It includes the prior (current) state and a planned state and it can be used to retrieve a list of ResourceDiff's.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrProductNotFound = fmt.Errorf("product not found") ErrPriceNotFound = fmt.Errorf("price not found") )
Errors that might be returned from NewState if either a product or a price are not found.
var HoursPerMonth = decimal.NewFromInt(730)
HoursPerMonth is an approximate number of hours in a month. It is calculated as 365 days in a year x 24 hours in a day / 12 months in year.
var Zero = Cost{}
Zero is Cost with zero value.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct { Quantity decimal.Decimal Unit string Rate Cost Details []string Error error }
Component describes the pricing of a single resource cost component. This includes Rate and Quantity and allows for final cost computation.
type ComponentDiff ¶
type ComponentDiff struct {
Prior, Planned *Component
}
ComponentDiff is a difference between the Prior and Planned Component.
func (ComponentDiff) PlannedCost ¶
func (cd ComponentDiff) PlannedCost() Cost
PlannedCost returns the full cost of the Planned Component or decimal.Zero if it doesn't exist.
func (ComponentDiff) PriorCost ¶
func (cd ComponentDiff) PriorCost() Cost
PriorCost returns the full cost of the Prior Component or decimal.Zero if it doesn't exist.
func (ComponentDiff) Valid ¶
func (cd ComponentDiff) Valid() bool
Valid returns true if there are no errors in both the Planned and Prior components.
type Cost ¶
type Cost struct { // Decimal is price per month. decimal.Decimal // Currency of the cost. Currency string }
Cost represents a monthly or hourly cost of a cloud resource or its component.
func NewMonthly ¶
NewMonthly returns a new Cost from price per month with currency.
type Plan ¶
type Plan struct {
Prior, Planned *State
}
Plan is the cost difference between two State instances. It is not tied to any specific cloud provider or IaC tool. Instead, it is a representation of the differences between two snapshots of cloud resources, with their associated costs. The Plan instance can be used to calculate the total cost difference of a plan, as well as cost differences of each resource (and their components) separately.
func (Plan) PlannedCost ¶
PlannedCost returns the total cost of the Planned State or decimal.Zero if it isn't included in the plan.
func (Plan) PriorCost ¶
PriorCost returns the total cost of the Prior State or decimal.Zero if it isn't included in the plan.
func (Plan) ResourceDifferences ¶
func (p Plan) ResourceDifferences() []ResourceDiff
ResourceDifferences merges the Prior and Planned State and returns a slice of differences between resources. The order of the elements in the slice is undefined and unstable.
func (Plan) SkippedAddresses ¶
SkippedAddresses returns the addresses of resources that were excluded from the estimation process. The order of the elements in the slice is undefined and unstable.
type Resource ¶
Resource represents costs of a single cloud resource. Each Resource includes a Component map, keyed by the label.
type ResourceDiff ¶
type ResourceDiff struct { Address string Provider string Type string ComponentDiffs map[string]*ComponentDiff }
ResourceDiff is the difference in costs between prior and planned Resource. It contains a ComponentDiff map, keyed by the label.
func (ResourceDiff) Errors ¶
func (rd ResourceDiff) Errors() map[string]error
Errors returns a map of Component errors keyed by the Component label.
func (ResourceDiff) PlannedCost ¶
func (rd ResourceDiff) PlannedCost() (Cost, error)
PlannedCost returns the sum of costs of every Component's PlannedCost. Error is returned if there is a mismatch between currencies of the Components.
func (ResourceDiff) PriorCost ¶
func (rd ResourceDiff) PriorCost() (Cost, error)
PriorCost returns the sum of costs of every Component's PriorCost. Error is returned if there is a mismatch between currencies of the Components.
func (ResourceDiff) Valid ¶
func (rd ResourceDiff) Valid() bool
Valid returns true if there are no errors in all of the ResourceDiff's components.
type State ¶
State represents a collection of all the Resource costs (either prior or planned.) It is not tied to any specific cloud provider or IaC tool. Instead, it is a representation of a snapshot of cloud resources at a given point in time, with their associated costs.