config

package
v0.10.17 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const InfracostDir = ".infracost"

Variables

View Source
var ErrorInvalidConfigFile = errors.New("parsing config file failed check file syntax")

Functions

func ConfigurationFilePath added in v0.9.6

func ConfigurationFilePath() string

func CredentialsFilePath added in v0.7.17

func CredentialsFilePath() string

func DetectProjectMetadata added in v0.9.0

func DetectProjectMetadata(path string) *schema.ProjectMetadata

func FileExists added in v0.9.7

func FileExists(path string) bool

func IsDev

func IsDev() bool

func IsEnvPresent added in v0.9.5

func IsEnvPresent(s string) bool

func IsTest

func IsTest() bool

func RootDir

func RootDir() string

Types

type Config

type Config struct {
	Credentials   Credentials
	Configuration Configuration

	Version         string `yaml:"version,omitempty" ignored:"true"`
	LogLevel        string `yaml:"log_level,omitempty" envconfig:"LOG_LEVEL"`
	DebugReport     bool   `ignored:"true"`
	NoColor         bool   `yaml:"no_color,omitempty" envconfig:"NO_COLOR"`
	SkipUpdateCheck bool   `yaml:"skip_update_check,omitempty" envconfig:"SKIP_UPDATE_CHECK"`
	Parallelism     *int   `envconfig:"PARALLELISM"`

	APIKey                    string `envconfig:"API_KEY"`
	PricingAPIEndpoint        string `yaml:"pricing_api_endpoint,omitempty" envconfig:"PRICING_API_ENDPOINT"`
	DefaultPricingAPIEndpoint string `yaml:"default_pricing_api_endpoint,omitempty" envconfig:"DEFAULT_PRICING_API_ENDPOINT"`
	DashboardAPIEndpoint      string `yaml:"dashboard_api_endpoint,omitempty" envconfig:"DASHBOARD_API_ENDPOINT"`
	DashboardEndpoint         string `yaml:"dashboard_endpoint,omitempty" envconfig:"DASHBOARD_ENDPOINT"`
	UsageAPIEndpoint          string `yaml:"usage_api_endpoint,omitempty" envconfig:"USAGE_API_ENDPOINT"`
	UsageActualCosts          bool   `yaml:"usage_actual_costs,omitempty" envconfig:"USAGE_ACTUAL_COSTS"`
	PolicyAPIEndpoint         string `yaml:"policy_api_endpoint" envconfig:"POLICY_API_ENDPOINT"`
	EnableDashboard           bool   `yaml:"enable_dashboard,omitempty" envconfig:"ENABLE_DASHBOARD"`
	EnableCloud               *bool  `yaml:"enable_cloud,omitempty" envconfig:"ENABLE_CLOUD"`
	EnableCloudUpload         *bool  `yaml:"enable_cloud,omitempty" envconfig:"ENABLE_CLOUD_UPLOAD"`
	DisableHCLParsing         bool   `yaml:"disable_hcl_parsing,omitempty" envconfig:"DISABLE_HCL_PARSING"`

	TLSInsecureSkipVerify *bool  `envconfig:"TLS_INSECURE_SKIP_VERIFY"`
	TLSCACertFile         string `envconfig:"TLS_CA_CERT_FILE"`

	Currency       string `envconfig:"CURRENCY"`
	CurrencyFormat string `envconfig:"CURRENCY_FORMAT"`

	AWSOverrideRegion    string `envconfig:"AWS_OVERRIDE_REGION"`
	AzureOverrideRegion  string `envconfig:"AZURE_OVERRIDE_REGION"`
	GoogleOverrideRegion string `envconfig:"GOOGLE_OVERRIDE_REGION"`

	// Org settings
	EnableCloudForOrganization bool

	Projects        []*Project `yaml:"projects" ignored:"true"`
	Format          string     `yaml:"format,omitempty" ignored:"true"`
	ShowAllProjects bool       `yaml:"show_all_projects,omitempty" ignored:"true"`
	ShowSkipped     bool       `yaml:"show_skipped,omitempty" ignored:"true"`
	SyncUsageFile   bool       `yaml:"sync_usage_file,omitempty" ignored:"true"`
	Fields          []string   `yaml:"fields,omitempty" ignored:"true"`
	CompareTo       string
	GitDiffTarget   *string

	// Base configuration settings
	// RootPath defines the raw value of the `--path` flag provided by the user
	RootPath string
	// ConfigFilePath defines the raw value of the `--config-file` flag provided by the user
	ConfigFilePath string

	NoCache bool `yaml:"fields,omitempty" ignored:"true"`

	SkipErrLine bool

	// for testing
	EventsDisabled bool
	// contains filtered or unexported fields
}

