updateengine

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package updateengine provides the core logic for Terraform dependency version checking and updating.

Index

Constants

View Source
const (
	TargetAll       = "all"
	TargetModules   = "modules"
	TargetProviders = "providers"
)

Target constants define what dependencies to check.

View Source
const (
	BumpPatch = "patch"
	BumpMinor = "minor"
	BumpMajor = "major"
)

Bump level constants.

Variables

This section is empty.

Functions

func BumpConstraint

func BumpConstraint(original string, newVersion Version) string

BumpConstraint generates a new constraint string based on the original style and new version.

func FindTFFileForModule

func FindTFFileForModule(modulePath, callName string) string

FindTFFileForModule searches for the .tf file containing a specific module block. This is a best-effort search used to populate the File field.

func FindTFFileForProvider

func FindTFFileForProvider(modulePath, providerName string) string

FindTFFileForProvider searches for the .tf file containing the required_providers block.

func IsRegistrySource

func IsRegistrySource(source string) bool

IsRegistrySource returns true if the source looks like a Terraform registry reference.

func ParseModuleSource

func ParseModuleSource(source string) (namespace, name, provider string, err error)

ParseModuleSource parses a registry module source like "hashicorp/consul/aws" into (namespace, name, provider).

func ParseProviderSource

func ParseProviderSource(source string) (namespace, typeName string, err error)

ParseProviderSource parses a provider source like "hashicorp/aws" into (namespace, typeName).

func SatisfiesAll

func SatisfiesAll(v Version, constraints []Constraint) bool

SatisfiesAll checks if a version satisfies all constraints.

func WriteModuleVersion

func WriteModuleVersion(filePath, moduleName, newVersion string) error

WriteModuleVersion updates the version attribute of a module block in a .tf file.

func WriteProviderVersion

func WriteProviderVersion(filePath, providerName, newConstraint string) error

WriteProviderVersion updates the version constraint in a required_providers block. Since hclwrite doesn't support nested object manipulation directly, we use token-level string replacement within the provider attribute.

Types

type Checker

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

Checker performs version checks across Terraform modules.

func NewChecker

func NewChecker(cfg *UpdateConfig, p *parser.Parser, reg RegistryClient, write bool) *Checker

NewChecker creates a new dependency version checker.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, modules []*discovery.Module) (*UpdateResult, error)

Check performs version checks on all provided modules.

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 HTTPRegistryClient

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

HTTPRegistryClient implements RegistryClient using the public Terraform Registry API.

func NewRegistryClient

func NewRegistryClient() *HTTPRegistryClient

NewRegistryClient creates a new HTTP-based registry client.

func NewRegistryClientWithBase

func NewRegistryClientWithBase(baseURL string) *HTTPRegistryClient

NewRegistryClientWithBase creates a registry client with a custom base URL (for testing).

func (*HTTPRegistryClient) ModuleVersions

func (c *HTTPRegistryClient) ModuleVersions(ctx context.Context, namespace, name, provider string) ([]string, error)

ModuleVersions fetches available versions for a registry module.

func (*HTTPRegistryClient) ProviderVersions

func (c *HTTPRegistryClient) ProviderVersions(ctx context.Context, namespace, typeName string) ([]string, error)

ProviderVersions fetches available versions for a registry provider.

type ModuleVersionUpdate

type ModuleVersionUpdate struct {
	ModulePath     string `json:"module_path"`
	CallName       string `json:"call_name"`
	Source         string `json:"source"`
	CurrentVersion string `json:"current_version"`
	LatestVersion  string `json:"latest_version"`
	BumpedVersion  string `json:"bumped_version,omitempty"`
	Constraint     string `json:"constraint"`
	Updated        bool   `json:"updated"`
	Skipped        bool   `json:"skipped"`
	SkipReason     string `json:"skip_reason,omitempty"`
	File           string `json:"file,omitempty"`
}

ModuleVersionUpdate represents a version check for a Terraform module dependency.

type ProviderVersionUpdate

type ProviderVersionUpdate struct {
	ModulePath     string `json:"module_path"`
	ProviderName   string `json:"provider_name"`
	ProviderSource string `json:"provider_source"`
	CurrentVersion string `json:"current_version"`
	LatestVersion  string `json:"latest_version"`
	BumpedVersion  string `json:"bumped_version,omitempty"`
	Constraint     string `json:"constraint"`
	Updated        bool   `json:"updated"`
	Skipped        bool   `json:"skipped"`
	SkipReason     string `json:"skip_reason,omitempty"`
	File           string `json:"file,omitempty"`
}

ProviderVersionUpdate represents a version check for a Terraform provider.

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.

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"`
}

UpdateResult contains all version check results.

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.

type Version

type Version struct {
	Major      int
	Minor      int
	Patch      int
	Prerelease string
}

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

func LatestByBump(current Version, versions []Version, bump string) (Version, bool)

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

func ParseVersion(s string) (Version, error)

ParseVersion parses a semver string like "1.2.3" or "1.2.3-beta".

func (Version) Compare

func (v Version) Compare(other Version) int

Compare returns -1, 0, or 1.

func (Version) IsZero

func (v Version) IsZero() bool

IsZero returns true if the version is 0.0.0.

func (Version) String

func (v Version) String() string

String returns the version as "major.minor.patch" (or with prerelease).

Jump to

Keyboard shortcuts

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