tflint

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: MPL-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package tflint is a generated GoMock package.

Index

Constants

View Source
const (
	// EvaluationError is an error when interpolation failed (unexpected)
	EvaluationError string = "E:Evaluation"
	// UnknownValueError is an error when an unknown value is referenced
	UnknownValueError string = "W:UnknownValue"
	// NullValueError is an error when null value is referenced
	NullValueError string = "W:NullValue"
	// TypeConversionError is an error when type conversion of cty.Value failed
	TypeConversionError string = "E:TypeConversion"
	// TypeMismatchError is an error when a type of cty.Value is not as expected
	TypeMismatchError string = "E:TypeMismatch"
	// UnevaluableError is an error when a received expression has unevaluable references.
	UnevaluableError string = "W:Unevaluable"
	// UnexpectedAttributeError is an error when handle unexpected attributes (e.g. block)
	UnexpectedAttributeError string = "E:UnexpectedAttribute"
	// ExternalAPIError is an error when calling the external API (e.g. AWS SDK)
	ExternalAPIError string = "E:ExternalAPI"
	// ContextError is pseudo error code for propagating runtime context.
	ContextError string = "I:Context"

	// FatalLevel is a recorverable error, it cause panic
	FatalLevel string = "Fatal"
	// ErrorLevel is a user-level error, it display and feedback error information
	ErrorLevel string = "Error"
	// WarningLevel is a user-level warning. Although it is an error, it has no effect on execution.
	WarningLevel string = "Warning"
)
View Source
const (
	// ERROR is possible errors
	ERROR = "Error"
	// WARNING doesn't cause problem immediately, but not good
	WARNING = "Warning"
	// NOTICE is not important, it's mentioned
	NOTICE = "Notice"
)
View Source
const Version string = "0.16.1"

Version is application version

Variables

This section is empty.

Functions

func AssertAppError added in v0.8.5

func AssertAppError(t *testing.T, expected Error, got error)

AssertAppError is an assertion helper for comparing tflint.Error

func AssertIssues added in v0.8.5

func AssertIssues(t *testing.T, expected Issues, actual Issues)

AssertIssues is an assertion helper for comparing issues

func AssertIssuesWithoutRange added in v0.8.5

func AssertIssuesWithoutRange(t *testing.T, expected Issues, actual Issues)

AssertIssuesWithoutRange is an assertion helper for comparing issues

func ParseTFVariables added in v0.8.5

func ParseTFVariables(vars []string, declVars map[string]*configs.Variable) (terraform.InputValues, error)

ParseTFVariables parses the passed Terraform variable CLI arguments, and returns terraform.InputValues

func ReferenceLink(name string) string

ReferenceLink returns the rule reference link

Types

type AbstractLoader

type AbstractLoader interface {
	LoadConfig(string) (*configs.Config, error)
	LoadAnnotations(string) (map[string]Annotations, error)
	LoadValuesFiles(...string) ([]terraform.InputValues, error)
	Files() (map[string]*hcl.File, error)
	Sources() map[string][]byte
}

AbstractLoader is a loader interface for mock

type Annotation added in v0.8.5

type Annotation struct {
	Content string
	Token   hclsyntax.Token
}

Annotation represents comments with special meaning in TFLint

func (*Annotation) IsAffected added in v0.8.5

func (a *Annotation) IsAffected(issue *Issue) bool

IsAffected checks if the passed issue is affected with the annotation

func (*Annotation) String added in v0.8.5

func (a *Annotation) String() string

String returns the string representation of the annotation

type Annotations added in v0.8.5

type Annotations []Annotation

Annotations is slice of Annotation

func NewAnnotations added in v0.8.5

func NewAnnotations(tokens hclsyntax.Tokens) Annotations

NewAnnotations find annotations from the passed tokens and return that list.

type Config

type Config struct {
	Module         bool
	DeepCheck      bool
	Force          bool
	AwsCredentials client.AwsCredentials
	IgnoreModules  map[string]bool
	Varfiles       []string
	Variables      []string
	Rules          map[string]*RuleConfig
	Plugins        map[string]*PluginConfig
}

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

func (*Config) ToPluginConfig added in v0.8.5

func (c *Config) ToPluginConfig() *tfplugin.Config

ToPluginConfig converts self into the plugin configuration format

func (*Config) ValidateRules added in v0.8.5

func (c *Config) ValidateRules(rulesets ...RuleSet) error