func DefaultConfig added in v0.7.17

func DefaultConfig() *Config

func (*Config) DisableReportCaller added in v0.10.8

func (c *Config) DisableReportCaller()

DisableReportCaller sets whether the log entry writes the filename to the log line.

func (*Config) IsLogging added in v0.7.17

func (c *Config) IsLogging() bool

func (*Config) IsSelfHosted added in v0.9.3

func (c *Config) IsSelfHosted() bool

func (*Config) LoadFromConfigFile added in v0.8.0

func (c *Config) LoadFromConfigFile(path string) error

func (*Config) LoadFromEnv added in v0.7.17

func (c *Config) LoadFromEnv() error

func (*Config) LogFields added in v0.10.8

func (c *Config) LogFields() map[string]interface{}

LogFields sets the meta fields that are added to any log line entries.

func (*Config) LogFormatter added in v0.10.8

func (c *Config) LogFormatter() logrus.Formatter

LogFormatter returns the log formatting to be used by a Logger.

func (*Config) LogWriter added in v0.9.7

func (c *Config) LogWriter() io.Writer

LogWriter returns the writer the Logger should use to write logs to. In most cases this should be stderr, but it can also be a file.

func (*Config) RepoPath added in v0.10.10

func (c *Config) RepoPath() string

RepoPath returns the filepath to either the config-file location or initial path provided by the user.

func (*Config) ReportCaller added in v0.10.8

func (c *Config) ReportCaller() bool

ReportCaller returns if the log entry writes the filename to the log line.

func (*Config) SetLogDisableTimestamps added in v0.10.8

func (c *Config) SetLogDisableTimestamps(v bool)

SetLogDisableTimestamps sets if logs should contain the timestamp the line is written at.

func (*Config) SetLogWriter added in v0.10.8

func (c *Config) SetLogWriter(w io.Writer)

SetLogWriter sets the io.Writer that the logs should be piped to.

func (*Config) WriteLevel added in v0.10.8

func (c *Config) WriteLevel() string

WriteLevel is the log level that the Logger writes to LogWriter.

type Configuration added in v0.9.6

type Configuration struct {
	Version               string `yaml:"version"`
	Currency              string `yaml:"currency,omitempty"`
	EnableDashboard       *bool  `yaml:"enable_dashboard,omitempty"`
	DisableHCLParsing     *bool  `yaml:"disable_hcl_parsing,omitempty"`
	TLSInsecureSkipVerify *bool  `yaml:"tls_insecure_skip_verify,omitempty"`
	TLSCACertFile         string `yaml:"tls_ca_cert_file,omitempty"`
	EnableCloud           *bool  `yaml:"enable_cloud"`
	EnableCloudUpload     *bool  `yaml:"enable_cloud_upload"`
}

func (Configuration) Save added in v0.9.6

func (c Configuration) Save() error

type Credentials added in v0.7.17

type Credentials struct {
	Version            string `yaml:"version"`
	APIKey             string `yaml:"api_key,omitempty"`
	PricingAPIEndpoint string `yaml:"pricing_api_endpoint,omitempty"`
}

func (Credentials) Save added in v0.7.17

func (c Credentials) Save() error

type Project added in v0.8.0

