models

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: 13 Imported by: 352

Documentation

Overview

Copyright 2017 HootSuite Media Inc. SPDX-License-Identifier: Apache-2.0 Modified hereafter by contributors to runatlantis/atlantis.

Package models holds all models that are needed across packages. We place these models in their own package so as to avoid circular dependencies between packages (which is a compile error).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApprovalCoversAllHashes added in v0.44.0

func ApprovalCoversAllHashes(approvalHashes, required []string) bool

ApprovalCoversAllHashes reports whether approvalHashes contains every element of required.

func CheckedBaseBranchRef added in v0.45.0

func CheckedBaseBranchRef(baseBranch string) (string, bool)

CheckedBaseBranchRef returns the normalized branch name for a safe API base_branch.

func GenerateLockKey added in v0.36.0

func GenerateLockKey(project Project, workspace string) string

GenerateLockKey creates a consistent lock key from a project and workspace. This ensures the same format is used across all locking operations.

func HashPolicyItem added in v0.44.0

func HashPolicyItem(item string) string

HashPolicyItem returns the SHA-256 hex digest of a policy output item.

func IsSupportedDriftVCSHostType added in v0.45.0

func IsSupportedDriftVCSHostType(vcsType string) bool

IsSupportedDriftVCSHostType reports whether the drift API can parse and execute requests for a VCS provider today.

func IsUnsafeAPIRef added in v0.45.0

func IsUnsafeAPIRef(ref string) bool

IsUnsafeAPIRef reports whether a caller-controlled non-PR API ref can target provider pull/merge request namespaces or alter git fetch behavior.

func IsValidAPIRepositoryForType added in v0.45.0

func IsValidAPIRepositoryForType(repository, vcsType string) bool

IsValidAPIRepositoryForType reports whether repository has a shape that can be safely handed to the configured VCS client for drift APIs.

func IsValidAPIWorkspace added in v0.45.0

func IsValidAPIWorkspace(workspace string) bool

IsValidAPIWorkspace reports whether an explicit drift/remediation workspace selector is safe to use for plan-file path construction.

func NormalizeAPIPath added in v0.45.0

func NormalizeAPIPath(directory string) (string, bool)

NormalizeAPIPath returns a clean repo-relative selector path for drift APIs.

func NormalizeAPIRef added in v0.45.0

func NormalizeAPIRef(ref string) string

NormalizeAPIRef normalizes branch refs used by drift and API command requests.

func ParseGitlabHostname added in v0.43.0

func ParseGitlabHostname(raw string) (host, basePath string, err error)

ParseGitlabHostname splits a user-supplied GitLab hostname into its host and base path components. Accepted inputs include bare hosts ("gitlab.com"), hosts with a subpath ("acme.com/gitlab"), and fully-qualified URLs ("https://acme.com:8080/gitlab/").

The returned host includes any port. The returned basePath is either empty or starts with "/" and has no trailing slash.

func RequiresBaseBranchForRef added in v0.45.0

func RequiresBaseBranchForRef(ref string) bool

RequiresBaseBranchForRef reports whether a drift API ref needs an explicit branch context.

func SplitRepoFullName added in v0.4.7

func SplitRepoFullName(repoFullName string) (owner string, repo string)

SplitRepoFullName splits a repo full name up into its owner and repo name segments. If the repoFullName is malformed, may return empty strings for owner or repo. Ex. runatlantis/atlantis => (runatlantis, atlantis)

gitlab/subgroup/runatlantis/atlantis => (gitlab/subgroup/runatlantis, atlantis)
azuredevops/project/atlantis => (azuredevops/project, atlantis)

Types

type ApprovalStatus added in v0.17.4

type ApprovalStatus struct {
	IsApproved bool
	ApprovedBy string
	Date       time.Time
}

type CommitStatus added in v0.4.3

type CommitStatus int

CommitStatus is the result of executing an Atlantis command for the commit. In Github the options are: error, failure, pending, success. In Gitlab the options are: failed, canceled, pending, running, success. We only support Failed, Pending, Success.

const (
	PendingCommitStatus CommitStatus = iota
	SuccessCommitStatus
	FailedCommitStatus
)

func (CommitStatus) String added in v0.4.3

func (s CommitStatus) String() string

type DriftDetectionPath added in v0.45.0

type DriftDetectionPath struct {
	// Directory is the relative path to the Terraform directory.
	Directory string `json:"directory"`
	// Workspace is the Terraform workspace (optional).
	Workspace string `json:"workspace,omitempty"`
}

DriftDetectionPath represents a project path for drift detection.

type DriftDetectionRequest added in v0.45.0

