drift

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package drift provides drift detection utilities for Atlantis. It enables detecting infrastructure drift outside of PR workflows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetOptions

type GetOptions struct {
	// ProjectName filters by project name (exact match).
	ProjectName string
	// Path filters by project path (exact match).
	Path string
	// Workspace filters by Terraform workspace (exact match).
	Workspace string
	// Ref filters by git reference (exact match). Drift records are keyed
	// by ref, so callers that want to act on a specific branch/commit
	// should set this to avoid mixing data across refs.
	Ref string
	// BaseBranch filters by the branch context used for repo-config branch
	// filters and undiverged checks.
	BaseBranch string
	// MaxAge filters out drift results older than this duration.
	// If zero, no age filtering is applied.
	MaxAge time.Duration
	// Exact treats empty project/path/workspace/ref/base_branch fields as exact
	// values instead of wildcards. This is useful for deleting a specific drift
	// record whose identity legitimately contains empty fields.
	Exact bool
}

GetOptions defines optional filters for retrieving drift results.

type InMemoryRemediationService

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

InMemoryRemediationService implements RemediationService with in-memory storage.

func NewInMemoryRemediationService

func NewInMemoryRemediationService(driftStorage Storage) *InMemoryRemediationService

NewInMemoryRemediationService creates a new in-memory remediation service.

func (*InMemoryRemediationService) GetResult

GetResult retrieves a remediation result by ID.

func (*InMemoryRemediationService) ListResults

func (s *InMemoryRemediationService) ListResults(repository string, limit int) ([]*models.RemediationResult, error)

ListResults returns all remediation results for a repository.

func (*InMemoryRemediationService) Remediate

Remediate executes drift remediation for the given projects.

type InMemoryStorage

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

InMemoryStorage is an in-memory implementation of drift Storage. Drift results are lost on server restart.

func NewInMemoryStorage

func NewInMemoryStorage() *InMemoryStorage

NewInMemoryStorage creates a new in-memory drift storage.

func (*InMemoryStorage) Delete

func (s *InMemoryStorage) Delete(repository string, projectName string) error

Delete removes drift results for a repository.

func (*InMemoryStorage) DeleteMatching

func (s *InMemoryStorage) DeleteMatching(repository string, opts GetOptions) error

DeleteMatching removes drift results for a repository that match the given filters.

func (*InMemoryStorage) Get

func (s *InMemoryStorage) Get(repository string, opts GetOptions) ([]models.ProjectDrift, error)

Get retrieves drift results for a repository with optional filtering.

func (*InMemoryStorage) GetAll

func (s *InMemoryStorage) GetAll() (map[string][]models.ProjectDrift, error)

GetAll retrieves all stored drift results across all repositories.

func (*InMemoryStorage) Store

func (s *InMemoryStorage) Store(repository string, drift models.ProjectDrift) error

Store saves a drift result for a project.

type Parser

type Parser struct{}

Parser extracts drift information from Terraform plan output.

func NewParser

func NewParser() *Parser

NewParser creates a new drift parser.

func (*Parser) HasDrift

func (p *Parser) HasDrift(plan *models.PlanSuccess) bool

HasDrift returns true if the plan output indicates infrastructure drift.

func (*Parser) ParsePlanOutput

func (p *Parser) ParsePlanOutput(plan *models.PlanSuccess) models.DriftSummary

ParsePlanOutput extracts drift information from a PlanSuccess result. This leverages the existing plan output parsing infrastructure in models.PlanSuccess.

func (*Parser) ParsePlanStats

func (p *Parser) ParsePlanStats(stats models.PlanSuccessStats, summary string) models.DriftSummary

ParsePlanStats creates a drift summary from plan statistics. This is useful when you have pre-computed stats.

type RemediationExecutor

type RemediationExecutor interface {
	// ExecutePlan runs a plan for the given project.
	ExecutePlan(repository, ref, vcsType, projectName, path, workspace string) (output string, driftSummary *models.DriftSummary, err error)

	// ExecuteApplyProjects plans and applies the given projects as one operation.
	ExecuteApplyProjects(repository, ref, vcsType string, projects []models.ProjectDrift) ([]models.ProjectRemediationResult, error)
}

RemediationExecutor executes the actual plan/apply operations. This interface allows the service to be decoupled from the API controller.

type RemediationHistory

type RemediationHistory struct {
	// ID is the unique identifier for this history entry.
	ID string `json:"id"`
	// Repository is the full repository name.
	Repository string `json:"repository"`
	// RemediationID links to the remediation result.
	RemediationID string `json:"remediation_id"`
	// Action is the remediation action performed.
	Action models.RemediationAction `json:"action"`
	// Status is the final status.
	Status models.RemediationStatus `json:"status"`
	// Timestamp is when the remediation occurred.
	Timestamp time.Time `json:"timestamp"`
	// ProjectCount is the number of projects remediated.
	ProjectCount int `json:"project_count"`
	// SuccessCount is the number of successful remediations.
	SuccessCount int `json:"success_count"`
}

RemediationHistory represents the history of remediations for tracking.

type RemediationService

type RemediationService interface {
	// Remediate executes drift remediation for the given projects.
	// It returns a result ID that can be used to track the remediation status.
	Remediate(req models.RemediationRequest, executor RemediationExecutor) (*models.RemediationResult, error)

	// GetResult retrieves a remediation result by ID.
	GetResult(id string) (*models.RemediationResult, error)

	// ListResults returns all remediation results for a repository.
	ListResults(repository string, limit int) ([]*models.RemediationResult, error)
}

RemediationService handles drift remediation operations.

type Storage

type Storage interface {
	// Store saves a drift result for a project.
	Store(repository string, drift models.ProjectDrift) error

	// Get retrieves drift results for a repository.
	// Optional filters can limit results by project name, path, or workspace.
	Get(repository string, opts GetOptions) ([]models.ProjectDrift, error)

	// Delete removes drift results for a repository.
	// If projectName is empty, all drift results for the repository are removed.
	Delete(repository string, projectName string) error

	// DeleteMatching removes drift results for a repository that match the given
	// filters. At least one filter must be set; use Delete(repository, "") to
	// clear an entire repository.
	DeleteMatching(repository string, opts GetOptions) error

	// GetAll retrieves all stored drift results across all repositories.
	GetAll() (map[string][]models.ProjectDrift, error)
}

Storage defines the interface for drift status persistence. Implementations can store drift data in memory, database, or external services.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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