ValidateRules checks for duplicate rule names, for invalid rule names, and so on.

type Error

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

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

func NewContextError added in v0.8.5

func NewContextError(msg string, cause error) *Error

NewContextError makes a new context error

func (*Error) Error

func (e *Error) Error() string

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

type Issue added in v0.8.5

type Issue struct {
	Rule    Rule
	Message string
	Range   hcl.Range
	Callers []hcl.Range
}

Issue represents a problem in configurations

type Issues added in v0.8.5

type Issues []*Issue

Issues is an alias for the map of Issue

func (Issues) Sort added in v0.8.5

func (issues Issues) Sort() Issues

Sort returns the sorted receiver

type Loader

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

Loader is a wrapper of Terraform's configload.Loader

func NewLoader

func NewLoader(fs afero.Afero, cfg *Config) (*Loader, error)

NewLoader returns a loader with module manifests

func (*Loader) Files added in v0.8.5

func (l *Loader) Files() (map[string]*hcl.File, error)

Files returns a map of hcl.File pointers for every file that has been read by the loader. It uses the source cache to avoid re-loading the files from disk. These files can be used to do low level decoding of Terraform configuration.

func (*Loader) LoadAnnotations added in v0.8.5

func (l *Loader) LoadAnnotations(dir string) (map[string]Annotations, error)

LoadAnnotations load TFLint annotation comments as HCL tokens.

func (*Loader) LoadConfig

func (l *Loader) LoadConfig(dir string) (*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

func (*Loader) Sources added in v0.8.5

func (l *Loader) Sources() map[string][]byte

Sources returns the source code cache for the underlying parser of this loader

type MockAbstractLoader added in v0.8.5

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

MockAbstractLoader is a mock of AbstractLoader interface

func NewMockAbstractLoader added in v0.8.5

func NewMockAbstractLoader(ctrl *gomock.Controller) *MockAbstractLoader

NewMockAbstractLoader creates a new mock instance

func (*MockAbstractLoader) EXPECT added in v0.8.5

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAbstractLoader) Files added in v0.8.5

func (m *MockAbstractLoader) Files() (map[string]*hcl.File, error)

Files mocks base method

func (*MockAbstractLoader) LoadAnnotations added in v0.8.5

func (m *MockAbstractLoader) LoadAnnotations(arg0 string) (map[string]Annotations, error)

LoadAnnotations mocks base method

func (*MockAbstractLoader) LoadConfig added in v0.8.5

func (m *MockAbstractLoader) LoadConfig(arg0 string) (*configs.Config, error)

LoadConfig mocks base method

func (*MockAbstractLoader) LoadValuesFiles added in v0.8.5

func (m *MockAbstractLoader) LoadValuesFiles(arg0 ...string) ([]terraform.InputValues, error)

LoadValuesFiles mocks base method

func (*MockAbstractLoader) Sources added in v0.8.5

func (m *MockAbstractLoader) Sources() map[string][]byte

Sources mocks base method

type MockAbstractLoaderMockRecorder added in v0.8.5

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

MockAbstractLoaderMockRecorder is the mock recorder for MockAbstractLoader

func (*MockAbstractLoaderMockRecorder) Files added in v0.8.5

Files indicates an expected call of Files

func (*MockAbstractLoaderMockRecorder) LoadAnnotations added in v0.8.5

func (mr *MockAbstractLoaderMockRecorder) LoadAnnotations(arg0 interface{}) *gomock.Call

LoadAnnotations indicates an expected call of LoadAnnotations

func (*MockAbstractLoaderMockRecorder) LoadConfig added in v0.8.5

func (mr *MockAbstractLoaderMockRecorder) LoadConfig(arg0 interface{}) *gomock.Call

LoadConfig indicates an expected call of LoadConfig

func (*MockAbstractLoaderMockRecorder) LoadValuesFiles added in v0.8.5

func (mr *MockAbstractLoaderMockRecorder) LoadValuesFiles(arg0 ...interface{}) *gomock.Call

LoadValuesFiles indicates an expected call of LoadValuesFiles

func (*MockAbstractLoaderMockRecorder) Sources added in v0.8.5

Sources indicates an expected call of Sources

type PluginConfig added in v0.8.5

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

PluginConfig is a TFLint's plugin config

type ProviderConfig added in v0.8.5

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

ProviderConfig represents a provider block with an eval context (runner)

func NewProviderConfig added in v0.8.5

