tflint

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MPL-2.0 Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const Version string = "0.41.0"

Version is application version

Variables

View Source
var DisableBundledPlugin = false

DisbaleBundledPlugin is a flag to temporarily disable the bundled plugin for integration tests.

Functions

func ReferenceLink(name string) string

ReferenceLink returns the rule reference link

Types

type Annotation added in v0.13.0

type Annotation struct {
	Content string
	Token   hclsyntax.Token
}

Annotation represents comments with special meaning in TFLint

func (*Annotation) IsAffected added in v0.13.0

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

IsAffected checks if the passed issue is affected with the annotation

func (*Annotation) String added in v0.13.0

func (a *Annotation) String() string

String returns the string representation of the annotation

type Annotations added in v0.13.0

type Annotations []Annotation

Annotations is slice of Annotation

func NewAnnotations added in v0.13.0

func NewAnnotations(tokens hclsyntax.Tokens) Annotations

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

type Config

type Config struct {
	Module            bool
	Force             bool
	IgnoreModules     map[string]bool
	Varfiles          []string
	Variables         []string
	DisabledByDefault bool
	Only              []string
	PluginDir         string
	Format            string
	Rules             map[string]*RuleConfig
	Plugins           map[string]*PluginConfig
	// contains filtered or unexported fields
}

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(fs afero.Afero, file string) (*Config, error)

LoadConfig loads TFLint config file. The priority of the configuration files is as follows:

1. current directory (./.tflint.hcl) 2. home directory (~/.tflint.hcl)

If neither file exists, an empty config is returned. You can also load any file name. However, there is no fallback to the home directory in this case.

It also automatically enables bundled plugin if the "terraform" plugin block is not explicitly declared.

func (*Config) Merge

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

Merge merges the two configs and applies to itself. Since the argument takes precedence, it can be used as overwriting of the config.

func (*Config) Sources added in v0.35.0

func (c *Config) Sources() map[string][]byte

Sources returns parsed config file sources. To support bundle plugin config, this function returns c.sources with a merge of the pseudo config file.

func (*Config) ToPluginConfig added in v0.14.0

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

ToPluginConfig converts self into the plugin configuration format

func (*Config) ValidateRules added in v0.14.0

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

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

type Issue added in v0.13.0

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

Issue represents a problem in configurations

type Issues added in v0.13.0

type Issues []*Issue

Issues is an alias for the map of Issue

func (Issues) Sort added in v0.13.0

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.16.1

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

func (*Loader) LoadAnnotations added in v0.13.0

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) (*terraform.Config, error)

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.13.0

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

type PluginConfig added in v0.13.0

type PluginConfig struct {
	Name       string `hcl:"name,label"`
	Enabled    bool   `hcl:"enabled"`
	Version    string `hcl:"version,optional"`
	Source     string `hcl:"source,optional"`
	SigningKey string `hcl:"signing_key,optional"`

	Body hcl.Body `hcl:",remain"`

	// Parsed source attributes
	SourceOwner string
	SourceRepo  string
}

PluginConfig is a TFLint's plugin config

func (*PluginConfig) Content added in v0.36.0

Content extracts a plugin config based on the passed schema.

type Rule

type Rule interface {
	Name() string
	Severity() Severity
	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.14.0

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

RuleSet is an interface to handle plugin's RuleSet. The real impl is github.com/terraform-linters/tflint-plugin-sdk/plugin/host2plugin.GRPCClient.

type Runner

type Runner struct {
	TFConfig *terraform.Config
	Issues   Issues
	Ctx      *terraform.Evaluator
	// 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 Modules that are not evaluated (`count` is 0 or `for_each` is empty) are ignored.

func NewRunner

func NewRunner(c *Config, ants map[string]Annotations, cfg *terraform.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.13.0

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.15.0

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

TestRunnerWithConfig returns a runner with passed config for testing.

func (*Runner) ConfigSources added in v0.36.0

func (r *Runner) ConfigSources() map[string][]byte

ConfigSources returns the sources of TFLint config files

func (*Runner) EmitIssue

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

EmitIssue builds an issue and accumulates it

func (*Runner) File added in v0.16.1

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.16.1

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) GetModuleContent added in v0.35.0

func (r *Runner) GetModuleContent(bodyS *hclext.BodySchema, opts sdk.GetModuleContentOption) (*hclext.BodyContent, hcl.Diagnostics)

GetModuleContent extracts body content from Terraform configurations based on the passed schema. Basically, this function is a wrapper for hclext.PartialContent, but in some ways it reproduces Terraform language semantics.

  1. The block schema implicitly adds dynamic blocks to the target https://www.terraform.io/language/expressions/dynamic-blocks
  2. Supports overriding files https://www.terraform.io/language/files/override
  3. Resources not created by count or for_each will be ignored https://www.terraform.io/language/meta-arguments/count https://www.terraform.io/language/meta-arguments/for_each

However, this behavior is controlled by options. The above is the default.

func (*Runner) LookupIssues

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

LookupIssues returns issues according to the received files

func (*Runner) RuleConfig added in v0.23.0

func (r *Runner) RuleConfig(ruleName string) *RuleConfig

RuleConfig returns the corresponding rule configuration

func (*Runner) Sources added in v0.35.0

func (r *Runner) Sources() map[string][]byte

Sources returns the sources in the module directory.

func (*Runner) WithExpressionContext added in v0.14.0

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

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

type Severity added in v0.35.0

type Severity = sdk.Severity

Severity indicates the severity of the issue

const (
	// ERROR is possible errors
	ERROR Severity = iota
	// WARNING doesn't cause problem immediately, but not good
	WARNING
	// NOTICE is not important, it's mentioned
	NOTICE
)

Jump to

Keyboard shortcuts

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