Documentation
¶
Index ¶
- Constants
- func ApplyDiscount(price *rat.Rat, discountRate *rat.Rat) *rat.Rat
- func ComponentMonthlyCost(c *provider.CostComponent) *rat.Rat
- func ConvertQuantityByPeriod(qty *rat.Rat, period provider.Period) (hourly, monthly *rat.Rat)
- func CountUsage(usageData *usage.Usage) (estimated, unestimated map[string]int)
- func EvaluateGuardrails(guardrails []*event.Guardrail, baseProjects, headProjects []ProjectResult) []goprotoevent.GuardrailResult
- func EvaluateProductionFilters(filters []*event.ProductionFilter, ...) bool
- func GetRequiredProviders(result *terraform.ModuleResult, providers map[provider.Provider]struct{}) map[string]struct{}
- func LoadOrGenerateRepositoryConfig(dir string, opts ...repoconfig.GenerationOption) (*repoconfig.Config, error)
- func LoadUsageData(r io.Reader, defaults *usage.Usage) (*usage.Usage, error)
- func LoadUsageDefaults(defaults *event.UsageDefaults, projectName string) *usage.Usage
- func MatchProductionFilter(matcher, value string) bool
- func ResourceMonthlyCost(r *provider.Resource) *rat.Rat
- func TotalMonthlyCostFromResources(resources []*provider.Resource) *rat.Rat
- type ProjectResult
- type ScanProjectOptions
Constants ¶
const ( RepoConfigFilename = "infracost.yml" RepoConfigTemplateFilename = "infracost.yml.tmpl" )
Variables ¶
This section is empty.
Functions ¶
func ApplyDiscount ¶
ApplyDiscount applies a discount rate to a price if the rate is greater than zero.
func ComponentMonthlyCost ¶
func ComponentMonthlyCost(c *provider.CostComponent) *rat.Rat
ComponentMonthlyCost computes the monthly cost of a single cost component, normalizing hourly prices to monthly and applying discounts.
func ConvertQuantityByPeriod ¶
ConvertQuantityByPeriod normalizes a quantity to both hourly and monthly based on the price period.
func CountUsage ¶
CountUsage splits loaded usage data into estimated (non-zero value) and unestimated (zero/empty value) counts. If usageData is nil, both returned maps are nil (signaling no usage file was loaded).
func EvaluateGuardrails ¶
func EvaluateGuardrails(guardrails []*event.Guardrail, baseProjects, headProjects []ProjectResult) []goprotoevent.GuardrailResult
EvaluateGuardrails evaluates guardrail configs against the base and head scan results, matching projects by name to compute per-project cost diffs.
func EvaluateProductionFilters ¶
func EvaluateProductionFilters(filters []*event.ProductionFilter, repositoryName, branchName, projectName string) bool
EvaluateProductionFilters checks whether a project should be marked as production based on the configured production filters.
func GetRequiredProviders ¶
func GetRequiredProviders(result *terraform.ModuleResult, providers map[provider.Provider]struct{}) map[string]struct{}
GetRequiredProviders extracts the set of cloud providers required by a Terraform module result. Returns the set of unsupported provider prefixes.
func LoadOrGenerateRepositoryConfig ¶
func LoadOrGenerateRepositoryConfig(dir string, opts ...repoconfig.GenerationOption) (*repoconfig.Config, error)
LoadOrGenerateRepositoryConfig loads an infracost.yml config from the given directory, or generates one if it doesn't exist. If an infracost.yml.tmpl template exists, it is used as the basis for generation.
func LoadUsageData ¶
LoadUsageData loads usage data from a usage config file (merging on top of the supplied defaults). The defaults are expected to come from the Infracost Cloud Platform.
func LoadUsageDefaults ¶
func LoadUsageDefaults(defaults *event.UsageDefaults, projectName string) *usage.Usage
LoadUsageDefaults converts API usage defaults into the proto usage format, filtered by project name if specified.
func MatchProductionFilter ¶
MatchProductionFilter evaluates production filter patterns with wildcard support.
func ResourceMonthlyCost ¶
ResourceMonthlyCost computes the monthly cost of a single resource, including its child resources.
Types ¶
type ProjectResult ¶
type ProjectResult struct {
Name string
Config *repoconfig.Project
TotalMonthlyCost *rat.Rat
Resources []*provider.Resource
FinopsResults []*provider.FinopsPolicyResult
TagPolicyResults []goprotoevent.TaggingPolicyResult
Diagnostics []*diagnostic.Diagnostic
}
ProjectResult holds the outputs for a single project scan.
func ScanProject ¶
func ScanProject(ctx context.Context, opts *ScanProjectOptions) (*ProjectResult, error)
ScanProject scans a single project and returns its resources, costs, and policy results.
type ScanProjectOptions ¶
type ScanProjectOptions struct {
RootDir string
CacheDir string
RepoConfig *repoconfig.Config
Project *repoconfig.Project
AccessToken string // nolint:gosec // G117: passed to providers, and not exposed
BranchName string
RepositoryName string
OrgID string
PricingEndpoint string
Currency string
TraceID string
ProductionFilters []*event.ProductionFilter
FinopsPolicies []*event.FinopsPolicySettings
TagPolicies []*event.TagPolicy
UsageDefaults *event.UsageDefaults
RepoUsage *usage.Usage
PreviousResourceAddresses []string
Plugins *plugins.Config
Logging logging.Config
}
ScanProjectOptions contains all the inputs needed to scan a single project.