schema

package
v0.10.35 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HourToMonthUnitMultiplier = decimal.NewFromInt(730)
	MonthToHourUnitMultiplier = decimal.NewFromInt(1).Div(HourToMonthUnitMultiplier)
	DaysInMonth               = HourToMonthUnitMultiplier.DivRound(decimal.NewFromInt(24), 24)
	DayToMonthUnitMultiplier  = DaysInMonth.DivRound(HourToMonthUnitMultiplier, 24)
)

Functions

func AddRawValue

func AddRawValue(r gjson.Result, key string, v interface{}) gjson.Result

func BuildResources added in v0.10.14

func BuildResources(projects []*Project, projectPtrToUsageMap map[*Project]UsageMap)

func CalculateCosts

func CalculateCosts(project *Project)

func IsEmptyPathTypeError added in v0.10.35

func IsEmptyPathTypeError(err error) bool

IsEmptyPathTypeError checks if the error is a diag for an empty path type.

func MultiplyQuantities added in v0.7.4

func MultiplyQuantities(resource *Resource, multiplier decimal.Decimal)

func ParseAttributes added in v0.7.15

func ParseAttributes(i interface{}) map[string]gjson.Result

func SortResources

func SortResources(project *Project)

Types

type ActualCosts added in v0.10.12

type ActualCosts struct {
	ResourceID     string
	StartTimestamp time.Time
	EndTimestamp   time.Time
	CostComponents []*CostComponent
}

type AttributeFilter

type AttributeFilter struct {
	Key        string  `json:"key"`
	Value      *string `json:"value,omitempty"`
	ValueRegex *string `json:"value_regex,omitempty"`
}

type BlankCoreResource added in v0.10.18

type BlankCoreResource struct {
	Name string
	Type string
}

BlankCoreResource is a helper struct for NoPrice and Skipped resources that are evaluated as part of the Policy API. This implements the CoreResource interface and returns a skipped resource that doesn't affect the CLI output.

func (BlankCoreResource) BuildResource added in v0.10.18

func (b BlankCoreResource) BuildResource() *Resource

func (BlankCoreResource) CoreType added in v0.10.18

func (b BlankCoreResource) CoreType() string

func (BlankCoreResource) PopulateUsage added in v0.10.18

func (b BlankCoreResource) PopulateUsage(u *UsageData)

func (BlankCoreResource) UsageSchema added in v0.10.18

func (b BlankCoreResource) UsageSchema() []*UsageItem

type CloudResourceIDFunc added in v0.10.13

type CloudResourceIDFunc func(d *ResourceData) []string

CloudResourceIDFunc is used to calculate the cloud resource ids (AWS ARN, Google HREF, etc...) associated with the resource

type CoreResource added in v0.10.12

type CoreResource interface {
	CoreType() string
	UsageSchema() []*UsageItem
	PopulateUsage(u *UsageData)
	BuildResource() *Resource
}

CoreResource is the new/preferred way to represent provider-agnostic resources that support advanced features such as Infracost Cloud usage estimates and actual costs.

type CoreResourceFunc added in v0.10.12

type CoreResourceFunc func(*ResourceData) CoreResource

type CoreResourceWithUsageParams added in v0.10.13

type CoreResourceWithUsageParams interface {
	CoreResource
	UsageEstimationParams() []UsageParam
}

CoreResourceWithUsageParams is a CoreResource that sends additional parameters (e.g. Lambda memory size) to the Usage API when estimating usage.

type CostComponent

type CostComponent struct {
	Name           string
	Unit           string
	UnitMultiplier decimal.Decimal
	// UnitRounding specifies the number of decimal places that the output unit should be rounded to.
	// This should be set to 0 if using MonthToHourUnitMultiplier otherwise the unit will show with
	// redundant .000 decimal places.
	UnitRounding         *int32
	IgnoreIfMissingPrice bool
	ProductFilter        *ProductFilter
	PriceFilter          *PriceFilter
	HourlyQuantity       *decimal.Decimal
	MonthlyQuantity      *decimal.Decimal
	MonthlyDiscountPerc  float64

	HourlyCost  *decimal.Decimal
	MonthlyCost *decimal.Decimal
	UsageBased  bool
	// contains filtered or unexported fields
}

