output

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: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UPDATED = iota
	ADDED
	REMOVED
)

Variables

View Source
var (
	GitHubMaxMessageSize = 262144 // bytes
)

Functions

func FormatCost2DP added in v0.10.14

func FormatCost2DP(currency string, d *decimal.Decimal) string

func FormatOutput added in v0.10.0

func FormatOutput(format string, r Root, opts Options) ([]byte, error)

FormatOutput returns Root r as the format specified. The default format is a table output.

func LoadAdditionalCommentData added in v0.10.30

func LoadAdditionalCommentData(path string) (string, error)

LoadAdditionalCommentData reads the file at the path into a string.

func ToDiff added in v0.8.0

func ToDiff(out Root, opts Options) ([]byte, error)

func ToHTML added in v0.7.6

func ToHTML(out Root, opts Options) ([]byte, error)

func ToJSON

func ToJSON(out Root, opts Options) ([]byte, error)

func ToSlackMessage added in v0.9.14

func ToSlackMessage(out Root, opts Options) ([]byte, error)

func ToTable

func ToTable(out Root, opts Options) ([]byte, error)

Types

type ActualCosts added in v0.10.12

type ActualCosts struct {
	ResourceID     string          `json:"resourceId"`
	StartTimestamp time.Time       `json:"startTimestamp"`
	EndTimestamp   time.Time       `json:"endTimestamp"`
	CostComponents []CostComponent `json:"costComponents,omitempty"`
}

type Breakdown added in v0.7.19

type Breakdown struct {
	Resources             []Resource       `json:"resources"`
	FreeResources         []Resource       `json:"freeResources,omitempty"`
	TotalHourlyCost       *decimal.Decimal `json:"totalHourlyCost"`
	TotalMonthlyCost      *decimal.Decimal `json:"totalMonthlyCost"`
	TotalMonthlyUsageCost *decimal.Decimal `json:"totalMonthlyUsageCost"`
}

func (*Breakdown) HasResources added in v0.10.32

func (b *Breakdown) HasResources() bool

HasResources returns true if the breakdown has any resources or free resources. This is used to determine if the breakdown should be shown in the output.

func (*Breakdown) TotalMonthlyBaselineCost added in v0.10.35

func (b *Breakdown) TotalMonthlyBaselineCost() *decimal.Decimal

type CostComponent added in v0.7.4

type CostComponent struct {
	Name            string           `json:"name"`
	Unit            string           `json:"unit"`
	HourlyQuantity  *decimal.Decimal `json:"hourlyQuantity"`
	MonthlyQuantity *decimal.Decimal `json:"monthlyQuantity"`
	Price           decimal.Decimal  `json:"price"`
	HourlyCost      *decimal.Decimal `json:"hourlyCost"`
	MonthlyCost     *decimal.Decimal `json:"monthlyCost"`
	UsageBased      bool             `json:"usageBased,omitempty"`
}

type GovernanceFailures added in v0.10.30

type GovernanceFailures []string

GovernanceFailures defines a list of governance failures that were returned from infracost cloud.

func (GovernanceFailures) Error added in v0.10.30

func (g GovernanceFailures) Error() string

Error implements the Error interface returning the failures as a single message that can be used in stderr.

type MarkdownCtx added in v0.10.17

type MarkdownCtx struct {
	Root                         Root
	SkippedProjectCount          int
	ErroredProjectCount          int
	SkippedUnchangedProjectCount int
	DiffOutput                   string
	Options                      Options
	MarkdownOptions              MarkdownOptions
	RunQuotaMsg                  string
	UsageCostsMsg                string
	CostDetailsMsg               string
}

MarkdownCtx holds information that can be used and executed with a go template.

type MarkdownOptions added in v0.9.17

type MarkdownOptions struct {
	WillUpdate          bool
	WillReplace         bool
	IncludeFeedbackLink bool
	OmitDetails         bool
	BasicSyntax         bool
	MaxMessageSize      int
	Additional          string
}

type MarkdownOutput added in v0.10.25

type MarkdownOutput struct {
	Msg             []byte
	RuneLen         int
	OriginalMsgSize int
}

MarkdownOutput holds the message converted to markdown with additional information about its length.

func ToMarkdown added in v0.9.13

func ToMarkdown(out Root, opts Options, markdownOpts MarkdownOptions) (MarkdownOutput, error)

type Metadata added in v0.10.10