type DriftDetectionRequest struct {
	// Repository is the full repository name (owner/repo). Required.
	Repository string `json:"repository"`
	// Ref is the git reference (branch/tag/commit) to check for drift. Required.
	Ref string `json:"ref"`
	// BaseBranch is required when ref is a raw commit SHA or tag value.
	// It preserves Atlantis repo-config branch filtering and undiverged checks.
	BaseBranch string `json:"base_branch,omitempty"`
	// Type is the VCS provider type (Github/Gitlab). Required.
	Type string `json:"type"`
	// Projects is a list of project names to check. If empty, all projects are checked.
	Projects []string `json:"projects,omitempty"`
	// Paths is a list of paths to check. If empty, project names are used.
	Paths []DriftDetectionPath `json:"paths,omitempty"`
}

DriftDetectionRequest is the API request for POST /api/drift/detect.

func (*DriftDetectionRequest) Validate added in v0.45.0

func (r *DriftDetectionRequest) Validate() []FieldError

Validate checks the request and returns any validation errors.

type DriftDetectionResult added in v0.45.0

type DriftDetectionResult struct {
	// ID is a unique identifier for this detection run.
	ID string `json:"id"`
	// Repository is the full repository name.
	Repository string `json:"repository"`
	// Projects contains the drift status for each project checked.
	Projects []ProjectDrift `json:"projects"`
	// DetectedAt is when the drift detection was performed.
	DetectedAt time.Time `json:"detected_at"`
	// TotalProjects is the total number of projects checked.
	TotalProjects int `json:"total_projects"`
	// ProjectsWithDrift is the number of projects that have drift.
	ProjectsWithDrift int `json:"projects_with_drift"`
}

DriftDetectionResult is the API response for POST /api/drift/detect.

func NewDriftDetectionResult added in v0.45.0

func NewDriftDetectionResult(repository string) *DriftDetectionResult

NewDriftDetectionResult creates a new DriftDetectionResult with a generated ID.

func (*DriftDetectionResult) AddProject added in v0.45.0

func (r *DriftDetectionResult) AddProject(project ProjectDrift)

AddProject adds a project drift result and updates counts.

type DriftStatusResponse added in v0.45.0

type DriftStatusResponse struct {
	// Repository is the full repository name (owner/repo).
	Repository string `json:"repository"`
	// Projects contains the drift status for each project.
	Projects []ProjectDrift `json:"projects"`
	// CheckedAt is when the drift check was performed.
	CheckedAt time.Time `json:"checked_at"`
	// TotalProjects is the total number of projects checked.
	TotalProjects int `json:"total_projects"`
	// ProjectsWithDrift is the number of projects that have drift.
	ProjectsWithDrift int `json:"projects_with_drift"`
}

DriftStatusResponse is the API response for GET /api/drift/status.

func NewDriftStatusResponse added in v0.45.0

func NewDriftStatusResponse(repository string, projects []ProjectDrift) DriftStatusResponse

NewDriftStatusResponse creates a DriftStatusResponse from a list of ProjectDrift.

type DriftSummary added in v0.45.0

type DriftSummary struct {
	// HasDrift indicates whether any drift was detected.
	HasDrift bool `json:"has_drift"`
	// ToAdd is the number of resources to add.
	ToAdd int `json:"to_add"`
	// ToChange is the number of resources to change.
	ToChange int `json:"to_change"`
	// ToDestroy is the number of resources to destroy.
	ToDestroy int `json:"to_destroy"`
	// ToImport is the number of resources to import (Terraform 1.5+).
	ToImport int `json:"to_import"`
	// ToForget is the number of resources to forget.
	ToForget int `json:"to_forget"`
	// Summary is a human-readable summary of the drift.
	Summary string `json:"summary"`
	// ChangesOutside indicates if Terraform detected changes made outside of Terraform.
	ChangesOutside bool `json:"changes_outside"`
}

DriftSummary represents detected infrastructure drift from a plan output. It captures the changes detected between the Terraform state and actual infrastructure.

func NewDriftSummaryFromPlanStats added in v0.45.0

func NewDriftSummaryFromPlanStats(stats PlanSuccessStats, summary string) DriftSummary

NewDriftSummaryFromPlanStats creates a DriftSummary from PlanSuccessStats. This leverages the existing plan output parsing infrastructure.

func NewDriftSummaryFromPlanSuccess added in v0.45.0

func NewDriftSummaryFromPlanSuccess(plan *PlanSuccess) DriftSummary

NewDriftSummaryFromPlanSuccess creates a DriftSummary from a PlanSuccess result.