func (*CostComponent) CalculateCosts

func (c *CostComponent) CalculateCosts()

func (*CostComponent) CustomPrice added in v0.9.22

func (c *CostComponent) CustomPrice() *decimal.Decimal

func (*CostComponent) Price

func (c *CostComponent) Price() decimal.Decimal

func (*CostComponent) PriceHash

func (c *CostComponent) PriceHash() string

func (*CostComponent) SetCustomPrice added in v0.9.22

func (c *CostComponent) SetCustomPrice(price *decimal.Decimal)

func (*CostComponent) SetPrice

func (c *CostComponent) SetPrice(price decimal.Decimal)

func (*CostComponent) SetPriceHash

func (c *CostComponent) SetPriceHash(priceHash string)

func (*CostComponent) UnitMultiplierHourlyQuantity added in v0.7.0

func (c *CostComponent) UnitMultiplierHourlyQuantity() *decimal.Decimal

func (*CostComponent) UnitMultiplierMonthlyQuantity added in v0.7.0

func (c *CostComponent) UnitMultiplierMonthlyQuantity() *decimal.Decimal

func (*CostComponent) UnitMultiplierPrice added in v0.7.0

func (c *CostComponent) UnitMultiplierPrice() decimal.Decimal

type EstimateFunc added in v0.9.8

type EstimateFunc func(context.Context, map[string]interface{}) error

EstimateFunc queries cloud providers to gather past usage information, then projects future usage based on the results.

type PartialResource added in v0.10.12

type PartialResource struct {
	Type      string
	Address   string
	Tags      *map[string]string
	UsageData *UsageData
	Metadata  map[string]gjson.Result

	// CoreResource is the new/preferred struct for providing an intermediate-object
	// that contains all provider-derived information, but has not yet been built into
	// a Resource.
	CoreResource CoreResource

	// Resource field is provided for backward compatibility with provider resource builders
	// that have not yet been converted to build CoreResource's
	Resource *Resource

	// CloudResourceIDs are collected during parsing in case they need to be uploaded to the
	// Cloud Usage API to be used in the usage estimate calculations.
	CloudResourceIDs []string
}

PartialResource is used to collect all information required to construct a resource that is generated by provider parser and pass it back up to top level functions that can supply additional provider-agnostic information (such as Infracost Cloud usage estimates) before the resource is built.

func NewPartialResource added in v0.10.33

func NewPartialResource(d *ResourceData, r *Resource, cr CoreResource, cloudResourceIds []string) *PartialResource

type Policies added in v0.10.14

type Policies []Policy

func (Policies) Len added in v0.10.14

func (r Policies) Len() int

func (Policies) Less added in v0.10.14

func (r Policies) Less(i, j int) bool

func (Policies) Swap added in v0.10.14

func (r Policies) Swap(i, j int)

type Policy added in v0.10.14

type Policy struct {
	ID                 string           `json:"id"`
	Title              string           `json:"title"`
	Description        string           `json:"description"`
	ResourceType       string           `json:"resource_type"`
	ResourceAttributes json.RawMessage  `json:"resource_attributes"`
	Address            string           `json:"address"`
	Suggested          string           `json:"suggested"`
	NoCost             bool             `json:"no_cost"`
	Cost               *decimal.Decimal `json:"cost"`
}

type PriceFilter

type PriceFilter struct {
	PurchaseOption     *string `json:"purchaseOption,omitempty"`
	Unit               *string `json:"unit,omitempty"`
	Description        *string `json:"description,omitempty"`
	DescriptionRegex   *string `json:"description_regex,omitempty"`
	StartUsageAmount   *string `json:"startUsageAmount,omitempty"`
	EndUsageAmount     *string `json:"endUsageAmount,omitempty"`
	TermLength         *string `json:"termLength,omitempty"`
	TermPurchaseOption *string `json:"termPurchaseOption,omitempty"`
	TermOfferingClass  *string `json:"termOfferingClass,omitempty"`
}

type ProductFilter