func NewProviderConfig(tfProvider *configs.Provider, runner *Runner, schema *hcl.BodySchema) (*ProviderConfig, error)

NewProviderConfig returns a provider config from the given `configs.Provider` and runner

func (*ProviderConfig) Get added in v0.8.5

func (p *ProviderConfig) Get(key string) (string, bool, error)

Get returns a value corresponding to the given key It should be noted that the value is evaluated if it is evaluable The second return value is a flag that determines whether a value exists We assume the provider has only simple attributes, so it just returns string

func (*ProviderConfig) GetBlock added in v0.8.5

func (p *ProviderConfig) GetBlock(key string, schema *configschema.Block) (map[string]string, bool, error)

GetBlock is Get for blocks. Obviously from the return type, nested blocks and blocks with complex types are not supported. Also note that all attributes are lost if the given block contains unevalable expressions because the entire block is evaluated.

type Rule

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

Rule is interface for building the issue

type RuleConfig

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

RuleConfig is a TFLint's rule config

type RuleSet added in v0.8.5

type RuleSet interface {
	RuleSetName() (string, error)
	RuleSetVersion() (string, error)
	RuleNames() ([]string, error)
}

RuleSet is an interface to handle plugin's RuleSet and core RuleSet both In the future, when all RuleSets are cut out into plugins, it will no longer be needed.

type Runner

type Runner struct {
	TFConfig  *configs.Config
	Issues    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, files map[string]*hcl.File, ants map[string]Annotations, cfg *configs.Config, variables ...terraform.InputValues) (*Runner, error)

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

func TestRunner added in v0.8.5

func TestRunner(t *testing.T, files map[string]string) *Runner

TestRunner returns a runner for testing. Note that this runner ignores a config, annotations, and input variables.

func TestRunnerWithConfig added in v0.8.5

func TestRunnerWithConfig(t *testing.T, files map[string]string, config *Config) *Runner

TestRunnerWithConfig returns a runner with passed config for testing.

func (*Runner) DecodeRuleConfig added in v0.8.5

func (r *Runner) DecodeRuleConfig(ruleName string, val interface{}) error

DecodeRuleConfig extracts the rule's configuration into the given value

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) EvalExpr added in v0.8.5

func (r *Runner) EvalExpr(expr hcl.Expression, ret interface{}, wantType cty.Type) (cty.Value, error)

EvalExpr is a wrapper of terraform.BultinEvalContext.EvaluateExpr In addition, this method determines whether the expression is evaluable, contains no unknown values, and so on. The returned cty.Value is converted according to the value passed as `ret`.

func (*Runner) EvaluateBlock added in v0.8.5

func (r *Runner) EvaluateBlock(block *hcl.Block, schema *configschema.Block, ret interface{}) error

EvaluateBlock is a wrapper of terraform.BultinEvalContext.EvaluateBlock and gocty.FromCtyValue

func (*Runner) EvaluateExpr

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

EvaluateExpr evaluates the expression and reflects the result in the value of `ret`. In the future, it will be no longer needed because all evaluation requests are invoked from RPC client

func (*Runner) EvaluateExprType added in v0.8.5

func (r *Runner) EvaluateExprType(expr hcl.Expression, ret interface{}, wantType cty.Type) error

EvaluateExprType is like EvaluateExpr, but also accepts a known cty.Type to pass to EvalExpr

func (*Runner) File added in v0.8.5

func (r *Runner) File(path string) *hcl.File

File returns the raw *hcl.File representation of a Terraform configuration at the specified path, or nil if there path does not match any configuration.

func (*Runner) Files added in v0.8.5

func (r *Runner) Files() map[string]*hcl.File

Files returns the raw *hcl.File representation of all Terraform configuration in the module directory.

func (*Runner) IsNullExpr

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

IsNullExpr check the passed expression is null

func (*Runner) LookupIssues

func (r *Runner) LookupIssues(files ...string) 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) WalkExpressions added in v0.8.5

func (r *Runner) WalkExpressions(walker func(hcl.Expression) error) error

WalkExpressions visits all blocks that can contain expressions: resource, data, module, provider, locals, and output. It calls the walker function with every expression it encounters and halts if the walker returns an error.

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

func (*Runner) WithExpressionContext added in v0.8.5

func (r *Runner) WithExpressionContext(expr hcl.Expression, proc func() error) error

WithExpressionContext sets the context of the passed expression currently being processed.

Jump to

Keyboard shortcuts

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