func (DriftSummary) TotalChanges added in v0.45.0

func (d DriftSummary) TotalChanges() int

TotalChanges returns the total number of resource changes.

type FieldError added in v0.45.0

type FieldError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

FieldError represents a validation error for a specific field.

type ImportSuccess added in v0.22.0

type ImportSuccess struct {
	// Output is the output from terraform import
	Output string
	// RePlanCmd is the command that users should run to re-plan this project.
	RePlanCmd string
}

ImportSuccess is the result of a successful import run.

type MergeableStatus added in v0.37.0

type MergeableStatus struct {
	IsMergeable bool
	// Short human readable explanation of why the PR is (or is not) mergeable
	Reason string
	// BlockingStatuses holds the names of the commit statuses that caused the
	// pull request to be considered not mergeable because of the project's
	// "Only allow merge if pipeline succeeds" setting. It lets per-project
	// command requirement checks ignore statuses that belong to other projects
	// in the same pull request (a failing plan in project B must not block an
	// apply of project A). Currently only populated by the GitLab client.
	BlockingStatuses []string
}

type Plan

type Plan struct {
	// Project is the project this plan is for.
	Project Project
	// LocalPath is the absolute path to the plan on disk
	// (versus the relative path from the repo root).
	LocalPath string
}

Plan is the result of running an Atlantis plan command. This model is used to represent a plan on disk.

type PlanSuccess added in v0.4.14

type PlanSuccess struct {
	// TerraformOutput is the output from Terraform of running plan.
	TerraformOutput string
	// LockURL is the full URL to the lock held by this plan.
	LockURL string
	// RePlanCmd is the command that users should run to re-plan this project.
	RePlanCmd string
	// ApplyCmd is the command that users should run to apply this plan.
	ApplyCmd string
	// MergedAgain is true if we're using the checkout merge strategy and the
	// branch we're merging into had been updated, and we had to merge again
	// before planning
	MergedAgain bool
}

PlanSuccess is the result of a successful plan.

func (PlanSuccess) DiffMarkdownFormattedTerraformOutput added in v0.17.3

func (p PlanSuccess) DiffMarkdownFormattedTerraformOutput() string

DiffMarkdownFormattedTerraformOutput formats the Terraform output to match diff markdown format

func (*PlanSuccess) DiffSummary added in v0.23.0

func (p *PlanSuccess) DiffSummary() string

DiffSummary extracts one line summary of plan changes from TerraformOutput. When the output contains multiple "Plan:" lines (e.g. terragrunt stack run plan, which prints one summary per unit), the counters are aggregated so the rendered summary reflects the total across all units.

func (*PlanSuccess) NoChanges added in v0.23.0

func (p *PlanSuccess) NoChanges() bool

NoChanges returns true if the plan has no changes.

func (PlanSuccess) Stats added in v0.24.3

func (p PlanSuccess) Stats() PlanSuccessStats

Stats returns plan change stats and contextual information.

func (*PlanSuccess) Summary added in v0.17.0

func (p *PlanSuccess) Summary() string

Summary extracts summaries of plan changes from TerraformOutput.

type PlanSuccessStats added in v0.24.3

type PlanSuccessStats struct {
	Import, Add, Change, Destroy, Forget int
	Changes, ChangesOutside              bool
}

PlanSuccessStats holds stats for a plan.

func NewPlanSuccessStats added in v0.24.3

func NewPlanSuccessStats(output string) PlanSuccessStats

type PolicyCheckResults added in v0.24.0

type PolicyCheckResults struct {
	PreConftestOutput  string
	PostConftestOutput string
	// PolicySetResults is the output from policy check binary(conftest|opa)
	PolicySetResults []PolicySetResult
	// LockURL is the full URL to the lock held by this policy check.
	LockURL string
	// RePlanCmd is the command that users should run to re-plan this project.
	RePlanCmd string
	// ApplyCmd is the command that users should run to apply this plan.
	ApplyCmd string
	// ApprovePoliciesCmd is the command that users should run to approve policies for this plan.
	ApprovePoliciesCmd string
	// HasDiverged is true if we're using the checkout merge strategy and the
	// branch we're merging into has been updated since we cloned and merged
	// it.
	HasDiverged bool
}

PolicyCheckResults is the result of a successful policy check run.

func (*PolicyCheckResults) CombinedOutput added in v0.24.0

func (p *PolicyCheckResults) CombinedOutput() string

func (*PolicyCheckResults) PolicyCleared added in v0.24.0

func (p *PolicyCheckResults) PolicyCleared() bool

PolicyCleared is used to determine if policies have all succeeded or been approved.