type ProductFilter struct {
	VendorName       *string            `json:"vendorName,omitempty"`
	Service          *string            `json:"service,omitempty"`
	ProductFamily    *string            `json:"productFamily,omitempty"`
	Region           *string            `json:"region,omitempty"`
	Sku              *string            `json:"sku,omitempty"`
	AttributeFilters []*AttributeFilter `json:"attributeFilters,omitempty"`
}

type Project added in v0.7.19

type Project struct {
	Name                 string
	Metadata             *ProjectMetadata
	PartialPastResources []*PartialResource
	PartialResources     []*PartialResource
	PastResources        []*Resource
	Resources            []*Resource
	Diff                 []*Resource
	HasDiff              bool
}

Project contains the existing, planned state of resources and the diff between them.

func NewProject added in v0.7.19

func NewProject(name string, metadata *ProjectMetadata) *Project

func (*Project) AddProviderMetadata added in v0.10.25

func (p *Project) AddProviderMetadata(metadatas []ProviderMetadata)

func (*Project) AllPartialResources added in v0.10.13

func (p *Project) AllPartialResources() []*PartialResource

AllPartialResources returns a pointer list of the current and past partial resources

func (*Project) AllResources added in v0.7.19

func (p *Project) AllResources() []*Resource

AllResources returns a pointer list of all resources of the state.

func (*Project) BuildResources added in v0.10.17

func (p *Project) BuildResources(usageMap UsageMap)

BuildResources builds the resources from the partial resources and sets the PastResources and Resources fields.

func (*Project) CalculateDiff added in v0.7.19

func (p *Project) CalculateDiff()

CalculateDiff calculates the diff of past and current resources

func (*Project) NameWithWorkspace added in v0.10.13

func (p *Project) NameWithWorkspace() string

NameWithWorkspace returns the proect Name appended with the paranenthized workspace name from Metadata if one exists.

type ProjectDiag added in v0.10.17

type ProjectDiag struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	IsError bool        `json:"isError"`

	// FriendlyMessage should be used to display a readable message to the CLI user.
	FriendlyMessage string `json:"-"`
}

ProjectDiag holds information about all diagnostics associated with a project. This can be both critical or warnings.

func NewDiagJSONParsingFailure added in v0.10.34

func NewDiagJSONParsingFailure(err error) *ProjectDiag

NewDiagJSONParsingFailure returns a project diag for a JSON parsing failure in the intermediary JSON that the HCL provider generates. This is considered a critical error as a project will not have any costs if this happens.

func NewDiagMissingVars added in v0.10.34

func NewDiagMissingVars(vars ...string) *ProjectDiag

NewDiagMissingVars returns a ProjectDiag for missing Terraform vars. This is considered a non-critical error and is used to notify the user.

func NewDiagModuleEvaluationFailure added in v0.10.34

func NewDiagModuleEvaluationFailure(err error) *ProjectDiag

NewDiagModuleEvaluationFailure returns a project diag for a module evaluation failure. This is used when a Terraform module fails to evaluate. This can either be a root module of a Terraform project or a child module.

func NewDiagRunQuotaExceeded added in v0.10.34

func NewDiagRunQuotaExceeded(err error) *ProjectDiag

NewDiagRunQuotaExceeded returns a project diag for a run quota exceeded error.

func NewDiagTerragruntEvaluationFailure added in v0.10.34

func NewDiagTerragruntEvaluationFailure(err error) *ProjectDiag

NewDiagTerragruntEvaluationFailure returns a project diag for a Terragrunt evaluation failure. This is used when a Terragrunt fails to run/evaluate in most cases this means that the entire project is not evaluated. It is considered a critical error.

func NewDiagTerragruntModuleEvaluationFailure added in v0.10.34

func NewDiagTerragruntModuleEvaluationFailure(err error) *ProjectDiag

NewDiagTerragruntModuleEvaluationFailure returns a project diag for a terragrunt module evaluation failure. This is used when a Terraform module which a Terragrunt configuration file references fails to evaluate.

func NewEmptyPathTypeError added in v0.10.34

func NewEmptyPathTypeError(err error) *ProjectDiag

NewEmptyPathTypeError returns a project diag to indicate that a path type cannot be detected.

func NewFailedDownloadDiagnostic added in v0.10.34

func NewFailedDownloadDiagnostic(source string, err error) *ProjectDiag

