scanner

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RepoConfigFilename         = "infracost.yml"
	RepoConfigTemplateFilename = "infracost.yml.tmpl"
)

Variables

This section is empty.

Functions

func ApplyDiscount

func ApplyDiscount(price *rat.Rat, discountRate *rat.Rat) *rat.Rat

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

func ConvertQuantityByPeriod(qty *rat.Rat, period provider.Period) (hourly, monthly *rat.Rat)

ConvertQuantityByPeriod normalizes a quantity to both hourly and monthly based on the price period.

func CountUsage

func CountUsage(usageData *usage.Usage) (estimated, unestimated map[string]int)

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

func LoadUsageData(r io.Reader, defaults *usage.Usage) (*usage.Usage, error)

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

func MatchProductionFilter(matcher, value string) bool

MatchProductionFilter evaluates production filter patterns with wildcard support.

func ResourceMonthlyCost

func ResourceMonthlyCost(r *provider.Resource) *rat.Rat

ResourceMonthlyCost computes the monthly cost of a single resource, including its child resources.

func TotalMonthlyCostFromResources

func TotalMonthlyCostFromResources(resources []*provider.Resource) *rat.Rat

TotalMonthlyCostFromResources computes the total monthly cost by summing all cost components across all resources (including 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.

Jump to

Keyboard shortcuts

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