type Project struct {
	// ConfigSha can be provided to identify the configuration used for the project
	ConfigSha string `yaml:"config_sha,omitempty"  ignored:"true"`
	// Path to the Terraform directory or JSON/plan file.
	// A path can be repeated with different parameters, e.g. for multiple workspaces.
	Path string `yaml:"path,omitempty" ignored:"true"`
	// ExcludePaths defines a list of directories that the provider should ignore.
	ExcludePaths []string `yaml:"exclude_paths,omitempty" ignored:"true"`
	// IncludeAllPaths tells autodetect to use all folders with valid project files.
	IncludeAllPaths bool `yaml:"include_all_paths,omitempty" ignored:"true"`
	// Name is a user defined name for the project
	Name string `yaml:"name,omitempty" ignored:"true"`
	// TerraformVarFiles is any var files that are to be used with the project.
	TerraformVarFiles []string `yaml:"terraform_var_files"`
	// TerraformVars is a slice of input vars that are to be used with the project.
	TerraformVars map[string]string `yaml:"terraform_vars"`
	// TerraformForceCLI will run a project by calling out to the terraform/terragrunt binary to generate a plan JSON file.
	TerraformForceCLI bool `yaml:"terraform_force_cli,omitempty"`
	// TerraformPlanFlags are flags to pass to terraform plan with Terraform directory paths
	TerraformPlanFlags string `yaml:"terraform_plan_flags,omitempty" ignored:"true"`
	// TerraformInitFlags are flags to pass to terraform init
	TerraformInitFlags string `yaml:"terraform_init_flags,omitempty" ignored:"true"`
	// TerraformBinary is an optional field used to change the path to the terraform or terragrunt binary
	TerraformBinary string `yaml:"terraform_binary,omitempty" envconfig:"TERRAFORM_BINARY"`
	// TerraformWorkspace is an optional field used to set the Terraform workspace
	TerraformWorkspace string `yaml:"terraform_workspace,omitempty" envconfig:"TERRAFORM_WORKSPACE"`
	// TerraformCloudHost is used to override the default app.terraform.io backend host. Only applicable for
	// terraform cloud/enterprise users.
	TerraformCloudHost string `yaml:"terraform_cloud_host,omitempty" envconfig:"TERRAFORM_CLOUD_HOST"`
	// TerraformCloudToken sets the Team API Token or User API Token so infracost can use it to access the plan.
	// Only applicable for terraform cloud/enterprise users.
	TerraformCloudToken string `yaml:"terraform_cloud_token,omitempty" envconfig:"TERRAFORM_CLOUD_TOKEN"`
	// TerragruntFlags set additional flags that should be passed to terragrunt.
	TerragruntFlags string `envconfig:"TERRAGRUNT_FLAGS"`
	// UsageFile is the full path to usage file that specifies values for usage-based resources
	UsageFile string `yaml:"usage_file,omitempty" ignored:"true"`
	// TerraformUseState sets if the users wants to use the terraform state for infracost ops.
	TerraformUseState bool              `yaml:"terraform_use_state,omitempty" ignored:"true"`
	Env               map[string]string `yaml:"env,omitempty" ignored:"true"`
}

Project defines a specific terraform project config. This can be used specify per folder/project configurations so that users don't have to provide flags every run. Fields are documented below. More info is outlined here: https://www.infracost.io/config-file

type ProjectContext added in v0.9.3

type ProjectContext struct {
	RunContext    *RunContext
	ProjectConfig *Project

	UsingCache bool
	CacheErr   string
	// contains filtered or unexported fields
}

func NewProjectContext added in v0.9.3

func NewProjectContext(runCtx *RunContext, projectCfg *Project, fields logrus.Fields) *ProjectContext

func (*ProjectContext) ContextValues added in v0.9.3

func (c *ProjectContext) ContextValues() map[string]interface{}

func (*ProjectContext) Logger added in v0.10.8

func (p *ProjectContext) Logger() *logrus.Entry

func (*ProjectContext) SetContextValue added in v0.9.3

func (c *ProjectContext) SetContextValue(key string, value interface{})

func (*ProjectContext) SetFrom added in v0.9.15

func (c *ProjectContext) SetFrom(d ProjectContexter)

type ProjectContexter added in v0.9.11

type ProjectContexter interface {
	ProjectContext() map[string]interface{}
}

