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 FindTFFileForModule(modulePath, callName string) string
- func FindTFFileForProvider(modulePath, providerName string) string
- func IsRegistrySource(source string) bool
- func ParseModuleSource(source string) (namespace, name, provider string, err error)
- func ParseProviderSource(source string) (namespace, typeName string, err error)
- func SatisfiesAll(v Version, constraints []Constraint) bool
- func WriteModuleVersion(filePath, moduleName, newVersion string) error
- func WriteProviderVersion(filePath, providerName, newConstraint string) error
- type Checker
- type Constraint
- type ConstraintOp
- type HTTPRegistryClient
- type ModuleVersionUpdate
- type ProviderVersionUpdate
- type RegistryClient
- type UpdateConfig
- type UpdateResult
- 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 FindTFFileForModule ¶
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 ¶
FindTFFileForProvider searches for the .tf file containing the required_providers block.
func IsRegistrySource ¶
IsRegistrySource returns true if the source looks like a Terraform registry reference.
func ParseModuleSource ¶
ParseModuleSource parses a registry module source like "hashicorp/consul/aws" into (namespace, name, provider).
func ParseProviderSource ¶
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 ¶
WriteModuleVersion updates the version attribute of a module block in a .tf file.
func WriteProviderVersion ¶
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.
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 ¶
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".