NewFailedDownloadDiagnostic returns a project diag for a failed module download. This contains additional information about the module source and the type of source.

func NewPrivateRegistryDiag added in v0.10.34

func NewPrivateRegistryDiag(source string, moduleLocation *string, err error) *ProjectDiag

NewPrivateRegistryDiag returns a project diag for a private registry module download failure. This contains additional information about the module source and the discovered location returned by the registry.

func (*ProjectDiag) Error added in v0.10.20

func (p *ProjectDiag) Error() string

type ProjectMetadata added in v0.9.0

type ProjectMetadata struct {
	Path                string             `json:"path"`
	Type                string             `json:"type"`
	ConfigSha           string             `json:"configSha,omitempty"`
	PolicySha           string             `json:"policySha,omitempty"`
	PastPolicySha       string             `json:"pastPolicySha,omitempty"`
	TerraformModulePath string             `json:"terraformModulePath,omitempty"`
	TerraformWorkspace  string             `json:"terraformWorkspace,omitempty"`
	VCSSubPath          string             `json:"vcsSubPath,omitempty"`
	VCSCodeChanged      *bool              `json:"vcsCodeChanged,omitempty"`
	Errors              []*ProjectDiag     `json:"errors,omitempty"`
	Warnings            []*ProjectDiag     `json:"warnings,omitempty"`
	Policies            Policies           `json:"policies,omitempty"`
	Providers           []ProviderMetadata `json:"providers,omitempty"`
	RemoteModuleCalls   []string           `json:"remoteModuleCalls,omitempty"`
}

func DetectProjectMetadata added in v0.10.34

func DetectProjectMetadata(path string) *ProjectMetadata

DetectProjectMetadata returns a new ProjectMetadata struct initialized from environment variables and the provided path.

func (*ProjectMetadata) AddError added in v0.10.17

func (m *ProjectMetadata) AddError(err error)

AddError pushes the provided error onto the metadata list. It does a naive conversion to ProjectDiag if the error provided is not already a diagnostic.

func (*ProjectMetadata) GenerateProjectName added in v0.10.10

func (m *ProjectMetadata) GenerateProjectName(remote vcs.Remote, dashboardEnabled bool) string

func (*ProjectMetadata) HasErrors added in v0.10.17

func (m *ProjectMetadata) HasErrors() bool

func (*ProjectMetadata) IsEmptyProjectError added in v0.10.34

func (m *ProjectMetadata) IsEmptyProjectError() bool

func (*ProjectMetadata) IsRunQuotaExceeded added in v0.10.31

func (m *ProjectMetadata) IsRunQuotaExceeded() (string, bool)

IsRunQuotaExceeded checks if any of the project diags are of type "run quota exceeded". If found it returns the associated message with this diag. This should be used when in any output that notifies the user.

func (*ProjectMetadata) WorkspaceLabel added in v0.10.4

func (m *ProjectMetadata) WorkspaceLabel() string

type Projects added in v0.9.23

type Projects []*Project

Projects is a slice of Project that is ordered alphabetically by project name.

func (Projects) Len added in v0.9.23

func (p Projects) Len() int

func (Projects) Less added in v0.9.23

func (p Projects) Less(i, j int) bool

func (Projects) Swap added in v0.9.23

func (p Projects) Swap(i, j int)

type Provider

type Provider interface {
	Type() string
	DisplayType() string
	AddMetadata(*ProjectMetadata)
	LoadResources(UsageMap) ([]*Project, error)
	Context() *config.ProjectContext
}

type ProviderMetadata added in v0.10.25

type ProviderMetadata struct {
	Name        string            `json:"name,omitempty"`
	DefaultTags map[string]string `json:"defaultTags,omitempty"`
	Filename    string            `json:"filename,omitempty"`
	StartLine   int64             `json:"startLine,omitempty"`
	EndLine     int64             `json:"endLine,omitempty"`
}

type ReferenceIDFunc added in v0.9.19

type ReferenceIDFunc func(d *ResourceData) []string

ReferenceIDFunc is used to let references be built using non-standard IDs (anything other than d.Get("id").string)

type RegistryItem

