Documentation
¶
Overview ¶
Package provider defines provider-agnostic interfaces for cloud cost estimation. AWS, GCP, Azure handlers all implement these interfaces.
Index ¶
- Constants
- func FixedMonthlyCost(monthly float64) (hourly, monthly2 float64)
- func GetBoolAttr(attrs map[string]any, key string) bool
- func GetFloatAttr(attrs map[string]any, key string) float64
- func GetIntAttr(attrs map[string]any, key string) int
- func GetStringAttr(attrs map[string]any, key string) string
- func HourlyCost(pricePerHour float64) (hourly, monthly float64)
- func LogUnsupported(resourceType, address string)
- func ScaledHourlyCost(pricePerHour float64, count int) (hourly, monthly float64)
- type CompoundHandler
- type CostCategory
- type Describer
- type LookupBuilder
- type Registry
- func (r *Registry) IsSupported(resourceType ResourceType) bool
- func (r *Registry) Register(providerID string, resourceType ResourceType, handler ResourceHandler)
- func (r *Registry) ResolveHandler(providerID string, resourceType ResourceType) (ResourceHandler, bool)
- func (r *Registry) SupportedTypes() []string
- type ResourceHandler
- type ResourceType
- type RuntimeDeps
- type SubResource
Constants ¶
const HoursPerMonth = 730
HoursPerMonth is the average number of hours in a month for cost calculations.
Variables ¶
This section is empty.
Functions ¶
func FixedMonthlyCost ¶
FixedMonthlyCost returns hourly and monthly costs from a fixed monthly rate.
func GetBoolAttr ¶
GetBoolAttr extracts a bool attribute from a resource attributes map.
func GetFloatAttr ¶
GetFloatAttr extracts a float64 attribute from a resource attributes map.
func GetIntAttr ¶
GetIntAttr extracts an int attribute from a resource attributes map.
func GetStringAttr ¶
GetStringAttr extracts a string attribute from a resource attributes map.
func HourlyCost ¶
HourlyCost returns hourly and monthly costs from an hourly rate.
func LogUnsupported ¶
func LogUnsupported(resourceType, address string)
LogUnsupported logs unsupported resource types at debug level.
func ScaledHourlyCost ¶
ScaledHourlyCost returns hourly and monthly costs for multiple units at an hourly rate.
Types ¶
type CompoundHandler ¶
type CompoundHandler interface {
SubResources(attrs map[string]any) []SubResource
}
CompoundHandler is implemented by handlers that produce additional sub-resource costs. The estimator dispatches each SubResource to the appropriate handler.
type CostCategory ¶
type CostCategory int
CostCategory classifies how a handler calculates costs.
const ( // CostCategoryStandard requires pricing API lookup. CostCategoryStandard CostCategory = iota // CostCategoryFixed uses hardcoded costs (no API call needed). CostCategoryFixed // CostCategoryUsageBased is usage-based pricing (returns $0 for fixed estimates). CostCategoryUsageBased )
type Describer ¶ added in v0.9.0
type Describer interface {
// Describe returns human-readable resource details.
// price may be nil for Fixed/UsageBased handlers or before API lookup.
Describe(price *pricing.Price, attrs map[string]any) map[string]string
}
Describer is implemented by handlers that expose human-readable resource details.
type LookupBuilder ¶ added in v0.9.0
type LookupBuilder interface {
// BuildLookup creates a PriceLookup from terraform resource attributes.
BuildLookup(region string, attrs map[string]any) (*pricing.PriceLookup, error)
}
LookupBuilder is implemented by handlers that require a pricing lookup.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps terraform resource types to cost estimation handlers. Provider-agnostic: AWS, GCP, Azure handlers all register here.
func (*Registry) IsSupported ¶
func (r *Registry) IsSupported(resourceType ResourceType) bool
IsSupported checks if a resource type is supported.
func (*Registry) Register ¶
func (r *Registry) Register(providerID string, resourceType ResourceType, handler ResourceHandler)
Register adds a handler for a resource type.
func (*Registry) ResolveHandler ¶ added in v0.9.0
func (r *Registry) ResolveHandler(providerID string, resourceType ResourceType) (ResourceHandler, bool)
ResolveHandler returns a handler scoped to a provider and resource type.
func (*Registry) SupportedTypes ¶
SupportedTypes returns all supported resource types.
type ResourceHandler ¶
type ResourceHandler interface {
// Category returns how this handler calculates costs.
Category() CostCategory
// CalculateCost calculates monthly cost from price, index, and resource attributes.
// For Fixed/UsageBased handlers, price and index may be nil.
CalculateCost(price *pricing.Price, index *pricing.PriceIndex, region string, attrs map[string]any) (hourly, monthly float64)
}
ResourceHandler extracts pricing information from terraform resource attributes. Implemented by each cloud provider's resource handlers.
type ResourceType ¶ added in v0.9.0
type ResourceType string
ResourceType is a provider-neutral Terraform resource identifier.
func (ResourceType) String ¶ added in v0.9.0
func (r ResourceType) String() string
String returns the raw Terraform resource type value.
type RuntimeDeps ¶ added in v0.9.0
type RuntimeDeps[T any] struct { Runtime *T }
RuntimeDeps stores an optional provider runtime dependency for a handler. Zero value is valid and can be paired with a fallback in tests.
func (RuntimeDeps[T]) RuntimeOr ¶ added in v0.9.0
func (d RuntimeDeps[T]) RuntimeOr(fallback *T) *T
RuntimeOr returns the injected runtime or the provided fallback when unset.
type SubResource ¶
type SubResource struct {
Suffix string // Address suffix, e.g., "/root_volume"
Type ResourceType // Resource type for handler lookup, e.g., "aws_ebs_volume"
Attrs map[string]any // Translated attributes for the sub-resource handler
}
SubResource represents a virtual sub-resource synthesized from a parent resource's inline attributes (e.g., root_block_device inside aws_instance → aws_ebs_volume).