func (*PolicyCheckResults) PolicySummary added in v0.24.0

func (p *PolicyCheckResults) PolicySummary() string

PolicySummary returns a summary of the current approval state of policy sets.

func (*PolicyCheckResults) Summary added in v0.24.0

func (p *PolicyCheckResults) Summary() string

Summary extracts one line summary of each policy check.

type PolicySetApproval added in v0.44.0

type PolicySetApproval struct {
	Approver string
	Hashes   []string
}

type PolicySetResult added in v0.24.0

type PolicySetResult struct {
	PolicySetName    string
	PolicyOutput     string
	Passed           bool
	ReqApprovalCount int
	Approvals        []PolicySetApproval
	Hashes           []string
	PolicyItemRegex  string
}

func NewPolicySetResult added in v0.44.0

func NewPolicySetResult(policySetName string, policyOutput string, passed bool, reqApprovalCount int, policyItemRegex string) (*PolicySetResult, error)

func (*PolicySetResult) ApprovedHashes added in v0.44.0

func (p *PolicySetResult) ApprovedHashes() []string

ApprovedHashes returns the deduplicated union of hashes across all approvals.

func (*PolicySetResult) GetCurApprovals added in v0.44.0

func (p *PolicySetResult) GetCurApprovals() int

GetCurApprovals returns the number of approvals that cover all hashes in this policy set result.

func (*PolicySetResult) PolicySetHashes added in v0.44.0

func (p *PolicySetResult) PolicySetHashes(policyItemRegex string) ([]string, error)

type PolicySetStatus added in v0.24.0

type PolicySetStatus struct {
	PolicySetName   string
	Passed          bool
	Approvals       []PolicySetApproval
	Hashes          []string
	PolicyItemRegex string
}

PolicySetStatus tracks the approval state for a given policy set.

func (*PolicySetStatus) GetCurApprovals added in v0.44.0

func (pss *PolicySetStatus) GetCurApprovals() int

GetCurApprovals returns the number of approvals that cover all hashes in this policy set.

func (*PolicySetStatus) OwnerHasFullyApproved added in v0.44.0

func (pss *PolicySetStatus) OwnerHasFullyApproved(owner string) bool

type Project

type Project struct {
	// ProjectName of the project
	ProjectName string
	// RepoFullName is the owner and repo name, ex. "runatlantis/atlantis"
	RepoFullName string
	// Path to project root in the repo.
	// If "." then project is at root.
	// Never ends in "/".
	// todo: rename to RepoRelDir to match rest of project once we can separate
	// out how this is saved in boltdb vs. its usage everywhere else so we don't
	// break existing dbs.
	Path string
}

Project represents a Terraform project. Since there may be multiple Terraform projects in a single repo we also include Path to the project root relative to the repo root.

func NewProject

func NewProject(repoFullName string, path string, projectName string) Project

NewProject constructs a Project. Use this constructor because it sets Path correctly.

func (Project) String added in v0.4.0

func (p Project) String() string

type ProjectCounts added in v0.44.1

type ProjectCounts struct {
	Success   int
	Total     int
	Errored   int
	NoChanges int
}

ProjectCounts holds the success/failure counts for a set of project operations. For command.Apply: Errored counts projects with apply errors. NoChanges is a subset of Success (projects that were already up to date count as successful). NoChanges is ignored for all other commands.

type ProjectDrift added in v0.45.0

type ProjectDrift struct {
	// ProjectName is the name of the project (from atlantis.yaml).
	ProjectName string `json:"project_name"`
	// Path is the relative path to the project root within the repository.
	Path string `json:"path"`
	// Workspace is the Terraform workspace.
	Workspace string `json:"workspace"`
	// Ref is the git reference (branch/tag/commit) that was checked.
	Ref string `json:"ref"`
	// BaseBranch is the branch context used for repo config branch filters and
	// requirements when Ref is a tag or commit SHA.
	BaseBranch string `json:"base_branch,omitempty"`
	// ResolvedCommit is the checked-out commit SHA that produced this drift
	// record. Remediation uses it to avoid applying stale drift after a moving ref
	// changes.
	ResolvedCommit string `json:"resolved_commit,omitempty"`
	// DetectionID links this drift result to the detection run that produced it.
	DetectionID string `json:"detection_id,omitempty"`
	// Drift contains the drift summary for this project.
	Drift DriftSummary `json:"drift"`
	// LastChecked is when the drift was last detected.
	LastChecked time.Time `json:"last_checked"`
	// Error contains any error message if drift detection failed for this project.
	Error string `json:"error,omitempty"`
}

ProjectDrift represents the drift status for a specific project.