type RegistryItem struct {
	Name                string
	Notes               []string
	RFunc               ResourceFunc
	CoreRFunc           CoreResourceFunc
	ReferenceAttributes []string
	CustomRefIDFunc     ReferenceIDFunc
	DefaultRefIDFunc    ReferenceIDFunc
	CloudResourceIDFunc CloudResourceIDFunc
	NoPrice             bool
}

type Remediater added in v0.9.8

type Remediater interface {
	// Describe provides an English description of the remediation action X that
	// would fit into a sentence "May we X?" (e.g. "enable bucket metrics").
	// The description can be used to prompt the user before taking action.
	Describe() string

	// Remediate attempts to fix a problem in the cloud that prevents estimation,
	// e.g. by enabling metrics collection on certain resources.
	Remediate() error
}

Remediater allows correction of cloud configuration issues so that future runs of Infracost will provide more accurate results.

type Resource

type Resource struct {
	Name              string
	CostComponents    []*CostComponent
	ActualCosts       []*ActualCosts
	SubResources      []*Resource
	HourlyCost        *decimal.Decimal
	MonthlyCost       *decimal.Decimal
	MonthlyUsageCost  *decimal.Decimal
	IsSkipped         bool
	NoPrice           bool
	SkipMessage       string
	ResourceType      string
	Tags              *map[string]string
	UsageSchema       []*UsageItem
	EstimateUsage     EstimateFunc
	EstimationSummary map[string]bool
	Metadata          map[string]gjson.Result
}

func AllProjectResources added in v0.7.19

func AllProjectResources(projects []*Project) []*Resource

AllProjectResources returns the resources for all projects

func BuildResource added in v0.10.12

func BuildResource(partial *PartialResource, fetchedUsage *UsageData) *Resource

BuildResource create a new Resource from the CoreResource, or (for backward compatibility) returns a previously built Resource

func CalculateDiff added in v0.9.23

func CalculateDiff(past []*Resource, current []*Resource) []*Resource

CalculateDiff calculates the diff of past and current resources

func (*Resource) CalculateCosts

func (r *Resource) CalculateCosts()

func (*Resource) FlattenedSubResources

func (r *Resource) FlattenedSubResources() []*Resource

func (*Resource) RemoveCostComponent

func (r *Resource) RemoveCostComponent(costComponent *CostComponent)

type ResourceData

type ResourceData struct {
	Type          string
	ProviderName  string
	Address       string
	Tags          *map[string]string
	RawValues     gjson.Result
	ReferencesMap map[string][]*ResourceData
	CFResource    cloudformation.Resource
	UsageData     *UsageData
	Metadata      map[string]gjson.Result
}

func NewCFResourceData added in v0.9.2

func NewCFResourceData(resourceType string, providerName string, address string, tags *map[string]string, cfResource cloudformation.Resource) *ResourceData

func NewResourceData

func NewResourceData(resourceType string, providerName string, address string, tags *map[string]string, rawValues gjson.Result) *ResourceData

func (*ResourceData) AddReference

func (d *ResourceData) AddReference(k string, reference *ResourceData, reverseRefAttrs []string)

func (*ResourceData) Get

func (d *ResourceData) Get(key string) gjson.Result

func (*ResourceData) GetBoolOrDefault added in v0.9.19

func (d *ResourceData) GetBoolOrDefault(key string, def bool) bool

func (*ResourceData) GetFloat64OrDefault added in v0.9.21

func (d *ResourceData) GetFloat64OrDefault(key string, def float64) float64

GetFloat64OrDefault returns the value of key within ResourceData as a float64. If the retrieved value is not set GetFloat64OrDefault will return def.

func (*ResourceData) GetInt64OrDefault added in v0.9.19

func (d *ResourceData) GetInt64OrDefault(key string, def int64) int64

GetInt64OrDefault returns the value of key within ResourceData as an int64. If the retrieved value is not set GetInt64OrDefault will return def.

func (*ResourceData) GetStringOrDefault added in v0.9.19

func (d *ResourceData) GetStringOrDefault(key, def string) string

GetStringOrDefault returns the value of key within ResourceData as a string. If the retrieved value is not set GetStringOrDefault will return def.

func (*ResourceData) IsEmpty added in v0.9.11

func (d *ResourceData) IsEmpty(key string) bool

