tflint

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisableBundledPlugin = false

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

Version is application version

Functions

func ReferenceLink(name string) string

ReferenceLink returns the rule reference link

func SeverityToInt32

func SeverityToInt32(s Severity) (int32, error)

Converts a severity into an ascending int32

Types

type Annotation

type Annotation interface {
	IsAffected(*Issue) bool
	String() string
}

Annotation represents comments with special meaning in TofuLint

type Annotations

type Annotations []Annotation

Annotations is a slice of Annotation

func NewAnnotations

func NewAnnotations(path string, file *hcl.File) (Annotations, hcl.Diagnostics)

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

type Config

type Config struct {
	CallModuleType    opentofu.CallModuleType
	CallModuleTypeSet bool

	Force    bool
	ForceSet bool

	DisabledByDefault    bool
	DisabledByDefaultSet bool

	PluginDir    string
	PluginDirSet bool

	Format    string
	FormatSet bool

	Varfiles      []string
	Variables     []string
	Only          []string
	IgnoreModules map[string]bool
	Rules         map[string]*RuleConfig
	Plugins       map[string]*PluginConfig
	// contains filtered or unexported fields
}

Config describes the behavior of TofuLint

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 TofuLint config file. The priority of the configuration files is as follows:

1. file passed by the --config option 2. file set by the TFLINT_CONFIG_FILE environment variable^ 3. current directory (.tofulint.hcl) 4. current directory (.tflint.hcl) 5. home directory (~/.tofulint.hcl) 6. current directory (./.tflint.hcl) 7. home directory (~/.tflint.hcl)

For 1 and 2, if the file does not exist, an error will be returned immediately. If 3 fails, fallback to 4, and If it fails, an empty configuration is returned.

It also automatically enables bundled plugin if the "opentofu" 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

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

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

ToPluginConfig converts self into the plugin configuration format

func (*Config) ValidateRules

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

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

type FileAnnotation

type FileAnnotation struct {
	Content string
	Token   hclsyntax.Token
}

FileAnnotation is an annotation for ignoring issues in a file

func (*FileAnnotation) IsAffected

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

IsAffected checks if the passed issue is affected with the annotation

func (*FileAnnotation) String

func (a *FileAnnotation) String() string

String returns the string representation of the annotation

type Issue

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

	// Source is the source code of the file where the issue was found.
	// Usually this is the same as the originally loaded source,
	// but it may be a different if rewritten by autofixes.
	Source []byte
}

Issue represents a problem in configurations

type Issues

type Issues []*Issue

Issues is an alias for the map of Issue

func (Issues) Sort

func (issues Issues) Sort() Issues

Sort returns the sorted receiver

type LineAnnotation

type LineAnnotation struct {
	Content string
	Token   hclsyntax.Token
}

LineAnnotation is an annotation for ignoring issues in a line

func (*LineAnnotation) IsAffected

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

IsAffected checks if the passed issue is affected with the annotation

func (*LineAnnotation) String

func (a *LineAnnotation) String() string

String returns the string representation of the annotation

type PluginConfig

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
	SourceHost  string
	SourceOwner string
	SourceRepo  string
}

PluginConfig is a TofuLint's plugin config

func (*PluginConfig) Content

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 TofuLint's rule config

type RuleSet

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/SoeldnerConsult/tofulint-plugin-sdk/plugin/host2plugin.GRPCClient.

type Runner

type Runner struct {
	TFConfig *opentofu.Config
	Issues   Issues
	Ctx      *opentofu.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 TofuLint 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(originalWorkingDir string, c *Config, ants map[string]Annotations, cfg *opentofu.Config, variables ...opentofu.InputValues) (*Runner, error)

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

func TestRunner

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

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

TestRunnerWithConfig returns a runner with passed config for testing.

func (*Runner) ApplyChanges

func (r *Runner) ApplyChanges(changes map[string][]byte) hcl.Diagnostics

ApplyChanges saves the changes and applies them to the Terraform module.

func (*Runner) ClearChanges

func (r *Runner) ClearChanges()

ClearChanges clears changes

func (*Runner) ConfigSources

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

ConfigSources returns the sources of TofuLint config files

func (*Runner) EmitIssue

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

EmitIssue builds an issue and accumulates it. Returns true if the issue was not ignored by annotations.

func (*Runner) File

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

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) LookupChanges

func (r *Runner) LookupChanges(files ...string) map[string][]byte

LookupChanges returns changes according to the received files

func (*Runner) LookupIssues

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

LookupIssues returns issues according to the received files

func (*Runner) RuleConfig

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

RuleConfig returns the corresponding rule configuration

func (*Runner) Sources

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

Sources returns the sources in the module directory.

func (*Runner) WithExpressionContext

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

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

type Severity

type Severity = sdk.Severity

Severity indicates the severity of the issue

func NewSeverity

func NewSeverity(s string) (Severity, error)

Creates a new severity from a string

Jump to

Keyboard shortcuts

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