Documentation
¶
Index ¶
- Constants
- Variables
- func FindExternalLock(tags []string) string
- func FindLockingMR(ctx context.Context, tags []string, thisMR string) string
- type DiscoverRule
- type ErroredWorkspace
- type ProjectConfig
- type TFCTrigger
- func (t *TFCTrigger) GetAction() TriggerAction
- func (t *TFCTrigger) GetBranch() string
- func (t *TFCTrigger) GetCommitSHA() string
- func (t *TFCTrigger) GetMergeRequestDiscussionID() string
- func (t *TFCTrigger) GetMergeRequestIID() int
- func (t *TFCTrigger) GetMergeRequestRootNoteID() int64
- func (t *TFCTrigger) GetProjectNameWithNamespace() string
- func (t *TFCTrigger) GetTriggerSource() TriggerSource
- func (t *TFCTrigger) GetVcsProvider() string
- func (t *TFCTrigger) GetWorkspace() string
- func (t *TFCTrigger) LockUnlockWorkspace(ws *tfe.Workspace, mr vcs.DetailedMR, lock bool) error
- func (t *TFCTrigger) SetMergeRequestDiscussionID(mrDiscID string)
- func (t *TFCTrigger) SetMergeRequestRootNoteID(id int64)
- func (t *TFCTrigger) SkipTFCEvents(ctx context.Context, reason string) (*TriggeredTFCWorkspaces, error)
- func (t *TFCTrigger) TriggerCleanupEvent(ctx context.Context) error
- func (t *TFCTrigger) TriggerTFCEvents(ctx context.Context) (*TriggeredTFCWorkspaces, error)
- type TFCTriggerOptions
- type TFCWorkspace
- type Trigger
- type TriggerAction
- type TriggerSource
- type TriggeredTFCWorkspaces
Constants ¶
const MRCommentTargetBranchEvalFailed = ":warning: Could not identify modified workspaces on target branch. Please review the plan carefully for unrelated changes."
MRCommentTargetBranchEvalFailed is the MR-level warning when analysis cannot determine whether the target branch modified workspace-relevant paths.
const ProjectConfigFilename = `.tfbuddy.yaml`
Variables ¶
var ( ErrWorkspaceNotDefined = errors.New("the workspace is not defined in " + ProjectConfigFilename) ErrNoChangesDetected = errors.New("no changes detected for configured Terraform directories") ErrWorkspaceLocked = errors.New("workspace is already locked") ErrWorkspaceUnlocked = errors.New("workspace is already unlocked") )
predefined errors
Functions ¶
func FindExternalLock ¶ added in v0.8.3
FindExternalLock returns the holder of the first external lock in tags: a tfbuddylock-<holder> tag whose holder is not an MR number. TFBuddy never acquires or releases these itself; it only refuses to apply while one exists.
Types ¶
type DiscoverRule ¶ added in v0.8.3
type DiscoverRule struct {
// Dir is a slash-separated path whose segments are either literal names or
// `*`, which matches exactly one directory name.
Dir string `yaml:"dir" validate:"empty=false"`
// Exclude lists doublestar patterns for directories Dir matches that are
// not workspaces.
Exclude []string `yaml:"exclude,omitempty"`
Name string `yaml:"name" validate:"empty=false"`
Organization string `yaml:"organization" validate:"empty=false"`
Mode string `yaml:"mode" default:"apply-before-merge" validate:"one_of=apply-before-merge,merge-before-apply,tfc-vcs-repo"`
TriggerDirs []string `yaml:"triggerDirs,omitempty"`
AutoMerge bool `yaml:"autoMerge" default:"true"`
}
DiscoverRule derives workspaces from the repository's directory layout, so a repo whose workspaces follow a naming convention does not need one entry per workspace. Every directory matching Dir becomes a workspace; {1}, {2}, … in Name and TriggerDirs stand for the directory names Dir's first, second, … `*` matched. For example, with Dir "services/*/*/" the directory "services/api/staging/" fills Name "services-{1}-{2}" as "services-api-staging".
func (*DiscoverRule) UnmarshalYAML ¶ added in v0.8.3
func (r *DiscoverRule) UnmarshalYAML(unmarshal func(interface{}) error) error
type ErroredWorkspace ¶
type ProjectConfig ¶
type ProjectConfig struct {
Workspaces []*TFCWorkspace `yaml:"workspaces"`
// Discover derives further workspaces from the repository's directory
// layout; see DiscoverRule.
Discover []*DiscoverRule `yaml:"discover,omitempty"`
}
type TFCTrigger ¶
type TFCTrigger struct {
// contains filtered or unexported fields
}
func (*TFCTrigger) GetAction ¶ added in v0.1.6
func (t *TFCTrigger) GetAction() TriggerAction
func (*TFCTrigger) GetBranch ¶ added in v0.1.6
func (t *TFCTrigger) GetBranch() string
func (*TFCTrigger) GetCommitSHA ¶ added in v0.1.6
func (t *TFCTrigger) GetCommitSHA() string
func (*TFCTrigger) GetMergeRequestDiscussionID ¶ added in v0.1.6
func (t *TFCTrigger) GetMergeRequestDiscussionID() string
func (*TFCTrigger) GetMergeRequestIID ¶ added in v0.1.6
func (t *TFCTrigger) GetMergeRequestIID() int
func (*TFCTrigger) GetMergeRequestRootNoteID ¶ added in v0.1.6
func (t *TFCTrigger) GetMergeRequestRootNoteID() int64
func (*TFCTrigger) GetProjectNameWithNamespace ¶ added in v0.1.6
func (t *TFCTrigger) GetProjectNameWithNamespace() string
func (*TFCTrigger) GetTriggerSource ¶ added in v0.1.6
func (t *TFCTrigger) GetTriggerSource() TriggerSource
func (*TFCTrigger) GetVcsProvider ¶ added in v0.1.6
func (t *TFCTrigger) GetVcsProvider() string
func (*TFCTrigger) GetWorkspace ¶ added in v0.1.6
func (t *TFCTrigger) GetWorkspace() string
func (*TFCTrigger) LockUnlockWorkspace ¶
func (t *TFCTrigger) LockUnlockWorkspace(ws *tfe.Workspace, mr vcs.DetailedMR, lock bool) error
func (*TFCTrigger) SetMergeRequestDiscussionID ¶ added in v0.1.6
func (t *TFCTrigger) SetMergeRequestDiscussionID(mrDiscID string)
func (*TFCTrigger) SetMergeRequestRootNoteID ¶ added in v0.1.6
func (t *TFCTrigger) SetMergeRequestRootNoteID(id int64)
func (*TFCTrigger) SkipTFCEvents ¶ added in v0.8.4
func (t *TFCTrigger) SkipTFCEvents(ctx context.Context, reason string) (*TriggeredTFCWorkspaces, error)
SkipTFCEvents discovers the same workspaces TriggerTFCEvents would trigger and posts a pending TFC/plan/<ws> and TFC/apply/<ws> commit status for each one, without ever cloning the repository or creating a Terraform Cloud run.
It exists for callers that intentionally decline to plan a commit (e.g. a skip-plan label) but still need every affected workspace to carry a visible, per-workspace status: posting one synthetic status for the whole merge request would let a merge gate that checks per-workspace statuses pass newly-added workspaces straight through, unreviewed.
func (*TFCTrigger) TriggerCleanupEvent ¶
func (t *TFCTrigger) TriggerCleanupEvent(ctx context.Context) error
func (*TFCTrigger) TriggerTFCEvents ¶
func (t *TFCTrigger) TriggerTFCEvents(ctx context.Context) (*TriggeredTFCWorkspaces, error)
TriggerTFCEvents dispatches one run per touched workspace. The clone and target-branch evaluation happen once per delivery, and every workspace is then run from that one checkout.
type TFCTriggerOptions ¶ added in v0.1.6
type TFCTriggerOptions struct {
Action TriggerAction
Branch string
CommitSHA string
ProjectNameWithNamespace string
MergeRequestIID int
MergeRequestDiscussionID string
MergeRequestRootNoteID int64
TriggerSource TriggerSource
VcsProvider string
// DeliveryID is the upstream webhook delivery ID (X-GitHub-Delivery /
// X-Gitlab-Event-UUID). It identifies the trigger for the workspace
// dispatch claim and the auto-merge apply generation, so a redelivery of
// the same webhook is recognised while a new push or comment is not.
DeliveryID string
// AutoMergeGeneration groups every workspace run dispatched by one apply command.
AutoMergeGeneration string
// AutoMergeSequence is the monotonically increasing GitLab note ID.
AutoMergeSequence int64
Workspace string `short:"w" long:"workspace" description:"A specific terraform Workspace to use" required:"false"`
TFVersion string `short:"v" long:"tf_version" description:"A specific terraform version to use" required:"false"`
Target string `short:"t" long:"target" description:"A specific terraform target to use" required:"false"`
AllowEmptyRun bool `short:"e" long:"allow_empty_run" description:"A specific terraform AllowEmptyRun" required:"false"`
}
func NewTFCTriggerConfig ¶ added in v0.1.6
func NewTFCTriggerConfig(opts *TFCTriggerOptions) (*TFCTriggerOptions, error)
type TFCWorkspace ¶
type TFCWorkspace struct {
Name string `yaml:"name" validate:"empty=false"`
Organization string `yaml:"organization" validate:"empty=false"`
Dir string `yaml:"dir"`
Mode string `yaml:"mode" default:"apply-before-merge" validate:"one_of=apply-before-merge,merge-before-apply,tfc-vcs-repo"`
TriggerDirs []string `yaml:"triggerDirs"`
AutoMerge bool `yaml:"autoMerge" default:"true"`
// Discovered marks a workspace derived by a DiscoverRule rather than
// listed in the config file. It cannot be set from YAML.
Discovered bool `yaml:"-"`
}
func (*TFCWorkspace) UnmarshalYAML ¶
func (s *TFCWorkspace) UnmarshalYAML(unmarshal func(interface{}) error) error
type Trigger ¶
type Trigger interface {
TriggerTFCEvents(context.Context) (*TriggeredTFCWorkspaces, error)
SkipTFCEvents(ctx context.Context, reason string) (*TriggeredTFCWorkspaces, error)
TriggerCleanupEvent(context.Context) error
GetAction() TriggerAction
GetBranch() string
GetCommitSHA() string
GetProjectNameWithNamespace() string
GetMergeRequestIID() int
GetMergeRequestDiscussionID() string
SetMergeRequestDiscussionID(mrdisID string)
GetMergeRequestRootNoteID() int64
SetMergeRequestRootNoteID(id int64)
GetTriggerSource() TriggerSource
GetWorkspace() string
GetVcsProvider() string
}
func NewTFCTrigger ¶
func NewTFCTrigger( appCfg config.Config, gl vcs.GitClient, tfc tfc_api.ApiClient, runstream runstream.StreamClient, cfg *TFCTriggerOptions, ) Trigger
type TriggerAction ¶
type TriggerAction int
const ( ApplyAction TriggerAction = iota DestroyAction LockAction PlanAction RefreshAction UnlockAction InvalidAction )
func CheckTriggerAction ¶ added in v0.1.6
func CheckTriggerAction(action string) TriggerAction
func (TriggerAction) String ¶
func (a TriggerAction) String() string
type TriggerSource ¶
type TriggerSource int
const ( CommentTrigger TriggerSource = iota MergeRequestEventTrigger )
type TriggeredTFCWorkspaces ¶
type TriggeredTFCWorkspaces struct {
Errored []*ErroredWorkspace
Executed []string
}