type ProjectLock

type ProjectLock struct {
	// Project is the project that is being locked.
	Project Project
	// Pull is the pull request from which the command was run that
	// created this lock.
	Pull PullRequest
	// User is the username of the user that ran the command
	// that created this lock.
	User User
	// Workspace is the Terraform workspace that this
	// lock is being held against.
	Workspace string
	// Time is the time at which the lock was first created.
	Time time.Time
}

ProjectLock represents a lock on a project.

type ProjectPlanStatus added in v0.4.14

type ProjectPlanStatus int

ProjectPlanStatus is the status of where this project is at in the planning cycle.

const (
	// ErroredPlanStatus means that this plan has an error or the apply has an
	// error.
	ErroredPlanStatus ProjectPlanStatus = iota
	// PlannedPlanStatus means that a plan has been successfully generated but
	// not yet applied.
	PlannedPlanStatus
	// PlannedNoChangesPlanStatus means that a plan has been successfully
	// generated with "No changes" and not yet applied.
	PlannedNoChangesPlanStatus
	// ErroredApplyStatus means that a plan has been generated but there was an
	// error while applying it.
	ErroredApplyStatus
	// AppliedPlanStatus means that a plan has been generated and applied
	// successfully.
	AppliedPlanStatus
	// DiscardedPlanStatus means that there was an unapplied plan that was
	// discarded due to a project being unlocked
	DiscardedPlanStatus
	// ErroredPolicyCheckStatus means that the policy check errored or has
	// failing policies.
	ErroredPolicyCheckStatus
	// PassedPolicyCheckStatus means that all policy checks passed or were
	// approved.
	PassedPolicyCheckStatus
)

func (ProjectPlanStatus) String added in v0.4.14

func (p ProjectPlanStatus) String() string

String returns a string representation of the status.

type ProjectRemediationResult added in v0.45.0

type ProjectRemediationResult struct {
	// ProjectName is the name of the project.
	ProjectName string `json:"project_name"`
	// Path is the relative path to the project.
	Path string `json:"path"`
	// Workspace is the Terraform workspace.
	Workspace string `json:"workspace"`
	// Status is the remediation status for this project.
	Status RemediationStatus `json:"status"`
	// PlanOutput contains the plan output if available.
	PlanOutput string `json:"plan_output,omitempty"`
	// ApplyOutput contains the apply output if action was auto-apply.
	ApplyOutput string `json:"apply_output,omitempty"`
	// Error contains any error message.
	Error string `json:"error,omitempty"`
	// DriftBefore contains the drift state before remediation.
	DriftBefore *DriftSummary `json:"drift_before,omitempty"`
	// DriftAfter contains the drift state after remediation (nil if not re-checked).
	DriftAfter *DriftSummary `json:"drift_after,omitempty"`
}

ProjectRemediationResult represents the remediation result for a single project.

type ProjectStatus added in v0.4.14

type ProjectStatus struct {
	Workspace   string
	RepoRelDir  string
	ProjectName string
	// PolicyStatus tracks the policy check status for each policy set.
	PolicyStatus []PolicySetStatus
	// Status is the status of where this project is at in the planning cycle.
	Status ProjectPlanStatus
}

ProjectStatus is the status of a specific project.

type PullReqStatus added in v0.17.4

type PullReqStatus struct {
	ApprovalStatus  ApprovalStatus
	MergeableStatus MergeableStatus
}

type PullRequest

type PullRequest struct {
	// Num is the pull request number or ID.
	Num int
	// HeadCommit is a sha256 that points to the head of the branch that is being
	// pull requested into the base. If the pull request is from Bitbucket Cloud
	// the string will only be 12 characters long because Bitbucket Cloud
	// truncates its commit IDs.
	HeadCommit string
	// URL is the url of the pull request.
	// ex. "https://github.com/runatlantis/atlantis/pull/1"
	URL string
	// HeadBranch is the name of the head branch (the branch that is getting
	// merged into the base).
	HeadBranch string
	// BaseBranch is the name of the base branch (the branch that the pull
	// request is getting merged into).
	BaseBranch string
	// HardenedNonPRRefCheckout makes synthetic non-PR API checkouts fetch the
	// requested ref directly instead of treating it as a branch checkout. This is
	// used by drift/remediation requests that accept branch, tag, and SHA refs.
	HardenedNonPRRefCheckout bool
	// Author is the username of the pull request author.
	Author string
	// Body is the description of the pull request. It may be empty when the VCS
	// payload omits a description.
	Body string
	// State will be one of Open or Closed.
	// Gitlab supports an additional "merged" state but Github doesn't so we map
	// merged to Closed.
	State PullRequestState
	// BaseRepo is the repository that the pull request will be merged into.
	BaseRepo Repo
}

