plugin

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package plugin provides plugin discovery and runner implementation for tfbreak. Types and interfaces are imported from github.com/jokarl/tfbreak-plugin-sdk.

Package plugin provides plugin discovery, loading, and execution for tfbreak.

This file provides utilities for loading raw HCL files from Terraform directories, which are then passed to plugins via the Runner interface.

Package plugin provides plugin discovery, loading, and execution for tfbreak.

This file implements the plugin loader, which uses hashicorp/go-plugin to load and communicate with external plugin binaries over gRPC.

Package plugin provides plugin discovery, loading, and execution for tfbreak.

This file implements the plugin manager, which coordinates plugin lifecycle (discovery, loading, execution, cleanup) and aggregates results from plugins.

Index

Constants

View Source
const (
	// PluginPrefix is the naming convention for tfbreak plugins.
	PluginPrefix = "tfbreak-ruleset-"

	// PluginDirEnv is the environment variable for plugin directory.
	PluginDirEnv = "TFBREAK_PLUGIN_DIR"

	// LocalPluginDir is the local plugin directory relative to cwd.
	LocalPluginDir = ".tfbreak.d/plugins"

	// HomePluginDir is the home directory plugin path.
	HomePluginDir = ".tfbreak.d/plugins"
)

Variables

This section is empty.

Functions

func CloseAll added in v0.3.0

func CloseAll(plugins []*LoadedPlugin)

CloseAll closes all loaded plugins.

func GetDefaultPluginDir added in v0.4.0

func GetDefaultPluginDir() string

GetDefaultPluginDir returns the default plugin directory (~/.tfbreak.d/plugins).

func GetMissingPlugins added in v0.4.0

func GetMissingPlugins(cfg *config.Config) []*config.PluginConfig

GetMissingPlugins returns plugins that are configured with a source but not found locally. This is used to determine if the user needs to run `tfbreak init`.

func LoadHCLFiles added in v0.3.0

func LoadHCLFiles(dir string) (map[string]*hcl.File, error)

LoadHCLFiles loads all .tf files from the given directory and returns them as a map from filename to parsed HCL file.

func LoadHCLFilesWithFilter added in v0.3.0

func LoadHCLFilesWithFilter(dir string, filter func(filename string) bool) (map[string]*hcl.File, error)

LoadHCLFilesWithFilter loads HCL files from the given directory, optionally applying a filter function to determine which files to include.

Types

type Downloader added in v0.4.0

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

Downloader handles downloading plugins from GitHub releases.

func NewDownloader added in v0.4.0

func NewDownloader(pluginDir string) *Downloader

NewDownloader creates a new plugin downloader. If pluginDir is empty, the default plugin directory is used.

func (*Downloader) Download added in v0.4.0

func (d *Downloader) Download(source, version string) error

Download downloads a plugin from the given source. source format: "github.com/{owner}/{repo}" (e.g., "github.com/jokarl/tfbreak-ruleset-azurerm") version: semantic version (e.g., "0.2.0") or "latest"

type Issue

type Issue struct {
	// Rule is the rule that emitted the issue.
	Rule tflint.Rule
	// Message is the issue message.
	Message string
	// Range is the source location of the issue.
	Range hcl.Range
}

Issue represents a finding emitted by a plugin rule.

type Issues

type Issues []Issue

Issues is a slice of Issue for convenience.

type LoadedPlugin added in v0.3.0

type LoadedPlugin struct {
	// Info contains metadata about the discovered plugin.
	Info PluginInfo
	// RuleSet is the plugin's RuleSet implementation.
	RuleSet tflint.RuleSet
	// Client is the go-plugin client for managing the plugin process.
	Client *goplugin.Client
}

LoadedPlugin represents a plugin that has been loaded and is ready for use.

func (*LoadedPlugin) Close added in v0.3.0

func (p *LoadedPlugin) Close()

Close terminates the plugin process.

type Loader added in v0.3.0

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

Loader loads and manages plugin binaries.

func NewLoader added in v0.3.0

func NewLoader() *Loader

NewLoader creates a new plugin loader.

func NewLoaderWithLogger added in v0.3.0

func NewLoaderWithLogger(logger hclog.Logger) *Loader

NewLoaderWithLogger creates a new plugin loader with a custom logger.

func (*Loader) Load added in v0.3.0

func (l *Loader) Load(info PluginInfo) (*LoadedPlugin, error)

Load loads a single plugin from the given path. The plugin process is started and a gRPC connection is established.

func (*Loader) LoadAll added in v0.3.0

func (l *Loader) LoadAll(plugins []PluginInfo) ([]*LoadedPlugin, []error)

LoadAll loads all plugins from the given list of plugin info. Returns a slice of loaded plugins and any errors encountered. Plugins that fail to load are skipped but errors are accumulated.

type Manager added in v0.3.0

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

Manager manages plugin lifecycle and execution.

func NewManager added in v0.3.0

func NewManager(cfg *config.Config) *Manager

NewManager creates a new plugin manager.

func (*Manager) Close added in v0.3.0

func (m *Manager) Close()