Return true if the key doesn't exist, is null, or is an empty string. Needed because gjson.Exists returns true as long as a key exists, even if it's empty or null.

func (*ResourceData) References

func (d *ResourceData) References(keys ...string) []*ResourceData

func (*ResourceData) Set

func (d *ResourceData) Set(key string, value interface{})

type ResourceFunc

type ResourceFunc func(*ResourceData, *UsageData) *Resource

type UsageData added in v0.7.12

type UsageData struct {
	Address    string
	Attributes map[string]gjson.Result
}

func NewUsageData added in v0.7.12

func NewUsageData(address string, attributes map[string]gjson.Result) *UsageData

func (*UsageData) CalcEstimationSummary added in v0.9.8

func (u *UsageData) CalcEstimationSummary() map[string]bool

CalcEstimationSummary returns a map where a value of true means the attribute key has an actual estimate, false means it is using the defaults

func (*UsageData) Copy added in v0.10.18

func (u *UsageData) Copy() *UsageData

Copy returns a clone of UsageData u.

func (*UsageData) Get added in v0.7.12

func (u *UsageData) Get(key string) gjson.Result

func (*UsageData) GetFloat added in v0.9.2

func (u *UsageData) GetFloat(key string) *float64

func (*UsageData) GetInt added in v0.9.2

func (u *UsageData) GetInt(key string) *int64

func (*UsageData) GetString added in v0.9.7

func (u *UsageData) GetString(key string) *string

func (*UsageData) GetStringArray added in v0.9.7

func (u *UsageData) GetStringArray(key string) *[]string

func (*UsageData) IsEmpty added in v0.9.11

func (u *UsageData) IsEmpty(key string) bool

Return true if the key doesn't exist, is null, or is an empty string. Needed because gjson.Exists returns true as long as a key exists, even if it's empty or null.

func (*UsageData) Merge added in v0.10.12

func (u *UsageData) Merge(other *UsageData) *UsageData

Merge returns a new UsageData which is the result of adding all keys from other that do not already exists in the usage data

type UsageItem added in v0.9.11

type UsageItem struct {
	Key          string
	DefaultValue interface{}
	Value        interface{}
	ValueType    UsageVariableType
	Description  string
}

type UsageMap added in v0.10.18

type UsageMap struct {
	// contains filtered or unexported fields
}

UsageMap is a map of address to UsageData built from a usage file. UsageMap is a standalone type so that we can do more involved matching functionality.

func NewUsageMap added in v0.7.15

func NewUsageMap(data map[string]*UsageData) UsageMap

NewUsageMap initialises a Usage map with the provided usage key data. It builds a set of wildcard keys if any are found and sorts them ready for searching by Attribute name at a later point.

func NewUsageMapFromInterface added in v0.10.18

func NewUsageMapFromInterface(m map[string]interface{}) UsageMap

NewUsageMapFromInterface returns an initialised UsageMap from interface map.

func (UsageMap) Data added in v0.10.18

func (usage UsageMap) Data() map[string]*UsageData

Data returns the entire map of usage data stored.

func (UsageMap) Get added in v0.10.18

func (usage UsageMap) Get(address string) *UsageData

Get returns UsageData for a given resource address, this can be a combined/merged UsageData from multiple keys. Usage data is merged adhering to the following hierarchy:

  1. Resource type defaults - e.g. aws_lambda:
  2. Wildcard specified data - e.g. aws_lambda.my_lambda[*]
  3. Exact resource data - e.g. aws_lambda.my_lambda["foo"]

Duplicate keys specified between levels are always overwritten by keys specified at a lower level, e.g:

aws_lambda.my_lambda[*]:
	monthly_requests: 700000000
	request_duration_ms: 750
aws_lambda.my_lambda["foo"]:
	request_duration_ms: 100 << this overwrites the 750 value given in the wildcard usage

If no usage key is found, Get will return nil.

type UsageParam added in v0.10.13

type UsageParam struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type UsageVariableType added in v0.9.2

type UsageVariableType int
const (
	Int64 UsageVariableType = iota
	String
	Float64
	StringArray
	SubResourceUsage
	KeyValueMap
)

Jump to

Keyboard shortcuts

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