PullRequest is a VCS pull request. GitLab calls these Merge Requests.

type PullRequestEventType added in v0.4.3

type PullRequestEventType int
const (
	OpenedPullEvent PullRequestEventType = iota
	UpdatedPullEvent
	ClosedPullEvent
	OtherPullEvent
)

func (PullRequestEventType) String added in v0.4.3

func (p PullRequestEventType) String() string

type PullRequestOptions added in v0.17.0

type PullRequestOptions struct {
	// When DeleteSourceBranchOnMerge flag is set to true VCS deletes the source branch after the PR is merged
	// Applied by GitLab & AzureDevops
	DeleteSourceBranchOnMerge bool
	// MergeMethod specifies the merge method for the VCS
	// Implemented only for Github
	MergeMethod string
}

PullRequestOptions is used to set optional paralmeters for PullRequest

type PullRequestState added in v0.2.0

type PullRequestState int
const (
	OpenPullState PullRequestState = iota
	ClosedPullState
)

type PullStatus added in v0.4.14

type PullStatus struct {
	// Projects are the projects that have been modified in this pull request.
	Projects []ProjectStatus
	// Pull is the original pull request model.
	Pull PullRequest
}

PullStatus is the current status of a pull request that is in progress.

func (PullStatus) StatusCount added in v0.5.0

func (p PullStatus) StatusCount(status ProjectPlanStatus) int

StatusCount returns the number of projects that have status.

type RemediationAction added in v0.45.0

type RemediationAction string

RemediationAction specifies the type of remediation to perform.

const (
	// RemediationPlanOnly runs a plan to preview remediation without applying.
	RemediationPlanOnly RemediationAction = "plan"
	// RemediationAutoApply runs both plan and apply to fix drift automatically.
	RemediationAutoApply RemediationAction = "apply"
)

func (RemediationAction) Default added in v0.45.0

Default returns the default action if empty.

func (RemediationAction) IsValid added in v0.45.0

func (a RemediationAction) IsValid() bool

IsValid returns true if the action is a recognized value.

type RemediationRequest added in v0.45.0

type RemediationRequest struct {
	// Repository is the full repository name (owner/repo). Required.
	Repository string `json:"repository"`
	// StorageRepository is the internal VCS-host-qualified repository key used
	// for cached drift lookups. It is populated by the API controller.
	StorageRepository string `json:"-"`
	// Ref is the git reference (branch/tag/commit) to remediate. Required.
	Ref string `json:"ref"`
	// ExecutionRef is the original git reference used for checkout/fetch. It is
	// populated by the API controller so storage can use normalized Ref while git
	// still receives an explicit ref such as refs/heads/main when supplied.
	ExecutionRef string `json:"-"`
	// BaseBranch is required when ref is a raw commit SHA or tag value.
	// It preserves Atlantis repo-config branch filtering and undiverged checks.
	BaseBranch string `json:"base_branch,omitempty"`
	// Type is the VCS provider type (Github/Gitlab). Required.
	Type string `json:"type"`
	// Action specifies plan-only or auto-apply. Defaults to "plan".
	Action RemediationAction `json:"action"`
	// Projects is a list of project names to remediate. If empty, all stored
	// projects matching the request filters are remediated. To restrict to
	// projects that actually have detected drift, set DriftOnly to true.
	Projects []string `json:"projects,omitempty"`
	// Paths is a list of repo-relative directories/workspaces to remediate.
	Paths []DriftDetectionPath `json:"paths,omitempty"`
	// Workspaces filters remediation to specific workspaces. If empty, all workspaces.
	Workspaces []string `json:"workspaces,omitempty"`
	// DriftOnly if true, only remediates projects that have detected drift.
	DriftOnly bool `json:"drift_only"`
}

RemediationRequest is the API request for POST /api/drift/remediate.

func (*RemediationRequest) ApplyDefaults added in v0.45.0

func (r *RemediationRequest) ApplyDefaults()

ApplyDefaults applies default values to optional fields.

func (*RemediationRequest) Validate added in v0.45.0

func (r *RemediationRequest) Validate() []FieldError

Validate checks the request and returns any validation errors.

type RemediationResult added in v0.45.0

