Documentation
¶
Overview ¶
Package run is responsible for OTF runs, the primary mechanism for executing terraform
Index ¶
- Constants
- Variables
- func NewService(opts Options) *service
- func StartReporter(ctx context.Context, opts ReporterOptions) error
- func StartSpawner(ctx context.Context, opts SpawnerOptions) error
- type Change
- type ChangeAction
- type Client
- func (c *Client) FinishPhase(ctx context.Context, id string, phase otf.PhaseType, opts PhaseFinishOptions) (*Run, error)
- func (c *Client) GetLockFile(ctx context.Context, runID string) ([]byte, error)
- func (c *Client) GetPlanFile(ctx context.Context, runID string, format PlanFormat) ([]byte, error)
- func (c *Client) GetRun(ctx context.Context, runID string) (*Run, error)
- func (c *Client) ListRuns(ctx context.Context, opts RunListOptions) (*RunList, error)
- func (c *Client) StartPhase(ctx context.Context, id string, phase otf.PhaseType, opts PhaseStartOptions) (*Run, error)
- func (c *Client) UploadLockFile(ctx context.Context, runID string, lockfile []byte) error
- func (c *Client) UploadPlanFile(ctx context.Context, runID string, plan []byte, format PlanFormat) error
- func (c *Client) Watch(ctx context.Context, opts WatchOptions) (<-chan otf.Event, error)
- type ConfigurationVersionService
- type JSONAPIMarshaler
- type Options
- type Phase
- type PhaseFinishOptions
- type PhaseStartOptions
- type PhaseStatus
- type PhaseStatusTimestamp
- type PlanFile
- type PlanFormat
- type ReporterOptions
- type ResourceChange
- type ResourceReport
- type Run
- func (r *Run) CanAccessOrganization(action rbac.Action, name string) bool
- func (*Run) CanAccessSite(action rbac.Action) bool
- func (r *Run) CanAccessWorkspace(action rbac.Action, policy *otf.WorkspacePolicy) bool
- func (r *Run) Cancel() (enqueue bool, err error)
- func (r *Run) Cancelable() bool
- func (r *Run) Confirmable() bool
- func (r *Run) Discard() error
- func (r *Run) Discardable() bool
- func (r *Run) Done() bool
- func (r *Run) EnqueueApply() error
- func (r *Run) EnqueuePlan() error
- func (r *Run) Finish(phase otf.PhaseType, opts PhaseFinishOptions) error
- func (r *Run) ForceCancel() error
- func (r *Run) HasApply() bool
- func (r *Run) HasChanges() bool
- func (r *Run) Phase() otf.PhaseType
- func (r *Run) PlanOnly() bool
- func (r *Run) Queued() bool
- func (r *Run) Start(phase otf.PhaseType) error
- func (r *Run) StatusTimestamp(status otf.RunStatus) (time.Time, error)
- type RunCreateOptions
- type RunList
- type RunListOptions
- type RunService
- type RunStatusTimestamp
- type Service
- type SpawnerOptions
- type VCSProviderService
- type WatchOptions
- type WorkspaceService
Constants ¶
const ( PlanFormatBinary = "bin" // plan file in binary format PlanFormatJSON = "json" // plan file in json format )
Variables ¶
var ErrInvalidRunStateTransition = errors.New("invalid run state transition")
var ErrPhaseAlreadyStarted = errors.New("phase already started")
Functions ¶
func NewService ¶
func NewService(opts Options) *service
func StartReporter ¶
func StartReporter(ctx context.Context, opts ReporterOptions) error
StartReporter starts a reporter.
func StartSpawner ¶
func StartSpawner(ctx context.Context, opts SpawnerOptions) error
StartSpawner starts the run spawner.
Types ¶
type Change ¶
type Change struct {
Actions []ChangeAction
}
Change represents the type of change being made
type ChangeAction ¶
type ChangeAction string
const ( CreateAction ChangeAction = "create" UpdateAction ChangeAction = "update" DeleteAction ChangeAction = "delete" )
type Client ¶
type Client struct {
otf.JSONAPIClient
http.Config
}
func (*Client) FinishPhase ¶
func (*Client) GetLockFile ¶
func (*Client) GetPlanFile ¶
func (*Client) StartPhase ¶
func (*Client) UploadLockFile ¶
func (*Client) UploadPlanFile ¶
type ConfigurationVersionService ¶
type ConfigurationVersionService configversion.Service
type JSONAPIMarshaler ¶
type JSONAPIMarshaler struct {
workspace.Service // for retrieving workspace and workspace permissions
// contains filtered or unexported fields
}
JSONAPIMarshaler marshals structs into the json:api encoding
func (*JSONAPIMarshaler) MarshalJSONAPI ¶
MarshalJSONAPI marshals a run into json:api encoded data
type Options ¶
type Options struct {
WorkspaceAuthorizer otf.Authorizer
WorkspaceService
ConfigurationVersionService
VCSProviderService
logr.Logger
otf.Cache
otf.DB
otf.Renderer
otf.Broker
otf.Signer
}
type Phase ¶
type Phase struct {
RunID string
otf.PhaseType
*ResourceReport // report of planned or applied resource changes
Status PhaseStatus // current phase status
StatusTimestamps []PhaseStatusTimestamp
}
Phase is a section of work performed by a run.
func (*Phase) HasChanges ¶
func (*Phase) StatusTimestamp ¶
func (p *Phase) StatusTimestamp(status PhaseStatus) (time.Time, error)
StatusTimestamp looks up the timestamp for a status
func (*Phase) UpdateStatus ¶
func (p *Phase) UpdateStatus(status PhaseStatus)
type PhaseFinishOptions ¶
type PhaseFinishOptions struct {
// Errored is true if the phase finished unsuccessfully.
Errored bool `jsonapi:"attr,errored,omitempty"`
}
PhaseFinishOptions report the status of a phase upon finishing.
type PhaseStartOptions ¶
type PhaseStartOptions struct {
AgentID string `jsonapi:"attr,agent-id,omitempty"`
}
type PhaseStatus ¶
type PhaseStatus string
const ( PhasePending PhaseStatus = "pending" PhaseQueued PhaseStatus = "queued" PhaseRunning PhaseStatus = "running" PhaseFinished PhaseStatus = "finished" PhaseCanceled PhaseStatus = "canceled" PhaseErrored PhaseStatus = "errored" PhaseUnreachable PhaseStatus = "unreachable" )
func (PhaseStatus) String ¶
func (s PhaseStatus) String() string
type PhaseStatusTimestamp ¶
type PhaseStatusTimestamp struct {
Status PhaseStatus
Timestamp time.Time
}
type PlanFile ¶
type PlanFile struct {
ResourceChanges []ResourceChange `json:"resource_changes"`
}
PlanFile represents the schema of a plan file
func (*PlanFile) Changes ¶
func (pf *PlanFile) Changes() (tally ResourceReport)
Changes provides a tally of the types of changes proposed in the plan file.
type PlanFormat ¶
type PlanFormat string
type ReporterOptions ¶
type ReporterOptions struct {
ConfigurationVersionService configversion.Service
WorkspaceService workspace.Service
VCSProviderService VCSProviderService
logr.Logger
otf.DB
otf.Subscriber
otf.HostnameService
}
type ResourceChange ¶
type ResourceChange struct {
Change Change
}
ResourceChange represents a proposed change to a resource in a plan file
type ResourceReport ¶
ResourceReport reports a summary of additions, changes, and deletions of resources in a plan or an apply.
func CompilePlanReport ¶
func CompilePlanReport(planJSON []byte) (ResourceReport, error)
CompilePlanReport compiles a report of planned changes from a JSON representation of a plan file.
func ParseApplyOutput ¶
func ParseApplyOutput(output string) (ResourceReport, error)
func (ResourceReport) HasChanges ¶
func (r ResourceReport) HasChanges() bool
func (ResourceReport) String ¶
func (r ResourceReport) String() string
type Run ¶
type Run struct {
ID string
CreatedAt time.Time
IsDestroy bool
ForceCancelAvailableAt *time.Time
Message string
Organization string
Refresh bool
RefreshOnly bool
ReplaceAddrs []string
PositionInQueue int
TargetAddrs []string
AutoApply bool
Speculative bool
Status otf.RunStatus
StatusTimestamps []RunStatusTimestamp
WorkspaceID string
ConfigurationVersionID string
ExecutionMode workspace.ExecutionMode
Plan Phase
Apply Phase
Latest bool // is latest run for workspace
Commit *string // commit sha that triggered this run
}
Run is a terraform run.
func NewRun ¶
func NewRun(cv *configversion.ConfigurationVersion, ws *workspace.Workspace, opts RunCreateOptions) *Run
NewRun creates a new run with defaults.
func UnmarshalJSONAPI ¶
func (*Run) CanAccessOrganization ¶
func (*Run) CanAccessWorkspace ¶
func (*Run) Cancel ¶
Cancel run. Returns a boolean indicating whether a cancel request should be enqueued (for an agent to kill an in progress process)
func (*Run) Cancelable ¶
Cancelable determines whether run can be cancelled.
func (*Run) Confirmable ¶
Confirmable determines whether run can be confirmed.
func (*Run) Discardable ¶
Discardable determines whether run can be discarded.
func (*Run) Done ¶
Done determines whether run has reached an end state, e.g. applied, discarded, etc.
func (*Run) EnqueueApply ¶
func (*Run) EnqueuePlan ¶
EnqueuePlan enqueues a plan for the run. It also sets the run as the latest run for its workspace (speculative runs are ignored).
func (*Run) Finish ¶
func (r *Run) Finish(phase otf.PhaseType, opts PhaseFinishOptions) error
Finish updates the run to reflect its plan or apply phase having finished.
func (*Run) ForceCancel ¶
ForceCancel force cancels a run. A cool-off period of 10 seconds must have elapsed following a cancelation request before a run can be force canceled.
func (*Run) HasChanges ¶
type RunCreateOptions ¶
type RunCreateOptions struct {
IsDestroy *bool
Refresh *bool
RefreshOnly *bool
Message *string
ConfigurationVersionID *string
TargetAddrs []string
ReplaceAddrs []string
AutoApply *bool
}
RunCreateOptions represents the options for creating a new run. See dto.RunCreateOptions for further detail.
type RunList ¶
type RunList struct {
*otf.Pagination
Items []*Run
}
RunList represents a list of runs.
type RunListOptions ¶
type RunListOptions struct {
otf.ListOptions
// Filter by run statuses (with an implicit OR condition)
Statuses []otf.RunStatus `schema:"statuses,omitempty"`
// Filter by workspace ID
WorkspaceID *string `schema:"workspace_id,omitempty"`
// Filter by organization name
Organization *string `schema:"organization_name,omitempty"`
// Filter by workspace name
WorkspaceName *string `schema:"workspace_name,omitempty"`
// Filter by speculative or non-speculative
Speculative *bool `schema:"-"`
// A list of relations to include. See available resources:
// https://www.terraform.io/docs/cloud/api/run.html#available-related-resources
Include *string `schema:"include,omitempty"`
}
RunListOptions are options for paginating and filtering a list of runs
type RunService ¶
type RunService = Service
Alias services so they don't conflict when nested together in struct
type RunStatusTimestamp ¶
type Service ¶
type Service interface {
CreateRun(ctx context.Context, workspaceID string, opts RunCreateOptions) (*Run, error)
GetRun(ctx context.Context, id string) (*Run, error)
ListRuns(ctx context.Context, opts RunListOptions) (*RunList, error)
EnqueuePlan(ctx context.Context, runID string) (*Run, error)
// StartPhase starts a run phase.
StartPhase(ctx context.Context, runID string, phase otf.PhaseType, _ PhaseStartOptions) (*Run, error)
// FinishPhase finishes a phase. Creates a report of changes before updating the status of
// the run.
FinishPhase(ctx context.Context, runID string, phase otf.PhaseType, opts PhaseFinishOptions) (*Run, error)
// GetPlanFile returns the plan file for the run.
GetPlanFile(ctx context.Context, runID string, format PlanFormat) ([]byte, error)
// UploadPlanFile persists a run's plan file. The plan format should be either
// be binary or json.
UploadPlanFile(ctx context.Context, runID string, plan []byte, format PlanFormat) error
// Watch provides access to a stream of run events. The WatchOptions filters
// events. Context must be cancelled to close stream.
//
// TODO(@leg100): it would be clearer to the caller if the stream is closed by
// returning a stream object with a Close() method. The calling code would
// call Watch(), and then defer a Close(), which is more readable IMO.
Watch(ctx context.Context, opts WatchOptions) (<-chan otf.Event, error)
// Cancel a run. If a run is in progress then a cancelation signal will be
// sent out.
Cancel(ctx context.Context, runID string) (*Run, error)
// Apply enqueues an Apply for the run.
Apply(ctx context.Context, runID string) error
// Delete a run.
Delete(ctx context.Context, runID string) error
otf.Authorizer // run authorizer
// contains filtered or unexported methods
}
type SpawnerOptions ¶
type SpawnerOptions struct {
logr.Logger
otf.Subscriber
ConfigurationVersionService
WorkspaceService
VCSProviderService
RunService
}
type VCSProviderService ¶
type VCSProviderService vcsprovider.Service
type WatchOptions ¶
type WatchOptions struct {
Organization *string `schema:"organization_name,omitempty"` // filter by organization name
WorkspaceID *string `schema:"workspace_id,omitempty"` // filter by workspace ID; mutually exclusive with organization filter
}
WatchOptions filters events returned by the Watch endpoint.