tflint

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2019 License: MPL-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EvaluationError is an error when interpolation failed (unexpected)
	EvaluationError int = 0
	// UnknownValueError is an error when an unknown value is referenced
	UnknownValueError int = 1 + iota
	// NullValueError is an error when null value is referenced
	NullValueError
	// TypeConversionError is an error when type conversion of cty.Value failed
	TypeConversionError
	// TypeMismatchError is an error when a type of cty.Value is not as expected
	TypeMismatchError
	// UnevaluableError is an error when a received expression has unevaluable references.
	UnevaluableError
	// UnexpectedAttributeError is an error when handle unexpected attributes (e.g. block)
	UnexpectedAttributeError
	// ExternalAPIError is an error when calling the external API (e.g. AWS SDK)
	ExternalAPIError

	// FatalLevel is a recorverable error, it cause panic
	FatalLevel int = 0
	// ErrorLevel is a user-level error, it display and feedback error information
	ErrorLevel int = 1 + iota
	// WarningLevel is a user-level warning. Although it is an error, it has no effect on execution.
	WarningLevel
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractLoader

type AbstractLoader interface {
	LoadConfig() (*configs.Config, error)
	LoadValuesFiles(...string) ([]terraform.InputValues, error)
	IsConfigFile(string) bool
}

AbstractLoader is a loader interface for mock

type Config

type Config struct {
	DeepCheck        bool
	AwsCredentials   client.AwsCredentials
	IgnoreModule     map[string]bool
	IgnoreRule       map[string]bool
	Varfile          []string
	TerraformVersion string
	Rules            map[string]*RuleConfig
}

Config describes the behavior of TFLint

func EmptyConfig

func EmptyConfig() *Config

EmptyConfig returns default config It is mainly used for testing

func LoadConfig

func LoadConfig(file string) (*Config, error)

LoadConfig loads TFLint config from file If failed to load the default config file, it tries to load config file under the home directory Therefore, if there is no default config file, it will not return an error

func (*Config) Merge

func (c *Config) Merge(other *Config) *Config

Merge returns a merged copy of the two configs Since the argument takes precedence, it can be used as overwriting of the config

type Error

type Error struct {
	Code    int
	Level   int
	Message string
	Cause   error
}

Error is application error object. It has own error code for processing according to a type of error.

func (*Error) Error

func (e *Error) Error() string

Error shows error message. This must be implemented for error interface.

type Loader

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

Loader is a wrapper of Terraform's configload.Loader

func NewLoader

func NewLoader() (*Loader, error)

NewLoader returns a loader with module manifests

func (*Loader) IsConfigFile

func (l *Loader) IsConfigFile(file string) bool

IsConfigFile checks whether the configuration files includes the file

func (*Loader) LoadConfig

func (l *Loader) LoadConfig() (*configs.Config, error)

LoadConfig loads Terraform's configurations TODO: Can we use configload.LoadConfig instead?

func (*Loader) LoadValuesFiles

func (l *Loader) LoadValuesFiles(files ...string) ([]terraform.InputValues, error)

LoadValuesFiles reads Terraform's values files and returns terraform.InputValues list in order of priority Pass values ​​files specified from the CLI as the arguments in order of priority This is the responsibility of the caller

type Rule

type Rule interface {
	Name() string
	Type() string
	Link() string
}

Rule is interface for building the issue

type RuleConfig

type RuleConfig struct {
	Name    string `hcl:"name,label"`
	Enabled bool   `hcl:"enabled"`
}

RuleConfig is a TFLint's rule config

type Runner

type Runner struct {
	TFConfig  *configs.Config
	Issues    issue.Issues
	AwsClient *client.AwsClient
	// contains filtered or unexported fields
}

Runner checks templates according rules. For variables interplation, it has Terraform eval context. After checking, it accumulates results as issues.

func NewModuleRunners

func NewModuleRunners(parent *Runner) ([]*Runner, error)

NewModuleRunners returns new TFLint runners for child modules Recursively search modules and generate Runners In order to propagate attributes of moduleCall as variables to the module, evaluate the variables. If it cannot be evaluated, treat it as unknown

func NewRunner

func NewRunner(c *Config, cfg *configs.Config, variables ...terraform.InputValues) *Runner

NewRunner returns new TFLint runner It prepares built-in context (workpace metadata, variables) from received `configs.Config` and `terraform.InputValues`

func (*Runner) EachStringSliceExprs

func (r *Runner) EachStringSliceExprs(expr hcl.Expression, proc func(val string, expr hcl.Expression)) error

EachStringSliceExprs iterates an evaluated value and the corresponding expression If the given expression is a static list, get an expression for each value If not, the given expression is used as it is

func (*Runner) EmitIssue

func (r *Runner) EmitIssue(rule Rule, message string, location hcl.Range)

EmitIssue builds an issue and accumulates it

func (*Runner) EnsureNoError

func (r *Runner) EnsureNoError(err error, proc func() error) error

EnsureNoError is a helper for processing when no error occurs This function skips processing without returning an error to the caller when the error is warning

func (*Runner) EvaluateExpr

func (r *Runner) EvaluateExpr(expr hcl.Expression, ret interface{}) error

EvaluateExpr is a wrapper of terraform.BultinEvalContext.EvaluateExpr and gocty.FromCtyValue When it received slice as `ret`, it converts cty.Value to expected list type because raw cty.Value has TupleType.

func (*Runner) IsNullExpr

func (r *Runner) IsNullExpr(expr hcl.Expression) bool

IsNullExpr check the passed expression is null

func (*Runner) LookupIssues

func (r *Runner) LookupIssues(files ...string) issue.Issues

LookupIssues returns issues according to the received files

func (*Runner) LookupResourcesByType

func (r *Runner) LookupResourcesByType(resourceType string) []*configs.Resource

LookupResourcesByType returns `configs.Resource` list according to the resource type

func (*Runner) TFConfigPath

func (r *Runner) TFConfigPath() string

TFConfigPath is a wrapper of addrs.Module

func (*Runner) WalkResourceAttributes

func (r *Runner) WalkResourceAttributes(resource, attributeName string, walker func(*hcl.Attribute) error) error

WalkResourceAttributes searches for resources and passes the appropriate attributes to the walker function

func (*Runner) WalkResourceBlocks

func (r *Runner) WalkResourceBlocks(resource, blockType string, walker func(*hcl.Block) error) error

WalkResourceBlocks walks all blocks of the passed resource and invokes the passed function

Jump to

Keyboard shortcuts

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