type RemediationResult struct {
	// ID is a unique identifier for this remediation run.
	ID string `json:"id"`
	// Repository is the full repository name.
	Repository string `json:"repository"`
	// StorageRepository is the internal VCS-host-qualified repository key used
	// to index remediation history. It is omitted from API responses.
	StorageRepository string `json:"-"`
	// Ref is the git reference that was remediated.
	Ref string `json:"ref"`
	// Action is the remediation action performed.
	Action RemediationAction `json:"action"`
	// Status is the overall remediation status.
	Status RemediationStatus `json:"status"`
	// StartedAt is when the remediation started.
	StartedAt time.Time `json:"started_at"`
	// CompletedAt is when the remediation completed.
	CompletedAt *time.Time `json:"completed_at,omitempty"`
	// TotalProjects is the total number of projects targeted.
	TotalProjects int `json:"total_projects"`
	// SuccessCount is the number of projects successfully remediated.
	SuccessCount int `json:"success_count"`
	// FailureCount is the number of projects that failed remediation.
	FailureCount int `json:"failure_count"`
	// Projects contains the remediation result for each project.
	Projects []ProjectRemediationResult `json:"projects"`
	// Error contains any top-level error message.
	Error string `json:"error,omitempty"`
}

RemediationResult is the API response for POST /api/drift/remediate.

func NewRemediationResult added in v0.45.0

func NewRemediationResult(id, repository, ref string, action RemediationAction) *RemediationResult

NewRemediationResult creates a new RemediationResult with initial values.

func (*RemediationResult) AddProjectResult added in v0.45.0

func (r *RemediationResult) AddProjectResult(result ProjectRemediationResult)

AddProjectResult adds a project remediation result.

func (*RemediationResult) Complete added in v0.45.0

func (r *RemediationResult) Complete()

Complete marks the remediation as complete and calculates final status.

type RemediationStatus added in v0.45.0

type RemediationStatus string

RemediationStatus represents the current status of a remediation.

const (
	// RemediationStatusPending indicates remediation is queued.
	RemediationStatusPending RemediationStatus = "pending"
	// RemediationStatusRunning indicates remediation is in progress.
	RemediationStatusRunning RemediationStatus = "running"
	// RemediationStatusSuccess indicates remediation completed successfully.
	RemediationStatusSuccess RemediationStatus = "success"
	// RemediationStatusFailed indicates remediation failed.
	RemediationStatusFailed RemediationStatus = "failed"
	// RemediationStatusPartial indicates some projects succeeded, some failed.
	RemediationStatusPartial RemediationStatus = "partial"
)

func (RemediationStatus) IsTerminal added in v0.45.0

func (s RemediationStatus) IsTerminal() bool

IsTerminal returns true if the status represents a final state.

type Repo

type Repo struct {
	// FullName is the owner and repo name separated
	// by a "/", ex. "runatlantis/atlantis", "gitlab/subgroup/atlantis",
	// "Bitbucket Server/atlantis", "azuredevops/project/atlantis".
	FullName string
	// Owner is just the repo owner, ex. "runatlantis" or "gitlab/subgroup"
	// or azuredevops/project. This may contain /'s in the case of GitLab
	// subgroups or Azure DevOps Team Projects. This may contain spaces in
	// the case of Bitbucket Server.
	Owner string
	// Name is just the repo name, ex. "atlantis". This will never have
	// /'s in it.
	Name string
	// CloneURL is the full HTTPS url for cloning with username and token string
	// ex. "https://username:token@github.com/atlantis/atlantis.git".
	CloneURL string
	// SanitizedCloneURL is the full HTTPS url for cloning with the password
	// redacted.
	// ex. "https://user:<redacted>@github.com/atlantis/atlantis.git".
	SanitizedCloneURL string
	// VCSHost is where this repo is hosted.
	VCSHost VCSHost
}

Repo is a VCS repository.

func NewRepo added in v0.3.2

func NewRepo(vcsHostType VCSHostType, repoFullName string, cloneURL string, vcsUser string, vcsToken string, vcsHostname string) (Repo, error)

NewRepo constructs a Repo object. repoFullName is the owner/repo form, cloneURL can be with or without .git at the end ex. https://github.com/runatlantis/atlantis.git OR

https://github.com/runatlantis/atlantis

vcsHostname is the configured hostname for the VCS (may include a subpath for GitLab, e.g. "acme.com/gitlab"). Pass empty string to skip the enhanced host/subpath validation; non-GitLab callers always pass "".

func (Repo) ID added in v0.7.0

func (r Repo) ID() string

ID returns the atlantis ID for this repo. ID is in the form: {vcs hostname}/{repoFullName}.

type StateRmSuccess added in v0.23.0

type StateRmSuccess struct {
	// Output is the output from terraform state rm
	Output string
	// RePlanCmd is the command that users should run to re-plan this project.
	RePlanCmd string
}

