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
- func CloseAll(plugins []*LoadedPlugin)
- func GetDefaultPluginDir() string
- func GetMissingPlugins(cfg *config.Config) []*config.PluginConfig
- func LoadHCLFiles(dir string) (map[string]*hcl.File, error)
- func LoadHCLFilesWithFilter(dir string, filter func(filename string) bool) (map[string]*hcl.File, error)
- type Downloader
- type Issue
- type Issues
- type LoadedPlugin
- type Loader
- type Manager
- func (m *Manager) Close()
- func (m *Manager) DiscoverAndLoad() (int, []error)
- func (m *Manager) DiscoverAndLoadWithAutoDownload(autoDownload bool) (int, []error)
- func (m *Manager) ExecuteRules(oldFiles, newFiles map[string]*hcl.File) ([]*types.Finding, []error)
- func (m *Manager) GetLoadedPlugins() []PluginSummary
- func (m *Manager) HasPlugins() bool
- func (m *Manager) PluginCount() int
- type PluginInfo
- type PluginSummary
- type RuleSetWithCheck
- type Runner
- func (r *Runner) DecodeRuleConfig(_ string, _ any) error
- func (r *Runner) EmitIssue(rule tflint.Rule, message string, issueRange hcl.Range) error
- func (r *Runner) GetNewModuleContent(schema *hclext.BodySchema, _ *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (r *Runner) GetNewResourceContent(resourceType string, schema *hclext.BodySchema, ...) (*hclext.BodyContent, error)
- func (r *Runner) GetOldModuleContent(schema *hclext.BodySchema, _ *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (r *Runner) GetOldResourceContent(resourceType string, schema *hclext.BodySchema, ...) (*hclext.BodyContent, error)
Constants ¶
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
LoadHCLFiles loads all .tf files from the given directory and returns them as a map from filename to parsed HCL file.
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 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 NewLoaderWithLogger ¶ added in v0.3.0
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
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
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
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
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
HasPlugins returns true if any plugins are loaded.
func (*Manager) PluginCount ¶ added in v0.3.0
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
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 NewRunnerFromContent ¶
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 ¶
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) 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.