type RunContext added in v0.9.3

type RunContext struct {
	Config      *Config
	State       *State
	VCSMetadata vcs.Metadata
	CMD         string

	ModuleMutex *intSync.KeyMutex
	StartTime   int64

	OutWriter io.Writer
	ErrWriter io.Writer
	Exit      func(code int)
	// contains filtered or unexported fields
}

func EmptyRunContext added in v0.9.3

func EmptyRunContext() *RunContext

func NewRunContextFromEnv added in v0.9.3

func NewRunContextFromEnv(rootCtx context.Context) (*RunContext, error)

func (*RunContext) Context added in v0.9.17

func (r *RunContext) Context() context.Context

Context returns the underlying context.

func (*RunContext) ContextValues added in v0.9.3

func (r *RunContext) ContextValues() map[string]interface{}

func (*RunContext) EventEnv added in v0.9.3

func (r *RunContext) EventEnv() map[string]interface{}

func (*RunContext) EventEnvWithProjectContexts added in v0.9.3

func (r *RunContext) EventEnvWithProjectContexts(projectContexts []*ProjectContext) map[string]interface{}

func (*RunContext) GetParallelism added in v0.10.16

func (r *RunContext) GetParallelism() (int, error)

func (*RunContext) GetResourceWarnings added in v0.9.22

func (r *RunContext) GetResourceWarnings() map[string]map[string]int

func (*RunContext) IsCIRun added in v0.9.12

func (r *RunContext) IsCIRun() bool

func (*RunContext) IsCloudEnabled added in v0.10.7

func (r *RunContext) IsCloudEnabled() bool

func (*RunContext) IsCloudUploadEnabled added in v0.10.16

func (r *RunContext) IsCloudUploadEnabled() bool

func (*RunContext) IsInfracostComment added in v0.10.7

func (r *RunContext) IsInfracostComment() bool

func (*RunContext) NewSpinner added in v0.9.22

func (r *RunContext) NewSpinner(msg string) *ui.Spinner

NewSpinner returns an ui.Spinner built from the RunContext.

func (*RunContext) SetContextValue added in v0.9.3

func (r *RunContext) SetContextValue(key string, value interface{})

func (*RunContext) SetIsInfracostComment added in v0.10.7

func (r *RunContext) SetIsInfracostComment()

SetIsInfracostComment identifies that the primary command being run is `infracost comment`

func (*RunContext) SetResourceWarnings added in v0.9.22

func (r *RunContext) SetResourceWarnings(resourceWarnings map[string]map[string]int)

func (*RunContext) UUID added in v0.9.16

func (r *RunContext) UUID() uuid.UUID

UUID returns the underlying run uuid. This can be used to globally identify the run context.

func (*RunContext) VCSRepositoryURL added in v0.10.12

func (r *RunContext) VCSRepositoryURL() string

type State added in v0.7.17

type State struct {
	InstallID              string `json:"installId"`
	LatestReleaseVersion   string `json:"latestReleaseVersion"`
	LatestReleaseCheckedAt string `json:"latestReleaseCheckedAt"`
}

func LoadState added in v0.9.3

func LoadState() (*State, error)

func (*State) Save added in v0.7.17

func (s *State) Save() error

type YamlError added in v0.9.12

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

YamlError is a custom error type that allows setting multiple error messages under a base message. It is used to decipher between internal errors and the yaml.v2 errors.

func (*YamlError) Error added in v0.9.12

func (y *YamlError) Error() string

Error implements the error interface returning the YamlError as a string. If a raw error is set it simply returns the error message from that. Otherwise, it constructs an indented error message out of the base and errors.

YamlError.Error supports multiple nesting and can construct heavily indented output if needed. e.g.

&YamlError{
	base: "top message",
	errors: []error{
		errors.New("top error 1"),
		&YamlError{
			base: "child message",
			errors: []error{
				errors.New("child error 1"),
			},
		},
	},
}

would output a string like so:

top message:
	top error 1
	child message:
		child error 1

This can be useful for ui error messages where you need to highlight issues with specific fields/entries.

Jump to

Keyboard shortcuts

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