type Metadata struct {
	InfracostCommand string `json:"infracostCommand"`

	Branch            string    `json:"vcsBranch"`
	CommitSHA         string    `json:"vcsCommitSha"`
	CommitAuthorName  string    `json:"vcsCommitAuthorName"`
	CommitAuthorEmail string    `json:"vcsCommitAuthorEmail"`
	CommitTimestamp   time.Time `json:"vcsCommitTimestamp"`
	CommitMessage     string    `json:"vcsCommitMessage"`

	VCSRepositoryURL     string   `json:"vcsRepositoryUrl,omitempty"`
	VCSProvider          string   `json:"vcsProvider,omitempty"`
	VCSBaseBranch        string   `json:"vcsBaseBranch,omitempty"`
	VCSPullRequestTitle  string   `json:"vcsPullRequestTitle,omitempty"`
	VCSPullRequestURL    string   `json:"vcsPullRequestUrl,omitempty"`
	VCSPullRequestAuthor string   `json:"vcsPullRequestAuthor,omitempty"`
	VCSPullRequestLabels []string `json:"vcsPullRequestLabels,omitempty"`
	VCSPipelineRunID     string   `json:"vcsPipelineRunId,omitempty"`
	VCSPullRequestID     string   `json:"vcsPullRequestId,omitempty"`

	UsageApiEnabled        bool   `json:"usageApiEnabled,omitempty"`
	UsageFilePath          string `json:"usageFilePath,omitempty"`
	ConfigFilePath         string `json:"configFilePath,omitempty"`
	ConfigFileHasUsageFile bool   `json:"configFileHasUsageFile,omitempty"`
}

Metadata holds common information used to identify the system that Infracost is run within.

func NewMetadata added in v0.10.10

func NewMetadata(ctx *config.RunContext) Metadata

NewMetadata returns a Metadata struct filled with information built from the RunContext.

type Options added in v0.7.8

type Options struct {
	DashboardEndpoint string
	NoColor           bool
	ShowSkipped       bool
	ShowAllProjects   bool
	ShowOnlyChanges   bool
	Fields            []string
	IncludeHTML       bool
	PolicyOutput      PolicyOutput

	CurrencyFormat string
	// contains filtered or unexported fields
}

type PolicyCheck added in v0.9.20

type PolicyCheck struct {
	Enabled  bool
	Failures PolicyCheckFailures
	Passed   []string
}

PolicyCheck holds information if a given run has any policy checks enabled. This struct is used in templates to create useful cost policy outputs.

func (PolicyCheck) HasFailed added in v0.9.20

func (p PolicyCheck) HasFailed() bool

HasFailed returns if the PolicyCheck has any cost policy failures

type PolicyCheckFailures added in v0.9.20

type PolicyCheckFailures []string

PolicyCheckFailures defines a list of policy check failures that can be collected from a policy evaluation.

func (PolicyCheckFailures) Error added in v0.9.20

func (p PolicyCheckFailures) Error() string

Error implements the Error interface returning the failures as a single message that can be used in stderr.

type PolicyCheckOutput added in v0.10.25

type PolicyCheckOutput struct {
	Name            string
	Failure         bool
	Warning         bool
	Message         string
	Details         []string
	ResourceDetails []PolicyCheckResourceDetails
	TruncatedCount  int
}

type PolicyCheckResourceDetails added in v0.10.25

type PolicyCheckResourceDetails struct {
	Address      string
	ResourceType string
	Path         string
	Line         int
	Violations   []PolicyCheckViolations
}

type PolicyCheckViolations added in v0.10.25

type PolicyCheckViolations struct {
	Details      []string
	ProjectNames []string
}

type PolicyOutput added in v0.10.25

type PolicyOutput struct {
	HasFailures bool
	HasWarnings bool
	Checks      []PolicyCheckOutput
}

PolicyOutput holds normalized PolicyCheck and TagPolicyCheck data so it can be output in a uniform "Policies" section of the infracost comment.

func NewPolicyOutput added in v0.10.25

func NewPolicyOutput(pc PolicyCheck) PolicyOutput

NewPolicyOutput normalizes a PolicyCheck suitable for use in the output markdown template.

type Project added in v0.7.19

type Project struct {
	Name          string                  `json:"name"`
	Metadata      *schema.ProjectMetadata `json:"metadata"`
	PastBreakdown *Breakdown              `json:"pastBreakdown"`
	Breakdown     *Breakdown              `json:"breakdown"`
	Diff          *Breakdown              `json:"diff"`
	Summary       *Summary                `json:"summary"`
	// contains filtered or unexported fields
}

func (*Project) Label added in v0.8.0

func (p *Project) Label() string

Label returns the display name of the project

func (*Project) LabelWithMetadata added in v0.10.4

func (p *Project) LabelWithMetadata() string

LabelWithMetadata returns the display name of the project appended with any distinguishing metadata (Module path or Workspace)

func (Project) ToSchemaProject added in v0.9.23

func (p Project) ToSchemaProject() *schema.Project

ToSchemaProject generates a schema.Project from a Project. The created schema.Project is not suitable to be used outside simple schema.Project to schema.Project comparisons. It contains missing information that cannot be inferred from a Project.

type Projects added in v0.9.23

type Projects []Project

func (Projects) IsRunQuotaExceeded added in v0.10.31

func (projects Projects) IsRunQuotaExceeded() (string, bool)

IsRunQuotaExceeded checks if any of the project metadata have errored with a "run quota exceeded" error. If found it returns the associated message with this diag. This should be used when in any output that notifies the user.

type ReportInput added in v0.7.8

type ReportInput struct {
	Metadata map[string]string
	Root     Root
}

func LoadPaths added in v0.9.17

func LoadPaths(paths []string) ([]ReportInput, error)

type Resource added in v0.7.4