Close terminates all loaded plugins.

func (*Manager) DiscoverAndLoad added in v0.3.0

func (m *Manager) DiscoverAndLoad() (int, []error)

DiscoverAndLoad discovers plugins and loads enabled ones. Returns the number of plugins loaded and any errors encountered.

func (*Manager) DiscoverAndLoadWithAutoDownload added in v0.4.0

func (m *Manager) DiscoverAndLoadWithAutoDownload(autoDownload bool) (int, []error)

DiscoverAndLoadWithAutoDownload discovers plugins, optionally auto-downloads missing ones, and loads enabled plugins. Returns the number of plugins loaded and any errors encountered.

func (*Manager) ExecuteRules added in v0.3.0

func (m *Manager) ExecuteRules(oldFiles, newFiles map[string]*hcl.File) ([]*types.Finding, []error)

ExecuteRules executes all loaded plugin rules against the provided configurations. Returns a slice of findings from all plugins.

func (*Manager) GetLoadedPlugins added in v0.3.0

func (m *Manager) GetLoadedPlugins() []PluginSummary

GetLoadedPlugins returns information about loaded plugins.

func (*Manager) HasPlugins added in v0.3.0

func (m *Manager) HasPlugins() bool

HasPlugins returns true if any plugins are loaded.

func (*Manager) PluginCount added in v0.3.0

func (m *Manager) PluginCount() int

PluginCount returns the number of loaded plugins.

type PluginInfo

type PluginInfo struct {
	// Name is the plugin name without prefix (e.g., "azurerm").
	Name string
	// Path is the full path to the plugin binary.
	Path string
	// Enabled indicates whether the plugin is enabled in config.
	Enabled bool
}

PluginInfo contains metadata about a discovered plugin.

func Discover

func Discover(cfg *config.Config) ([]PluginInfo, error)

Discover finds plugins from configured paths. Priority: config.PluginDir > TFBREAK_PLUGIN_DIR > ./.tfbreak.d/plugins > ~/.tfbreak.d/plugins

func DiscoverWithAutoDownload added in v0.4.0

func DiscoverWithAutoDownload(cfg *config.Config, autoDownload bool) ([]PluginInfo, []error)

DiscoverWithAutoDownload discovers plugins and optionally downloads missing ones. For each plugin configured in config with a source field, it checks if the plugin is already discovered locally. If not found and autoDownload is true, it downloads the plugin from the configured source.

func GetEnabledPlugins

func GetEnabledPlugins(plugins []PluginInfo) []PluginInfo

GetEnabledPlugins returns only enabled plugins from the discovered list.

type PluginSummary added in v0.3.0

type PluginSummary struct {
	Name      string
	Version   string
	RuleCount int
	Rules     []string
}

PluginSummary contains summary information about a loaded plugin.

type RuleSetWithCheck added in v0.3.0

type RuleSetWithCheck interface {
	tflint.RuleSet
	// Check executes all enabled rules using the provided runner.
	Check(runner tflint.Runner) error
}

RuleSetWithCheck extends tflint.RuleSet with a Check method. The SDK's GRPCRuleSetClient implements this interface.

type Runner

type Runner struct {

	// Issues contains all issues emitted during rule execution.
	Issues Issues
	// contains filtered or unexported fields
}

Runner implements tflint.Runner for providing config access to plugins. This is the host-side implementation that provides old/new configurations to plugin rules during execution.

func NewRunner

func NewRunner(oldFiles, newFiles map[string]*hcl.File) *Runner

NewRunner creates a new Runner with the provided old and new HCL files.

func NewRunnerFromContent

func NewRunnerFromContent(oldContent, newContent map[string]string) (*Runner, error)

NewRunnerFromContent creates a Runner by parsing HCL content from string maps. This is useful for testing or when files are provided as strings.

func (*Runner) DecodeRuleConfig

func (r *Runner) DecodeRuleConfig(_ string, _ any) error

DecodeRuleConfig decodes rule-specific configuration. This is a stub implementation that returns nil (no config). Full implementation will be added when gRPC communication is implemented.

func (*Runner) EmitIssue

func (r *Runner) EmitIssue(rule tflint.Rule, message string, issueRange hcl.Range) error

EmitIssue records an issue from a plugin rule.

func (*Runner) GetNewModuleContent

func (r *Runner) GetNewModuleContent(schema *hclext.BodySchema, _ *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetNewModuleContent retrieves module content from new files.

func (*Runner) GetNewResourceContent

func (r *Runner) GetNewResourceContent(resourceType string, schema *hclext.BodySchema, _ *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetNewResourceContent retrieves resources of a specific type from new files.

func (*Runner) GetOldModuleContent

func (r *Runner) GetOldModuleContent(schema *hclext.BodySchema, _ *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetOldModuleContent retrieves module content from old files.

func (*Runner) GetOldResourceContent

func (r *Runner) GetOldResourceContent(resourceType string, schema *hclext.BodySchema, _ *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetOldResourceContent retrieves resources of a specific type from old files.

Jump to

Keyboard shortcuts

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