StateRmSuccess is the result of a successful state rm run.

type TeamAllowlistCheckerContext added in v0.30.0

type TeamAllowlistCheckerContext struct {
	// BaseRepo is the repository that the pull request will be merged into.
	BaseRepo Repo

	// The name of the command that is being executed, i.e. 'plan', 'apply' etc.
	CommandName string

	// EscapedCommentArgs are the extra arguments that were added to the atlantis
	// command, ex. atlantis plan -- -target=resource. We then escape them
	// by adding a \ before each character so that they can be used within
	// sh -c safely, i.e. sh -c "terraform plan $(touch bad)".
	EscapedCommentArgs []string

	// HeadRepo is the repository that is getting merged into the BaseRepo.
	// If the pull request branch is from the same repository then HeadRepo will
	// be the same as BaseRepo.
	HeadRepo Repo

	// Log is a logger that's been set up for this context.
	Log logging.SimpleLogging

	// Pull is the pull request we're responding to.
	Pull PullRequest

	// ProjectName is the name of the project set in atlantis.yaml. If there was
	// no name this will be an empty string.
	ProjectName string

	// RepoDir is the absolute path to the repo root
	RepoDir string

	// RepoRelDir is the directory of this project relative to the repo root.
	RepoRelDir string

	// User is the user that triggered this command.
	User User

	// Verbose is true when the user would like verbose output.
	Verbose bool

	// Workspace is the Terraform workspace this project is in. It will always
	// be set.
	Workspace string

	// API is true if plan/apply by API endpoints
	API bool
}

TeamAllowlistCheckerContext defines the context for a TeamAllowlistChecker to verify command permissions.

type User

type User struct {
	Username string
	Teams    []string
}

User is a VCS user. During an autoplan, the user will be the Atlantis API user.

type VCSHost added in v0.3.6

type VCSHost struct {
	// Hostname is the hostname of the VCS provider, ex. "github.com" or
	// "github-enterprise.example.com".
	Hostname string

	// Type is which type of VCS host this is, ex. GitHub or GitLab.
	Type VCSHostType
}

VCSHost is a Git hosting provider, for example GitHub.

type VCSHostType added in v0.3.6

type VCSHostType int
const (
	Github VCSHostType = iota
	Gitlab
	BitbucketCloud
	BitbucketServer
	AzureDevops
	Gitea
)

func NewVCSHostType added in v0.19.8

func NewVCSHostType(t string) (VCSHostType, error)

func (VCSHostType) String added in v0.3.6

func (h VCSHostType) String() string

type VersionSuccess added in v0.17.3

type VersionSuccess struct {
	VersionOutput string
}

type WorkflowHookCommandContext added in v0.18.2

type WorkflowHookCommandContext struct {
	// BaseRepo is the repository that the pull request will be merged into.
	BaseRepo Repo
	// The name of the command that is being executed, i.e. 'plan', 'apply' etc.
	CommandName string
	// Set true if there were any errors during the command execution
	CommandHasErrors bool
	// EscapedCommentArgs are the extra arguments that were added to the atlantis
	// command, ex. atlantis plan -- -target=resource. We then escape them
	// by adding a \ before each character so that they can be used within
	// sh -c safely, i.e. sh -c "terraform plan $(touch bad)".
	EscapedCommentArgs []string
	// HeadRepo is the repository that is getting merged into the BaseRepo.
	// If the pull request branch is from the same repository then HeadRepo will
	// be the same as BaseRepo.
	HeadRepo Repo
	// HookDescription is a description of the hook that is being executed.
	HookDescription string
	// UUID for reference
	HookID string
	// HookStepName is the name of the step that is being executed.
	HookStepName string
	// Log is a logger that's been set up for this context.
	Log logging.SimpleLogging
	// Pull is the pull request we're responding to.
	Pull PullRequest
	// ProjectName is the name of the project set in atlantis.yaml. If there was
	// no name this will be an empty string.
	ProjectName string
	// SuppressJobOutput prevents hook output from being published to the public
	// job stream for API workflows such as drift detection.
	SuppressJobOutput bool
	// RepoRelDir is the directory of this project relative to the repo root.
	RepoRelDir string
	// User is the user that triggered this command.
	User User
	// Verbose is true when the user would like verbose output.
	Verbose bool
	// Workspace is the Terraform workspace this project is in. It will always
	// be set.
	Workspace string
	// API is true if plan/apply by API endpoints
	API bool
}

WorkflowHookCommandContext defines the context for a pre and post workflow_hooks that will be executed before workflows.

Jump to

Keyboard shortcuts

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