Documentation
¶
Index ¶
- Constants
- Variables
- func FindLockingMR(ctx context.Context, tags []string, thisMR string) string
- 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) SetWorkspaceStream(s WorkspacePublisher)
- 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
- type WorkspacePublisher
- type WorkspaceStream
- type WorkspaceTriggerMsg
- type WorkspaceTriggerWorker
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`
const (
WorkspaceTriggerStreamName = "TFBUDDY_WORKSPACE_TRIGGERS"
)
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 ¶
Types ¶
type ErroredWorkspace ¶
type ProjectConfig ¶
type ProjectConfig struct {
Workspaces []*TFCWorkspace `yaml:"workspaces"`
}
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) SetWorkspaceStream ¶ added in v0.5.0
func (t *TFCTrigger) SetWorkspaceStream(s WorkspacePublisher)
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 so the fan-out path doesn't redo MR-level work in every worker.
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). Used as the JetStream dedup anchor so retriggers
// are not silently dropped within the dedup window.
DeliveryID string
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"`
}
func (*TFCWorkspace) UnmarshalYAML ¶
func (s *TFCWorkspace) UnmarshalYAML(unmarshal func(interface{}) error) error
type Trigger ¶
type Trigger interface {
TriggerTFCEvents(context.Context) (*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
SetWorkspaceStream(WorkspacePublisher)
}
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
}
type WorkspacePublisher ¶ added in v0.5.0
type WorkspacePublisher interface {
Publish(ctx context.Context, msg *WorkspaceTriggerMsg) error
}
type WorkspaceStream ¶ added in v0.5.0
type WorkspaceStream struct {
// contains filtered or unexported fields
}
func NewWorkspaceStream ¶ added in v0.5.0
func NewWorkspaceStream(js nats.JetStreamContext, workspaceStreamReplicas int, dedupWindow time.Duration) (*WorkspaceStream, error)
NewWorkspaceStream provisions the per-workspace fan-out stream. dedupWindow sets the JetStream Duplicates window used in tandem with the Nats-Msg-Id stamped by gongs from WorkspaceTriggerMsg.GetId — without Duplicates set, the per-delivery dedup is silently inert at the server. Operators tune the window via TFBUDDY_JETSTREAM_DEDUP_WINDOW.
func (*WorkspaceStream) HealthCheck ¶ added in v0.5.0
func (s *WorkspaceStream) HealthCheck() error
HealthCheck reports unhealthy when the stream is missing from JetStream, or when it has no consumers (published messages would otherwise pile up undelivered).
func (*WorkspaceStream) Publish ¶ added in v0.5.0
func (s *WorkspaceStream) Publish(ctx context.Context, msg *WorkspaceTriggerMsg) error
func (*WorkspaceStream) QueueSubscribe ¶ added in v0.5.0
func (s *WorkspaceStream) QueueSubscribe(handler func(*WorkspaceTriggerMsg) error) (*nats.Subscription, error)
QueueSubscribe binds workers to a shared queue so each message is delivered to exactly one replica.
type WorkspaceTriggerMsg ¶ added in v0.5.0
type WorkspaceTriggerMsg struct {
Opts TFCTriggerOptions `json:"opts"`
Workspace TFCWorkspace `json:"workspace"`
Carrier propagation.MapCarrier `json:"Carrier"`
// contains filtered or unexported fields
}
func (*WorkspaceTriggerMsg) Context ¶ added in v0.5.0
func (m *WorkspaceTriggerMsg) Context() context.Context
func (*WorkspaceTriggerMsg) DecodeEventData ¶ added in v0.5.0
func (m *WorkspaceTriggerMsg) DecodeEventData(b []byte) error
func (*WorkspaceTriggerMsg) EncodeEventData ¶ added in v0.5.0
func (m *WorkspaceTriggerMsg) EncodeEventData(ctx context.Context) []byte
func (*WorkspaceTriggerMsg) GetId ¶ added in v0.5.0
func (m *WorkspaceTriggerMsg) GetId(ctx context.Context) string
GetId is the JetStream dedup key. When DeliveryID is present (the normal path for GitHub X-GitHub-Delivery / GitLab Idempotency-Key), we compose the key directly from the opaque per-delivery identifier plus workspace identity. The sha256 fallback handles only legacy messages missing the delivery header.
type WorkspaceTriggerWorker ¶ added in v0.5.0
type WorkspaceTriggerWorker struct {
// contains filtered or unexported fields
}
WorkspaceTriggerWorker drains the WorkspaceTriggerStream. Each delivery gets its own AckWait window, which is the durability boundary the fan-out provides. The stream is shared across VCS providers, so the worker routes each message to the matching client by Opts.VcsProvider.
func NewWorkspaceTriggerWorker ¶ added in v0.5.0
func NewWorkspaceTriggerWorker(stream *WorkspaceStream, appCfg config.Config, clients map[string]vcs.GitClient, tfc tfc_api.ApiClient, rs runstream.StreamClient) (*WorkspaceTriggerWorker, error)
func NewWorkspaceTriggerWorkerWithoutSubscription ¶ added in v0.5.0
func NewWorkspaceTriggerWorkerWithoutSubscription(appCfg config.Config, clients map[string]vcs.GitClient, tfc tfc_api.ApiClient, rs runstream.StreamClient) *WorkspaceTriggerWorker
NewWorkspaceTriggerWorkerWithoutSubscription constructs a worker without subscribing. Used by tests that drive HandleMsg directly.
func (*WorkspaceTriggerWorker) HandleMsg ¶ added in v0.5.0
func (w *WorkspaceTriggerWorker) HandleMsg(msg *WorkspaceTriggerMsg) (rerr error)