cost

package
v1.10.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
var Zero = Cost{}

Zero is Cost with zero value.

Functions

This section is empty.

Types

type Component

type Component struct {
	Name            string
	MonthlyQuantity decimal.Decimal
	HourlyQuantity  decimal.Decimal
	Unit            string
	Rate            Cost
	Details         []string
	Usage           bool

	Error error
}

Component describes the pricing of a single resource cost component. This includes Rate and Quantity and allows for final cost computation.

func (Component) Cost

func (c Component) Cost() Cost

Cost returns the cost of this component (Rate multiplied by Quantity).

func (Component) GetRounded

func (c Component) GetRounded() Component

GetRounded returns component with rounded values to show

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 (Cost) Add

func (c Cost) Add(c2 Cost) (Cost, error)

Add adds the values of two Cost structs. If the currency of both costs doesn't match, error is returned.

func (Cost) Hourly

func (c Cost) Hourly() decimal.Decimal

Hourly returns the cost per hour.

func (Cost) Monthly

func (c Cost) Monthly() decimal.Decimal

Monthly returns the cost per month.

func (Cost) MulDecimal

func (c Cost) MulDecimal(d decimal.Decimal) Cost

MulDecimal multiplies the Cost by the given decimal.Decimal.

type ModularState added in v1.7.0

type ModularState struct {
	ChildModules map[string]ModularState
	Resources    map[string]Resource
}

func (*ModularState) Cost added in v1.7.0

func (s *ModularState) Cost() (Cost, error)

func (*ModularState) ToClassicState added in v1.7.0

func (s *ModularState) ToClassicState() *State

func (*ModularState) TotalResourcesCount added in v1.7.0

func (s *ModularState) TotalResourcesCount() int

type Resource

type Resource struct {
	Address     string
	Provider    string
	Type        string
	Components  map[string][]Component
	Skipped     bool
	IsSupported bool
}

Resource represents costs of a single cloud resource. Each Resource includes a Component map, keyed by the label.

func (Resource) Cost

func (re Resource) Cost() (Cost, error)

Cost returns the sum of costs of every Component of this Resource. Error is returned if there is a mismatch in Component currency.

func (Resource) CostRows

func (re Resource) CostRows() ([]table.Row, error)

CostRows returns rows for resource components containing the components costs and total cost for the resource

type State

type State struct {
	Resources map[string]Resource
}

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.

func (*State) AddComponent

func (s *State) AddComponent(resAddress, compLabel string, component Component)

AddComponent adds the Component with given label to the Resource at given address.

func (*State) Cost

func (s *State) Cost() (Cost, error)

Cost returns the sum of the costs of every Resource included in this State. Error is returned if there is a mismatch in resource currencies.

func (*State) CostString

func (s *State) CostString() (string, error)

CostString returns a string to show the breakdown of the costs for a state containing the resources and their components costs and total cost for the resources and the state

func (*State) EnsureResource

func (s *State) EnsureResource(address, typ string, provider string, skipped, isSupported bool)

EnsureResource creates Resource at the given address if it doesn't already exist.

func (*State) GetCostComponents

func (s *State) GetCostComponents() []Component

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL