Documentation
¶
Overview ¶
Package updateengine provides the core logic for Terraform dependency version checking and updating.
Index ¶
- Constants
- func BumpConstraint(original string, newVersion Version) string
- func SatisfiesAll(v Version, constraints []Constraint) bool
- type ApplyService
- type Constraint
- type ConstraintOp
- type ModuleDependency
- type ModuleVersionUpdate
- func (u ModuleVersionUpdate) CallName() string
- func (u ModuleVersionUpdate) Constraint() string
- func (u ModuleVersionUpdate) DisplayAvailable() string
- func (u ModuleVersionUpdate) DisplayCurrent() string
- func (u ModuleVersionUpdate) DisplayLatest() string
- func (u ModuleVersionUpdate) IncludedInUpdateLogs() bool
- func (u ModuleVersionUpdate) IsApplied() bool
- func (u ModuleVersionUpdate) IsApplyPending() bool
- func (u ModuleVersionUpdate) IsUpdatable() bool
- func (u ModuleVersionUpdate) MarkApplied() ModuleVersionUpdate
- func (u ModuleVersionUpdate) MarkError(issue string) ModuleVersionUpdate
- func (u ModuleVersionUpdate) ModulePath() string
- func (u ModuleVersionUpdate) Source() string
- func (u ModuleVersionUpdate) StatusLabel() string
- type ProviderDependency
- type ProviderVersionUpdate
- func (u ProviderVersionUpdate) Constraint() string
- func (u ProviderVersionUpdate) DisplayAvailable() string
- func (u ProviderVersionUpdate) DisplayCurrent() string
- func (u ProviderVersionUpdate) DisplayLatest() string
- func (u ProviderVersionUpdate) IncludedInUpdateLogs() bool
- func (u ProviderVersionUpdate) IsApplied() bool
- func (u ProviderVersionUpdate) IsApplyPending() bool
- func (u ProviderVersionUpdate) IsUpdatable() bool
- func (u ProviderVersionUpdate) MarkApplied() ProviderVersionUpdate
- func (u ProviderVersionUpdate) MarkError(issue string) ProviderVersionUpdate
- func (u ProviderVersionUpdate) ModulePath() string
- func (u ProviderVersionUpdate) ProviderName() string
- func (u ProviderVersionUpdate) ProviderSource() string
- func (u ProviderVersionUpdate) StatusLabel() string
- type RegistryClient
- type UpdateConfig
- type UpdateResult
- type UpdateResultBuilder
- func (b *UpdateResultBuilder) AddModuleUpdate(update ModuleVersionUpdate)
- func (b *UpdateResultBuilder) AddProviderUpdate(update ProviderVersionUpdate)
- func (b *UpdateResultBuilder) Build() *UpdateResult
- func (b *UpdateResultBuilder) RecordError()
- func (b *UpdateResultBuilder) Result() *UpdateResult
- type UpdateStatus
- type UpdateSummary
- type Version
Constants ¶
const ( TargetAll = "all" TargetModules = "modules" TargetProviders = "providers" )
Target constants define what dependencies to check.
const ( BumpPatch = "patch" BumpMinor = "minor" BumpMajor = "major" )
Bump level constants.
Variables ¶
This section is empty.
Functions ¶
func BumpConstraint ¶
BumpConstraint generates a new constraint string based on the original style and new version.
func SatisfiesAll ¶
func SatisfiesAll(v Version, constraints []Constraint) bool
SatisfiesAll checks if a version satisfies all constraints.
Types ¶
type ApplyService ¶ added in v0.9.0
type ApplyService struct{}
ApplyService applies discovered dependency updates to Terraform files.
func NewApplyService ¶ added in v0.9.0
func NewApplyService() *ApplyService
NewApplyService constructs a stateless update apply service.
func (*ApplyService) Apply ¶ added in v0.9.0
func (s *ApplyService) Apply(result *UpdateResult)
Apply mutates the result items in place with apply outcomes.
type Constraint ¶
type Constraint struct {
Op ConstraintOp
Version Version
// Raw parts count to distinguish "~> 5.0" (2 parts) from "~> 5.0.1" (3 parts).
Parts int
}
Constraint represents a single version constraint like "~> 5.0".
func ParseConstraints ¶
func ParseConstraints(s string) ([]Constraint, error)
ParseConstraints parses comma-separated version constraints. Examples: "~> 5.0", ">= 1.0, < 2.0", "= 1.2.3"
func (Constraint) Satisfies ¶
func (c Constraint) Satisfies(v Version) bool
Satisfies checks if a version satisfies a single constraint.
type ConstraintOp ¶
type ConstraintOp int
ConstraintOp represents a version constraint operator.
const ( OpEqual ConstraintOp = iota // = OpNotEqual // != OpGreater // > OpGreaterEqual // >= OpLess // < OpLessEqual // <= OpPessimistic // ~> )
type ModuleDependency ¶ added in v0.9.0
type ModuleDependency struct {
ModulePath string `json:"module_path"`
CallName string `json:"call_name"`
Source string `json:"source"`
Constraint string `json:"constraint"`
}
ModuleDependency describes a discovered Terraform module dependency before any checks are run.
type ModuleVersionUpdate ¶
type ModuleVersionUpdate struct {
Dependency ModuleDependency `json:"dependency"`
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
BumpedVersion string `json:"bumped_version,omitempty"`
Status UpdateStatus `json:"status"`
Issue string `json:"issue,omitempty"`
File string `json:"file,omitempty"`
}
ModuleVersionUpdate represents the outcome of checking a Terraform module dependency.
func NewModuleVersionUpdate ¶ added in v0.9.0
func NewModuleVersionUpdate(dep ModuleDependency) ModuleVersionUpdate
NewModuleVersionUpdate creates an up-to-date module outcome from a discovered dependency.
func (ModuleVersionUpdate) CallName ¶
func (u ModuleVersionUpdate) CallName() string
CallName returns the Terraform module call name.
func (ModuleVersionUpdate) Constraint ¶
func (u ModuleVersionUpdate) Constraint() string
Constraint returns the declared version constraint.
func (ModuleVersionUpdate) DisplayAvailable ¶ added in v0.9.0
func (u ModuleVersionUpdate) DisplayAvailable() string
DisplayAvailable returns the version selected for update application.
func (ModuleVersionUpdate) DisplayCurrent ¶ added in v0.9.0
func (u ModuleVersionUpdate) DisplayCurrent() string
DisplayCurrent returns the best current-version representation for humans.
func (ModuleVersionUpdate) DisplayLatest ¶ added in v0.9.0
func (u ModuleVersionUpdate) DisplayLatest() string
DisplayLatest returns the latest version only when it adds signal beyond the chosen bump.
func (ModuleVersionUpdate) IncludedInUpdateLogs ¶ added in v0.9.0
func (u ModuleVersionUpdate) IncludedInUpdateLogs() bool
IncludedInUpdateLogs returns true when this item should appear in grouped update output.
func (ModuleVersionUpdate) IsApplied ¶ added in v0.9.0
func (u ModuleVersionUpdate) IsApplied() bool
IsApplied returns true when the module update was written successfully.
func (ModuleVersionUpdate) IsApplyPending ¶ added in v0.9.0
func (u ModuleVersionUpdate) IsApplyPending() bool
IsApplyPending returns true when the module update is ready to be written.
func (ModuleVersionUpdate) IsUpdatable ¶ added in v0.9.0
func (u ModuleVersionUpdate) IsUpdatable() bool
IsUpdatable returns true when the dependency can be applied or surfaced in update logs.
func (ModuleVersionUpdate) MarkApplied ¶ added in v0.9.0
func (u ModuleVersionUpdate) MarkApplied() ModuleVersionUpdate
MarkApplied transitions the module outcome into an applied state.
func (ModuleVersionUpdate) MarkError ¶ added in v0.9.0
func (u ModuleVersionUpdate) MarkError(issue string) ModuleVersionUpdate
MarkError transitions the module outcome into an error state with context.
func (ModuleVersionUpdate) ModulePath ¶
func (u ModuleVersionUpdate) ModulePath() string
ModulePath returns the Terraform module path containing the dependency.
func (ModuleVersionUpdate) Source ¶
func (u ModuleVersionUpdate) Source() string
Source returns the dependency source reference.
func (ModuleVersionUpdate) StatusLabel ¶ added in v0.9.0
func (u ModuleVersionUpdate) StatusLabel() string
StatusLabel returns a human-readable state for reporting surfaces.
type ProviderDependency ¶ added in v0.9.0
type ProviderDependency struct {
ModulePath string `json:"module_path"`
ProviderName string `json:"provider_name"`
ProviderSource string `json:"provider_source"`
Constraint string `json:"constraint"`
}
ProviderDependency describes a discovered Terraform provider dependency before any checks are run.
type ProviderVersionUpdate ¶
type ProviderVersionUpdate struct {
Dependency ProviderDependency `json:"dependency"`
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
BumpedVersion string `json:"bumped_version,omitempty"`
Status UpdateStatus `json:"status"`
Issue string `json:"issue,omitempty"`
File string `json:"file,omitempty"`
}
ProviderVersionUpdate represents the outcome of checking a Terraform provider dependency.
func NewProviderVersionUpdate ¶ added in v0.9.0
func NewProviderVersionUpdate(dep ProviderDependency) ProviderVersionUpdate
NewProviderVersionUpdate creates an up-to-date provider outcome from a discovered dependency.
func (ProviderVersionUpdate) Constraint ¶
func (u ProviderVersionUpdate) Constraint() string
Constraint returns the declared version constraint.
func (ProviderVersionUpdate) DisplayAvailable ¶ added in v0.9.0
func (u ProviderVersionUpdate) DisplayAvailable() string
DisplayAvailable returns the version selected for update application.
func (ProviderVersionUpdate) DisplayCurrent ¶ added in v0.9.0
func (u ProviderVersionUpdate) DisplayCurrent() string
DisplayCurrent returns the best current-version representation for humans.
func (ProviderVersionUpdate) DisplayLatest ¶ added in v0.9.0
func (u ProviderVersionUpdate) DisplayLatest() string
DisplayLatest returns the latest version only when it adds signal beyond the chosen bump.
func (ProviderVersionUpdate) IncludedInUpdateLogs ¶ added in v0.9.0
func (u ProviderVersionUpdate) IncludedInUpdateLogs() bool
IncludedInUpdateLogs returns true when this item should appear in grouped update output.
func (ProviderVersionUpdate) IsApplied ¶ added in v0.9.0
func (u ProviderVersionUpdate) IsApplied() bool
IsApplied returns true when the provider update was written successfully.
func (ProviderVersionUpdate) IsApplyPending ¶ added in v0.9.0
func (u ProviderVersionUpdate) IsApplyPending() bool
IsApplyPending returns true when the provider update is ready to be written.
func (ProviderVersionUpdate) IsUpdatable ¶ added in v0.9.0
func (u ProviderVersionUpdate) IsUpdatable() bool
IsUpdatable returns true when the dependency can be applied or surfaced in update logs.
func (ProviderVersionUpdate) MarkApplied ¶ added in v0.9.0
func (u ProviderVersionUpdate) MarkApplied() ProviderVersionUpdate
MarkApplied transitions the provider outcome into an applied state.
func (ProviderVersionUpdate) MarkError ¶ added in v0.9.0
func (u ProviderVersionUpdate) MarkError(issue string) ProviderVersionUpdate
MarkError transitions the provider outcome into an error state with context.
func (ProviderVersionUpdate) ModulePath ¶
func (u ProviderVersionUpdate) ModulePath() string
ModulePath returns the Terraform module path containing the dependency.
func (ProviderVersionUpdate) ProviderName ¶
func (u ProviderVersionUpdate) ProviderName() string
ProviderName returns the Terraform provider local name.
func (ProviderVersionUpdate) ProviderSource ¶
func (u ProviderVersionUpdate) ProviderSource() string
ProviderSource returns the provider source reference.
func (ProviderVersionUpdate) StatusLabel ¶ added in v0.9.0
func (u ProviderVersionUpdate) StatusLabel() string
StatusLabel returns a human-readable state for reporting surfaces.
type RegistryClient ¶
type RegistryClient interface {
ModuleVersions(ctx context.Context, namespace, name, provider string) ([]string, error)
ProviderVersions(ctx context.Context, namespace, typeName string) ([]string, error)
}
RegistryClient queries the Terraform Registry for version information.
func NewCachedRegistryClient ¶ added in v0.9.0
func NewCachedRegistryClient(base RegistryClient) RegistryClient
type UpdateConfig ¶
type UpdateConfig struct {
Enabled bool `yaml:"enabled" json:"enabled" jsonschema:"description=Enable dependency update checks,default=false"`
Target string `` /* 161-byte string literal not displayed */
Bump string `` /* 156-byte string literal not displayed */
Ignore []string `yaml:"ignore,omitempty" json:"ignore,omitempty" jsonschema:"description=Provider or module sources to ignore"`
Pipeline bool `` /* 137-byte string literal not displayed */
}
UpdateConfig defines configuration for the update plugin.
func (*UpdateConfig) IsIgnored ¶
func (c *UpdateConfig) IsIgnored(source string) bool
IsIgnored returns true if the given source should be ignored.
func (*UpdateConfig) ShouldCheckModules ¶
func (c *UpdateConfig) ShouldCheckModules() bool
ShouldCheckModules returns true if modules should be checked.
func (*UpdateConfig) ShouldCheckProviders ¶
func (c *UpdateConfig) ShouldCheckProviders() bool
ShouldCheckProviders returns true if providers should be checked.
func (*UpdateConfig) Validate ¶
func (c *UpdateConfig) Validate() error
Validate checks if the config values are valid.
type UpdateResult ¶
type UpdateResult struct {
Modules []ModuleVersionUpdate `json:"modules,omitempty"`
Providers []ProviderVersionUpdate `json:"providers,omitempty"`
Summary UpdateSummary `json:"summary"`
// contains filtered or unexported fields
}
UpdateResult contains all version check results.
func NewUpdateResult ¶ added in v0.9.0
func NewUpdateResult() *UpdateResult
NewUpdateResult constructs an empty update result accumulator.
func (*UpdateResult) RecordError ¶ added in v0.9.0
func (r *UpdateResult) RecordError()
RecordError adds a non-item-specific operational error to the summary.
type UpdateResultBuilder ¶ added in v0.9.0
type UpdateResultBuilder struct {
// contains filtered or unexported fields
}
UpdateResultBuilder accumulates update outcomes and summary-level errors.
func NewUpdateResultBuilder ¶ added in v0.9.0
func NewUpdateResultBuilder() *UpdateResultBuilder
NewUpdateResultBuilder constructs an empty result builder.
func (*UpdateResultBuilder) AddModuleUpdate ¶ added in v0.9.0
func (b *UpdateResultBuilder) AddModuleUpdate(update ModuleVersionUpdate)
AddModuleUpdate appends a checked module outcome.
func (*UpdateResultBuilder) AddProviderUpdate ¶ added in v0.9.0
func (b *UpdateResultBuilder) AddProviderUpdate(update ProviderVersionUpdate)
AddProviderUpdate appends a checked provider outcome.
func (*UpdateResultBuilder) Build ¶ added in v0.9.0
func (b *UpdateResultBuilder) Build() *UpdateResult
Build finalizes derived fields and returns the accumulated result.
func (*UpdateResultBuilder) RecordError ¶ added in v0.9.0
func (b *UpdateResultBuilder) RecordError()
RecordError adds a non-item-specific operational error to the underlying result.
func (*UpdateResultBuilder) Result ¶ added in v0.9.0
func (b *UpdateResultBuilder) Result() *UpdateResult
Result returns the underlying mutable result.
type UpdateStatus ¶ added in v0.9.0
type UpdateStatus string
UpdateStatus represents the lifecycle state of a dependency update check.
const ( StatusUpToDate UpdateStatus = "up_to_date" StatusUpdateAvailable UpdateStatus = "update_available" StatusApplied UpdateStatus = "applied" StatusSkipped UpdateStatus = "skipped" StatusError UpdateStatus = "error" )
type UpdateSummary ¶
type UpdateSummary struct {
TotalChecked int `json:"total_checked"`
UpdatesAvailable int `json:"updates_available"`
UpdatesApplied int `json:"updates_applied"`
Skipped int `json:"skipped"`
Errors int `json:"errors"`
}
UpdateSummary provides aggregated counts.
func BuildUpdateSummary ¶ added in v0.9.0
func BuildUpdateSummary(result *UpdateResult) UpdateSummary
BuildUpdateSummary recalculates derived counters from the current result items.
type Version ¶
Version represents a semantic version.
func LatestAllowed ¶
func LatestAllowed(versions []Version, constraints []Constraint) (Version, bool)
LatestAllowed finds the highest version from the list that satisfies all constraints.
func LatestByBump ¶
LatestByBump finds the highest version respecting the bump level policy. - patch: only allow same major.minor - minor: only allow same major - major: allow anything (latest absolute)
func ParseVersion ¶
ParseVersion parses a semver string like "1.2.3" or "1.2.3-beta".