type Resource struct {
	Name             string                 `json:"name"`
	ResourceType     string                 `json:"resourceType,omitempty"`
	Tags             *map[string]string     `json:"tags,omitempty"`
	Metadata         map[string]interface{} `json:"metadata"`
	HourlyCost       *decimal.Decimal       `json:"hourlyCost,omitempty"`
	MonthlyCost      *decimal.Decimal       `json:"monthlyCost,omitempty"`
	MonthlyUsageCost *decimal.Decimal       `json:"monthlyUsageCost,omitempty"`
	CostComponents   []CostComponent        `json:"costComponents,omitempty"`
	ActualCosts      []ActualCosts          `json:"actualCosts,omitempty"`
	SubResources     []Resource             `json:"subresources,omitempty"`
}

type Root added in v0.7.4

type Root struct {
	Version                   string           `json:"version"`
	Metadata                  Metadata         `json:"metadata"`
	RunID                     string           `json:"runId,omitempty"`
	ShareURL                  string           `json:"shareUrl,omitempty"`
	CloudURL                  string           `json:"cloudUrl,omitempty"`
	Currency                  string           `json:"currency"`
	Projects                  Projects         `json:"projects"`
	TotalHourlyCost           *decimal.Decimal `json:"totalHourlyCost"`
	TotalMonthlyCost          *decimal.Decimal `json:"totalMonthlyCost"`
	TotalMonthlyUsageCost     *decimal.Decimal `json:"totalMonthlyUsageCost,omitempty"`
	PastTotalHourlyCost       *decimal.Decimal `json:"pastTotalHourlyCost"`
	PastTotalMonthlyCost      *decimal.Decimal `json:"pastTotalMonthlyCost"`
	PastTotalMonthlyUsageCost *decimal.Decimal `json:"pastTotalMonthlyUsageCost,omitempty"`
	DiffTotalHourlyCost       *decimal.Decimal `json:"diffTotalHourlyCost"`
	DiffTotalMonthlyCost      *decimal.Decimal `json:"diffTotalMonthlyCost"`
	DiffTotalMonthlyUsageCost *decimal.Decimal `json:"diffTotalMonthlyUsageCost,omitempty"`
	TimeGenerated             time.Time        `json:"timeGenerated"`
	Summary                   *Summary         `json:"summary"`
	FullSummary               *Summary         `json:"-"`
	IsCIRun                   bool             `json:"-"`
}

func Combine added in v0.7.4

func Combine(inputs []ReportInput) (Root, error)

func CompareTo added in v0.9.23

func CompareTo(c *config.Config, current, prior Root) (Root, error)

CompareTo generates an output Root using another Root as the base snapshot. Each project in current Root will have all past resources overwritten with the matching projects in the prior Root. If we can't find a matching project then we assume that the project has been newly created and will show a 100% increase in the output Root.

func Load added in v0.7.4

func Load(p string) (Root, error)

Load reads the file at the location p and the file body into a Root struct. Load naively validates that the Infracost JSON body is valid by checking the that the version attribute is within a supported range.

func ToOutputFormat added in v0.7.4

func ToOutputFormat(c *config.Config, projects []*schema.Project) (Root, error)

func (*Root) ExampleProjectName added in v0.9.21

func (r *Root) ExampleProjectName() string

func (*Root) HasDiff added in v0.10.16

func (r *Root) HasDiff() bool

HasDiff returns true if any project has a difference in monthly cost or resources

func (*Root) HasUnsupportedResources added in v0.10.32

func (r *Root) HasUnsupportedResources() bool

HasUnsupportedResources returns if the summary has any unsupported resources. This is used to determine if the summary should be shown in different output formats.

type Summary added in v0.8.0

type Summary struct {
	TotalResources            *int `json:"totalResources,omitempty"`
	TotalDetectedResources    *int `json:"totalDetectedResources,omitempty"`
	TotalSupportedResources   *int `json:"totalSupportedResources,omitempty"`
	TotalUnsupportedResources *int `json:"totalUnsupportedResources,omitempty"`
	TotalUsageBasedResources  *int `json:"totalUsageBasedResources,omitempty"`
	TotalNoPriceResources     *int `json:"totalNoPriceResources,omitempty"`

	SupportedResourceCounts   *map[string]int `json:"supportedResourceCounts,omitempty"`
	UnsupportedResourceCounts *map[string]int `json:"unsupportedResourceCounts,omitempty"`
	NoPriceResourceCounts     *map[string]int `json:"noPriceResourceCounts,omitempty"`

	EstimatedUsageCounts   *map[string]int `json:"-"`
	UnestimatedUsageCounts *map[string]int `json:"-"`
	TotalEstimatedUsages   *int            `json:"-"`
	TotalUnestimatedUsages *int            `json:"-"`
}

func BuildSummary added in v0.8.0

func BuildSummary(resources []*schema.Resource, opts SummaryOptions) (*Summary, error)

func MergeSummaries added in v0.9.3

func MergeSummaries(summaries []*Summary) *Summary

type SummaryOptions added in v0.8.0

type SummaryOptions struct {
	IncludeUnsupportedProviders bool
	OnlyFields                  []string
}

Jump to

Keyboard shortcuts

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