Documentation
¶
Overview ¶
Package plugin provides the compile-time plugin system for TerraCi. Plugins register themselves via init() and blank imports, following the same pattern as database/sql drivers and Caddy modules.
Index ¶
- func ByCapability[T Plugin]() []T
- func Register(p Plugin)
- func Reset()
- func RunHooks(ctx context.Context, hooks []WorkflowHook, phase HookPhase, ...) error
- type AppContext
- type ChangeDetectionProvider
- type CommandProvider
- type CommentSection
- type ConfigProvider
- type ExecutionContext
- type FilterProvider
- type Finalizable
- type GeneratorProvider
- type HookPhase
- type InitContribution
- type InitContributor
- type InitField
- type InitGroupSpec
- type InitOption
- type InitState
- type Initializable
- type PipelineContributor
- type Plugin
- type StateMap
- type SummaryContributor
- type VersionProvider
- type WorkflowHook
- type WorkflowHookProvider
- type WorkflowState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByCapability ¶
func ByCapability[T Plugin]() []T
ByCapability returns all plugins that implement the given capability interface.
func Register ¶
func Register(p Plugin)
Register adds a plugin to the global registry. Called from init() in plugin packages. Panics on duplicate names (fail-fast at startup).
func RunHooks ¶
func RunHooks(ctx context.Context, hooks []WorkflowHook, phase HookPhase, state *WorkflowState) error
RunHooks executes all hooks for the given phase.
Types ¶
type AppContext ¶
type AppContext struct {
Config *config.Config
WorkDir string
Version string
// Refresh is called before accessing Config/WorkDir to ensure
// they reflect the current state. Set by the App struct.
Refresh func()
}
AppContext is the public API available to plugins. Config and WorkDir are resolved lazily via the accessor function so they reflect the state after PersistentPreRunE completes.
func (*AppContext) Ensure ¶
func (a *AppContext) Ensure()
Ensure refreshes the context from the App state. Safe to call multiple times; no-op if Refresh is nil.
type ChangeDetectionProvider ¶
type ChangeDetectionProvider interface {
Plugin
DetectChangedModules(ctx context.Context, appCtx *AppContext, baseRef string, moduleIndex *discovery.ModuleIndex) (changed []*discovery.Module, changedFiles []string, err error)
DetectChangedLibraries(ctx context.Context, appCtx *AppContext, baseRef string, libraryPaths []string) ([]string, error)
}
ChangeDetectionProvider detects changed modules from git (or other VCS).
type CommandProvider ¶
type CommandProvider interface {
Plugin
Commands(ctx *AppContext) []*cobra.Command
}
CommandProvider adds CLI subcommands to TerraCi.
type CommentSection ¶
type CommentSection struct {
Order int // Lower = rendered first
Title string // Section heading
Content string // Markdown content
}
CommentSection is an additional section contributed by a plugin to the PR/MR comment.
type ConfigProvider ¶
type ConfigProvider interface {
Plugin
ConfigKey() string
NewConfig() any
SetConfig(cfg any) error
IsConfigured() bool // true if SetConfig was called with explicit config
}
ConfigProvider declares a config section under "plugins:" in .terraci.yaml.
type ExecutionContext ¶
type ExecutionContext struct {
// PlanResults is the collected plan result data, available for enrichment.
PlanResults *ci.PlanResultCollection
// Sections holds additional markdown sections contributed by plugins.
Sections []CommentSection
// Data holds arbitrary typed data for inter-plugin communication.
Data map[string]any
// contains filtered or unexported fields
}
ExecutionContext holds shared mutable state during command execution. Plugins read and write to this during the summary phase.
func NewExecutionContext ¶
func NewExecutionContext(plans *ci.PlanResultCollection) *ExecutionContext
NewExecutionContext creates an ExecutionContext from plan results.
func (*ExecutionContext) AddSection ¶
func (e *ExecutionContext) AddSection(section CommentSection)
AddSection adds a comment section from a plugin.
func (*ExecutionContext) GetData ¶
func (e *ExecutionContext) GetData(key string) (any, bool)
GetData retrieves a value set by another plugin.
func (*ExecutionContext) SetData ¶
func (e *ExecutionContext) SetData(key string, value any)
SetData stores a value for inter-plugin communication.
type FilterProvider ¶
type FilterProvider interface {
Plugin
Filters(ctx *AppContext) []filter.ModuleFilter
}
FilterProvider registers custom module filters.
type Finalizable ¶
Finalizable plugins clean up resources after the command completes.
type GeneratorProvider ¶
type GeneratorProvider interface {
Plugin
ProviderName() string
DetectEnv() bool
NewGenerator(ctx *AppContext, depGraph *graph.DependencyGraph, modules []*discovery.Module) pipeline.Generator
NewCommentService(ctx *AppContext) ci.CommentService
}
GeneratorProvider supplies a pipeline generator and comment service for a CI provider.
func ResolveProvider ¶
func ResolveProvider() (GeneratorProvider, error)
ResolveProvider detects the active CI provider from registered GeneratorProviders. Priority: env detection → TERRACI_PROVIDER env → single registered → default gitlab fallback.
type HookPhase ¶
type HookPhase int
HookPhase identifies where in the workflow a hook runs.
const ( // PhasePreScan runs before module discovery. PhasePreScan HookPhase = iota // PhasePostScan runs after module discovery, before filtering. PhasePostScan // PhasePostFilter runs after filtering, before HCL parsing. PhasePostFilter // PhasePostParse runs after HCL parsing, before graph building. PhasePostParse // PhasePostGraph runs after the dependency graph is built. PhasePostGraph )
type InitContribution ¶
InitContribution holds the config produced by a plugin's init logic.
type InitContributor ¶
type InitContributor interface {
Plugin
InitGroup() *InitGroupSpec
BuildInitConfig(state InitState) *InitContribution
}
InitContributor plugins contribute fields and config to the init wizard.
type InitField ¶
type InitField struct {
Key string
Title string
Description string
Type string // "string", "bool", "select"
Default any
Options []InitOption
Placeholder string
}
InitField describes a single form field in the init wizard.
type InitGroupSpec ¶
type InitGroupSpec struct {
Title string
Order int
Fields []InitField
ShowWhen func(InitState) bool
}
InitGroupSpec describes a group of form fields contributed by a plugin.
type InitOption ¶
InitOption represents a selectable option for a field.
type InitState ¶
type InitState interface {
Get(key string) any
Set(key string, val any)
Provider() string
Binary() string
}
InitState provides read/write access to the shared init wizard state.
type Initializable ¶
type Initializable interface {
Plugin
Initialize(ctx context.Context, appCtx *AppContext) error
}
Initializable plugins set up resources after config is loaded, before any command runs.
type PipelineContributor ¶
type PipelineContributor interface {
Plugin
PipelineContribution() *pipeline.Contribution
}
PipelineContributor plugins add steps or jobs to the generated CI pipeline.
type Plugin ¶
type Plugin interface {
// Name returns a unique identifier (e.g., "gitlab", "cost", "slack").
Name() string
// Description returns a human-readable description.
Description() string
}
Plugin is the core interface every plugin must implement.
type StateMap ¶
type StateMap struct {
// contains filtered or unexported fields
}
StateMap is the default InitState implementation backed by maps. It provides stable pointers for huh form field binding.
func (*StateMap) BoolPtr ¶
BoolPtr returns a stable *bool pointer for huh form binding. If a value was previously Set for the key, it initializes the pointer with that value.
func (*StateMap) Get ¶
Get retrieves a value, preferring pointer-backed values from StringPtr/BoolPtr.
type SummaryContributor ¶
type SummaryContributor interface {
Plugin
ContributeToSummary(ctx context.Context, appCtx *AppContext, execCtx *ExecutionContext) error
}
SummaryContributor plugins enrich plan results during `terraci summary`. Called in registration order before comment rendering.
type VersionProvider ¶
VersionProvider plugins contribute version info to `terraci version`.
type WorkflowHook ¶
type WorkflowHook struct {
Phase HookPhase
Priority int // Lower = runs first. Default 100.
Fn func(ctx context.Context, state *WorkflowState) error
}
WorkflowHook injects behavior at a specific workflow phase.
func CollectHooks ¶
func CollectHooks() []WorkflowHook
CollectHooks gathers all workflow hooks from registered plugins, sorted by priority.
type WorkflowHookProvider ¶
type WorkflowHookProvider interface {
Plugin
WorkflowHooks() []WorkflowHook
}
WorkflowHookProvider injects behavior at workflow stages.
type WorkflowState ¶
type WorkflowState struct {
// AllModules is populated after scan.
AllModules []*discovery.Module
// Filtered is populated after filter.
Filtered []*discovery.Module
// Dependencies is populated after parse.
Dependencies map[string]*parser.ModuleDependencies
// Graph is populated after graph build.
Graph *graph.DependencyGraph
// Warnings collects non-fatal issues.
Warnings []error
}
WorkflowState provides mutable access to intermediate workflow results. Fields are populated progressively as the workflow advances through phases.