Documentation
¶
Overview ¶
Package run is responsible for OTF runs, the primary mechanism for executing terraform
templ: version: v0.3.906
Index ¶
- Constants
- Variables
- func CompilePlanReports(planJSON []byte) (resources Report, outputs Report, err error)
- func NewCommand(client *otfapi.Client) *cobra.Command
- func NewScheduler(opts SchedulerOptions) *scheduler
- type CLI
- type Change
- type ChangeAction
- type Chunk
- type Client
- func (c *Client) Get(ctx context.Context, runID resource.TfeID) (*Run, error)
- func (c *Client) GetLockFile(ctx context.Context, runID resource.TfeID) ([]byte, error)
- func (c *Client) GetPlanFile(ctx context.Context, runID resource.TfeID, format PlanFormat) ([]byte, error)
- func (c *Client) ListRuns(ctx context.Context, opts ListOptions) (*resource.Page[*Run], error)
- func (c *Client) PutChunk(ctx context.Context, opts PutChunkOptions) error
- func (c *Client) UploadLockFile(ctx context.Context, runID resource.TfeID, lockfile []byte) error
- func (c *Client) UploadPlanFile(ctx context.Context, runID resource.TfeID, plan []byte, format PlanFormat) error
- type ConfigurationVersionService
- type CreateOptions
- type Event
- type GetChunkOptions
- type ListOptions
- type MetricsCollector
- type Operation
- type Options
- type PeriodReport
- type Phase
- func (p *Phase) Done() bool
- func (p *Phase) ElapsedTime(now time.Time) time.Duration
- func (p *Phase) HasChanges() bool
- func (p *Phase) HasStarted() bool
- func (p *Phase) StartedAt() time.Time
- func (p *Phase) StatusTimestamp(status PhaseStatus) (time.Time, error)
- func (p *Phase) String() string
- func (p *Phase) UpdateStatus(status PhaseStatus)
- type PhaseFinishOptions
- type PhaseStartOptions
- type PhaseStatus
- type PhaseStatusTimestamp
- type PhaseType
- type PhaseWriter
- type PhaseWriterOptions
- type PlanFile
- type PlanFileOptions
- type PlanFormat
- type PostgresHex
- type PutChunkOptions
- type PutChunkService
- type Report
- type Reporter
- type ResourceChange
- type Run
- func (r *Run) Cancel(isUser, force bool) 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) ElapsedTime(now time.Time) time.Duration
- func (r *Run) EnqueueApply() error
- func (r *Run) EnqueuePlan() error
- func (r *Run) Finish(phase PhaseType, opts PhaseFinishOptions) (autoapply bool, err error)
- func (r *Run) ForceCancelAvailableAt() *time.Time
- func (r *Run) ForceCancelable() bool
- func (r *Run) HasChanges() bool
- func (r *Run) HasStarted() bool
- func (r *Run) InProgress() bool
- func (r *Run) PeriodReport(now time.Time) (report PeriodReport)
- func (r *Run) Phase() PhaseType
- func (r *Run) Queued() bool
- func (r *Run) Start() error
- func (r *Run) StartedAt() time.Time
- func (r *Run) StatusTimestamp(status runstatus.Status) (time.Time, error)
- func (r *Run) String() string
- type SchedulerOptions
- type Service
- func (s *Service) AddHandlers(r *mux.Router)
- func (s *Service) AfterCancelRun(hook func(context.Context, *Run) error)
- func (s *Service) AfterEnqueueApply(hook func(context.Context, *Run) error)
- func (s *Service) AfterEnqueuePlan(hook func(context.Context, *Run) error)
- func (s *Service) AfterForceCancelRun(hook func(context.Context, *Run) error)
- func (s *Service) Apply(ctx context.Context, runID resource.TfeID) error
- func (s *Service) Cancel(ctx context.Context, runID resource.TfeID) error
- func (s *Service) Create(ctx context.Context, workspaceID resource.TfeID, opts CreateOptions) (*Run, error)
- func (s *Service) Delete(ctx context.Context, runID resource.TfeID) error
- func (s *Service) Discard(ctx context.Context, runID resource.TfeID) error
- func (s *Service) EnqueuePlan(ctx context.Context, runID resource.TfeID) (run *Run, err error)
- func (s *Service) FinishPhase(ctx context.Context, runID resource.TfeID, phase PhaseType, ...) (*Run, error)
- func (s *Service) ForceCancel(ctx context.Context, runID resource.TfeID) error
- func (s *Service) Get(ctx context.Context, runID resource.TfeID) (*Run, error)
- func (s *Service) GetChunk(ctx context.Context, opts GetChunkOptions) (Chunk, error)
- func (s *Service) GetLockFile(ctx context.Context, runID resource.TfeID) ([]byte, error)
- func (s *Service) GetPlanFile(ctx context.Context, runID resource.TfeID, format PlanFormat) ([]byte, error)
- func (s *Service) List(ctx context.Context, opts ListOptions) (*resource.Page[*Run], error)
- func (f Service) NewRun(ctx context.Context, workspaceID resource.TfeID, opts CreateOptions) (*Run, error)
- func (s *Service) PutChunk(ctx context.Context, opts PutChunkOptions) error
- func (s *Service) StartPhase(ctx context.Context, runID resource.TfeID, phase PhaseType, ...) (*Run, error)
- func (s *Service) Tail(ctx context.Context, opts TailOptions) (<-chan Chunk, error)
- func (s *Service) UploadLockFile(ctx context.Context, runID resource.TfeID, file []byte) error
- func (s *Service) UploadPlanFile(ctx context.Context, runID resource.TfeID, plan []byte, format PlanFormat) error
- func (s *Service) Watch(ctx context.Context) (<-chan pubsub.Event[*Event], func())
- type Spawner
- type StatusPeriod
- type StatusTimestamp
- type TFEApply
- type TFEPhaseStatusTimestamps
- type TFEPlan
- type TFEResourceReport
- type TFERun
- type TFERunActions
- type TFERunCreateOptions
- type TFERunEvent
- type TFERunEventList
- type TFERunList
- type TFERunListOptions
- type TFERunOperation
- type TFERunPermissions
- type TFERunStatusTimestamps
- type TFERunVariable
- type TFEWorkspace
- type TailOptions
- type Timeout
- type VCSProviderService
- type Variable
- type WatchOptions
Constants ¶
const ( STX = 0x02 // marks the beginning of logs for a phase ETX = 0x03 // marks the end of logs for a phase )
const ( PhasePending PhaseStatus = "pending" PhaseQueued PhaseStatus = "queued" PhaseRunning PhaseStatus = "running" PhaseFinished PhaseStatus = "finished" PhaseCanceled PhaseStatus = "canceled" PhaseErrored PhaseStatus = "errored" PhaseUnreachable PhaseStatus = "unreachable" PendingPhase PhaseType = "pending" PlanPhase PhaseType = "plan" ApplyPhase PhaseType = "apply" FinalPhase PhaseType = "final" UnknownPhase PhaseType = "unknown" )
const ( EventLogChunk string = "log_update" EventLogFinished string = "log_finished" )
Variables ¶
var ( ErrRunDiscardNotAllowed = errors.New("run was not paused for confirmation or priority; discard not allowed") ErrRunCancelNotAllowed = errors.New("run was not planning or applying; cancel not allowed") ErrRunForceCancelNotAllowed = errors.New("run was not planning or applying, has not been canceled non-forcefully, or the cool-off period has not yet passed") // ErrPhaseAlreadyStarted = errors.New("phase already started") )
var ( ActiveRun = []runstatus.Status{ runstatus.ApplyQueued, runstatus.Applying, runstatus.Confirmed, runstatus.PlanQueued, runstatus.Planned, runstatus.Planning, } IncompleteRun = append(ActiveRun, runstatus.Pending) )
var ErrInvalidRunStateTransition = errors.New("invalid run state transition")
Functions ¶
func CompilePlanReports ¶ added in v0.0.51
CompilePlanReports compiles reports of planned changes from a JSON representation of a plan file: one report for planned *resources*, and another for planned *outputs*.
func NewScheduler ¶ added in v0.3.10
func NewScheduler(opts SchedulerOptions) *scheduler
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 Chunk ¶ added in v0.3.25
type Chunk struct {
// TODO: this is better set as a monotonic serial rather than a TFE ID.
ID resource.TfeID `json:"chunk_id"` // Uniquely identifies the chunk.
RunID resource.TfeID `json:"run_id"` // ID of run that generated the chunk
Phase PhaseType `json:"phase"` // Phase that generated the chunk
Offset int `json:"_offset"` // Position within logs.
Data PostgresHex `json:"chunk"` // The log data
}
Chunk is a section of logs for a phase.
func (Chunk) Cut ¶ added in v0.3.25
func (c Chunk) Cut(opts GetChunkOptions) Chunk
Cut returns a new, smaller chunk.
func (Chunk) NextOffset ¶ added in v0.3.25
NextOffset returns the offset for the next chunk
type Client ¶
func (*Client) GetLockFile ¶
func (*Client) GetPlanFile ¶
func (*Client) PutChunk ¶ added in v0.3.25
func (c *Client) PutChunk(ctx context.Context, opts PutChunkOptions) error
func (*Client) UploadLockFile ¶
func (*Client) UploadPlanFile ¶
type ConfigurationVersionService ¶
type ConfigurationVersionService configversion.Service
Alias services so they don't conflict when nested together in struct
type CreateOptions ¶ added in v0.1.8
type CreateOptions struct {
IsDestroy *bool
Refresh *bool
RefreshOnly *bool
Message *string
// Specifies the configuration version to use for this run. If the
// configuration version ID is nil, the run will be created using the
// workspace's latest configuration version.
ConfigurationVersionID *resource.TfeID
TargetAddrs []string
ReplaceAddrs []string
AutoApply *bool
Source source.Source
TerraformVersion *string
AllowEmptyApply *bool
// PlanOnly specifies if this is a speculative, plan-only run that
// Terraform cannot apply. Takes precedence over whether the
// configuration version is marked as speculative or not.
PlanOnly *bool
Variables []Variable
// contains filtered or unexported fields
}
CreateOptions represents the options for creating a new run. See api.types.RunCreateOptions for documentation on each field.
type Event ¶ added in v0.3.23
type Event struct {
ID resource.TfeID `json:"run_id"`
CreatedAt time.Time `json:"created_at"`
CancelSignaledAt *time.Time `json:"cancel_signaled_at"`
IsDestroy bool `json:"is_destroy"`
PositionInQueue int `json:"position_in_queue"`
Refresh bool `json:"refresh"`
RefreshOnly bool `json:"refresh_only"`
ReplaceAddrs []string `json:"replace_addrs"`
TargetAddrs []string `json:"target_addrs"`
Status runstatus.Status `json:"status"`
WorkspaceID resource.TfeID `json:"workspace_id"`
ConfigurationVersionID resource.TfeID `json:"configuration_version_id"`
AutoApply bool `json:"auto_apply"`
PlanOnly bool `json:"plan_only"`
CreatedBy *user.Username `json:"created_by"`
Source source.Source `json:"source"`
EngineVersion string `json:"engine_version"`
AllowEmptyApply bool `json:"allow_empty_apply"`
Engine *engine.Engine `json:"engine"`
}
type GetChunkOptions ¶ added in v0.3.25
type ListOptions ¶ added in v0.1.8
type ListOptions struct {
resource.PageOptions
// Filter by workspace ID
WorkspaceID *resource.TfeID `schema:"workspace_id,omitempty"`
// Filter by organization name
Organization *organization.Name `schema:"organization_name,omitempty"`
// Filter by workspace name
WorkspaceName *string `schema:"workspace_name,omitempty"`
// Filter by run statuses (with an implicit OR condition)
Statuses []runstatus.Status `schema:"search[status],omitempty"`
// Filter by plan-only runs
PlanOnly *bool `schema:"-"`
// Filter by sources
Sources []source.Source
// Filter by commit SHA that triggered a run
CommitSHA *string
// Filter by VCS user's username that triggered a run
VCSUsername *string
}
ListOptions are options for paginating and filtering a list of runs
type MetricsCollector ¶ added in v0.3.4
type MetricsCollector struct {
Service *Service
// contains filtered or unexported fields
}
type Options ¶
type Options struct {
Authorizer *authz.Authorizer
VCSEventSubscriber vcs.Subscriber
WorkspaceService *workspace.Service
OrganizationService *organization.Service
ConfigVersionService *configversion.Service
EngineService *engine.Service
VCSProviderService *vcs.Service
TokensService *tokens.Service
UsersService *user.Service
logr.Logger
internal.Cache
*sql.DB
*tfeapi.Responder
*surl.Signer
*sql.Listener
}
type PeriodReport ¶ added in v0.1.17
type PeriodReport struct {
TotalTime time.Duration `json:"total_time"`
Periods []StatusPeriod `json:"periods"`
}
func (PeriodReport) Percentage ¶ added in v0.1.17
func (r PeriodReport) Percentage(i int) float64
type Phase ¶
type Phase struct {
RunID resource.TfeID `json:"run_id"`
Status PhaseStatus `json:"status"`
// Timestamps of when a state transition occured. Ordered earliest
// first.
StatusTimestamps []PhaseStatusTimestamp `json:"status_timestamps"`
PhaseType `json:"phase"`
// report of planned or applied resource changes
ResourceReport *Report `json:"resource_report"`
// report of planned or applied output changes
OutputReport *Report `json:"output_report"`
}
Phase is a section of work performed by a run.
func (*Phase) ElapsedTime ¶ added in v0.1.17
ElapsedTime returns the time taken for the phase to complete its running state. If the run is yet to enter a running state then it returns 0. If the running state is still in progress then it returns the time since entering the running state.
func (*Phase) HasChanges ¶
func (*Phase) HasStarted ¶ added in v0.1.17
func (*Phase) StartedAt ¶ added in v0.1.17
StartedAt returns the time the phase started running, returning zero time if it is yet to start running.
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 bool `json:"errored,omitempty"`
}
PhaseFinishOptions report the status of a phase upon finishing.
type PhaseStartOptions ¶
type PhaseStatus ¶
type PhaseStatus string
func (PhaseStatus) String ¶
func (s PhaseStatus) String() string
type PhaseStatusTimestamp ¶
type PhaseStatusTimestamp struct {
Phase PhaseType
Status PhaseStatus `json:"status"`
Timestamp time.Time `json:"timestamp"`
}
type PhaseWriter ¶ added in v0.3.25
type PhaseWriter struct {
PutChunkService // for uploading logs to server
// contains filtered or unexported fields
}
PhaseWriter writes logs on behalf of a run phase.
func NewPhaseWriter ¶ added in v0.3.25
func NewPhaseWriter(ctx context.Context, opts PhaseWriterOptions) *PhaseWriter
func (*PhaseWriter) Close ¶ added in v0.3.25
func (w *PhaseWriter) Close() error
Close must be called to complete writing job logs
type PhaseWriterOptions ¶ added in v0.3.25
type PhaseWriterOptions struct {
RunID resource.TfeID
Phase PhaseType
Writer PutChunkService
}
type PlanFile ¶
type PlanFile struct {
ResourceChanges []ResourceChange `json:"resource_changes"`
OutputChanges map[string]Change `json:"output_changes"`
}
PlanFile represents the schema of a plan file
type PlanFileOptions ¶
type PlanFileOptions struct {
Format PlanFormat `schema:"format,required"`
}
PlanFileOptions are options for the plan file API
type PlanFormat ¶
type PlanFormat string
type PostgresHex ¶ added in v0.3.25
type PostgresHex []byte
PostgresHex is a hex encoded byte array originating from Postgres.
func (*PostgresHex) UnmarshalJSON ¶ added in v0.3.25
func (h *PostgresHex) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the overly escaped hex encoded byte array.
type PutChunkOptions ¶ added in v0.3.25
type PutChunkService ¶ added in v0.3.25
type PutChunkService interface {
PutChunk(ctx context.Context, opts PutChunkOptions) error
}
type Report ¶ added in v0.0.51
type Report struct {
Additions int `json:"additions"`
Changes int `json:"changes"`
Destructions int `json:"destructions"`
}
Report reports a summary of additions, changes, and deletions of resources in a plan or an apply.
func ParseApplyOutput ¶
func (Report) HasChanges ¶ added in v0.0.51
type Reporter ¶
type Reporter struct {
logr.Logger
*internal.HostnameService
Configs reporterConfigClient
Workspaces reporterWorkspaceClient
VCS reporterVCSClient
Runs reporterRunClient
// Cache most recently set status for each incomplete run to ensure the
// same status is not set more than once on an upstream VCS provider.
// This is important to avoid hitting rate limits on VCS providers, e.g.
// GitHub has a limit of 1000 status updates on a commit:
//
// https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status
//
// Key is the run ID.
Cache map[resource.TfeID]vcs.Status
}
Reporter reports back to VCS providers the current status of VCS-triggered runs.
type ResourceChange ¶
type ResourceChange struct {
Change Change
}
ResourceChange represents a proposed change to a resource in a plan file
type Run ¶
type Run struct {
ID resource.TfeID `jsonapi:"primary,runs"`
CreatedAt time.Time `jsonapi:"attribute" json:"created_at"`
UpdatedAt time.Time `jsonapi:"attribute" json:"updated_at"`
IsDestroy bool `jsonapi:"attribute" json:"is_destroy"`
CancelSignaledAt *time.Time `jsonapi:"attribute" json:"cancel_signaled_at"`
Message string `jsonapi:"attribute" json:"message"`
Organization organization.Name `jsonapi:"attribute" json:"organization"`
Refresh bool `jsonapi:"attribute" json:"refresh"`
RefreshOnly bool `jsonapi:"attribute" json:"refresh_only"`
ReplaceAddrs []string `jsonapi:"attribute" json:"replace_addrs"`
PositionInQueue int `jsonapi:"attribute" json:"position_in_queue"`
TargetAddrs []string `jsonapi:"attribute" json:"target_addrs"`
EngineVersion string `jsonapi:"attribute" json:"engine_version"`
Engine *engine.Engine `jsonapi:"attribute" json:"engine"`
AllowEmptyApply bool `jsonapi:"attribute" json:"allow_empty_apply"`
AutoApply bool `jsonapi:"attribute" json:"auto_apply"`
PlanOnly bool `jsonapi:"attribute" json:"plan_only"`
Source source.Source `jsonapi:"attribute" json:"source"`
SourceIcon templ.Component `json:"-"`
Status runstatus.Status `jsonapi:"attribute" json:"status"`
WorkspaceID resource.TfeID `jsonapi:"attribute" json:"workspace_id"`
ConfigurationVersionID resource.TfeID `jsonapi:"attribute" json:"configuration_version_id"`
ExecutionMode workspace.ExecutionMode `jsonapi:"attribute" json:"execution_mode"`
Variables []Variable `jsonapi:"attribute" json:"variables"`
Plan Phase `jsonapi:"attribute" json:"plan"`
Apply Phase `jsonapi:"attribute" json:"apply"`
// Timestamps of when a state transition occured. Ordered earliest
// first.
StatusTimestamps []StatusTimestamp `jsonapi:"attribute" json:"status_timestamps"`
Latest bool `jsonapi:"attribute" json:"latest"` // is latest run for workspace
// IngressAttributes is non-nil if run was triggered by a VCS event.
IngressAttributes *configversion.IngressAttributes `jsonapi:"attribute" json:"ingress_attributes"`
// Username of user who created the run. This is nil if the run was
// instead triggered by a VCS event.
CreatedBy *user.Username
// OTF doesn't support cost estimation but some go-tfe API tests expect
// a run to enter the RunCostEstimated state, and this boolean
// determines whether to enter that state upon finishing a plan.
CostEstimationEnabled bool
}
Run is a terraform run.
func (*Run) Cancel ¶
Cancel run. Depending upon whether the run is currently in-progress, the run is either immediately canceled and its status updated to reflect that, or CancelSignaledAt is set to the current time to indicate that a cancelation signal should be sent to the process executing the run.
The isUser arg should be set to true if a user is directly instigating the cancelation; otherwise it should be set to false, i.e. the job service has canceled a job and is now canceling the corresponding run.
The force arg when set to true forceably cancels the run. This is only allowed when an attempt has already been made to cancel the run non-forceably. The force arg is only respected when isUser is true.
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) ElapsedTime ¶ added in v0.1.17
ElapsedTime returns the total time the run has taken thus far. If the run has completed, then it is the time taken from entering the pending state (creation) through to completion. Otherwise it is the time since entering the pending state.
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 PhaseType, opts PhaseFinishOptions) (autoapply bool, err error)
Finish updates the run to reflect its plan or apply phase having finished. If a plan phase has finished and an apply should be automatically enqueued then autoapply will be set to true.
func (*Run) ForceCancelAvailableAt ¶
ForceCancelAvailableAt provides the time from which point it is permitted to forceably cancel the run. It only possible to do so when an attempt has previously been made to cancel the run non-forceably and a cool-off period has elapsed.
func (*Run) ForceCancelable ¶ added in v0.2.0
ForceCancelable determines whether run can be forceably cancelled.
func (*Run) HasChanges ¶
func (*Run) HasStarted ¶ added in v0.1.17
HasStarted is used by the running_time.tmpl partial template to determine whether to show the "elapsed time" for a run.
func (*Run) InProgress ¶ added in v0.2.0
func (*Run) PeriodReport ¶ added in v0.1.17
func (r *Run) PeriodReport(now time.Time) (report PeriodReport)
PeriodReport provides a report of the duration in which a run has been in each status thus far. Completed statuses such as completed, errored, etc, are ignored because they are an instant not a period of time.
func (*Run) StatusTimestamp ¶
type SchedulerOptions ¶ added in v0.3.10
type Service ¶
func NewService ¶
func (*Service) AddHandlers ¶ added in v0.2.2
func (*Service) AfterCancelRun ¶ added in v0.2.0
func (*Service) AfterEnqueueApply ¶ added in v0.2.0
func (*Service) AfterEnqueuePlan ¶ added in v0.2.0
func (*Service) AfterForceCancelRun ¶ added in v0.2.0
func (*Service) EnqueuePlan ¶
EnqueuePlan enqueues a plan for the run.
func (*Service) FinishPhase ¶
func (s *Service) FinishPhase(ctx context.Context, runID resource.TfeID, phase PhaseType, opts PhaseFinishOptions) (*Run, error)
FinishPhase finishes a phase. Creates a report of changes before updating the status of the run.
func (*Service) ForceCancel ¶ added in v0.2.2
ForceCancel forcefully cancels a run.
func (*Service) GetLockFile ¶ added in v0.2.2
GetLockFile returns the lock file for the run.
func (*Service) GetPlanFile ¶
func (s *Service) GetPlanFile(ctx context.Context, runID resource.TfeID, format PlanFormat) ([]byte, error)
GetPlanFile returns the plan file for the run.
func (*Service) List ¶ added in v0.2.2
List retrieves multiple runs. Use opts to filter and paginate the list.
func (Service) NewRun ¶ added in v0.2.2
func (f Service) NewRun(ctx context.Context, workspaceID resource.TfeID, opts CreateOptions) (*Run, error)
NewRun constructs a new run using the provided options.
func (*Service) PutChunk ¶ added in v0.3.25
func (s *Service) PutChunk(ctx context.Context, opts PutChunkOptions) error
PutChunk writes a chunk of logs for a run phase
func (*Service) StartPhase ¶
func (s *Service) StartPhase(ctx context.Context, runID resource.TfeID, phase PhaseType, _ PhaseStartOptions) (*Run, error)
StartPhase starts a run phase.
func (*Service) Tail ¶ added in v0.3.25
Tail logs for a phase. Offset specifies the number of bytes into the logs from which to start tailing.
func (*Service) UploadLockFile ¶ added in v0.2.2
UploadLockFile persists the lock file for a run.
func (*Service) UploadPlanFile ¶
func (s *Service) UploadPlanFile(ctx context.Context, runID resource.TfeID, plan []byte, format PlanFormat) error
UploadPlanFile persists a run's plan file. The plan format should be either be binary or json.
type StatusPeriod ¶ added in v0.1.17
type StatusPeriod struct {
Status runstatus.Status `json:"status"`
Period time.Duration `json:"period"`
}
StatusPeriod is the duration over which a run has had a status.
type StatusTimestamp ¶ added in v0.1.8
type TFEApply ¶ added in v0.3.17
type TFEApply struct {
ID resource.TfeID `jsonapi:"primary,applies"`
LogReadURL string `jsonapi:"attribute" json:"log-read-url"`
Status string `jsonapi:"attribute" json:"status"`
StatusTimestamps *TFEPhaseStatusTimestamps `jsonapi:"attribute" json:"status-timestamps"`
TFEResourceReport
}
TFEApply is a terraform apply
type TFEPhaseStatusTimestamps ¶ added in v0.3.17
type TFEPhaseStatusTimestamps struct {
CanceledAt *time.Time `json:"canceled-at,omitempty"`
ErroredAt *time.Time `json:"errored-at,omitempty"`
FinishedAt *time.Time `json:"finished-at,omitempty"`
PendingAt *time.Time `json:"pending-at,omitempty"`
QueuedAt *time.Time `json:"queued-at,omitempty"`
StartedAt *time.Time `json:"started-at,omitempty"`
UnreachableAt *time.Time `json:"unreachable-at,omitempty"`
}
TFEPhaseStatusTimestamps holds the timestamps for individual statuses for a phase.
type TFEPlan ¶ added in v0.3.17
type TFEPlan struct {
ID resource.TfeID `jsonapi:"primary,plans"`
HasChanges bool `jsonapi:"attribute" json:"has-changes"`
LogReadURL string `jsonapi:"attribute" json:"log-read-url"`
Status string `jsonapi:"attribute" json:"status"`
StatusTimestamps *TFEPhaseStatusTimestamps `jsonapi:"attribute" json:"status-timestamps"`
TFEResourceReport
}
TFEPlan represents a Terraform Enterprise plan.
type TFEResourceReport ¶ added in v0.3.17
type TFERun ¶ added in v0.3.17
type TFERun struct {
ID resource.TfeID `jsonapi:"primary,runs"`
Actions *TFERunActions `jsonapi:"attribute" json:"actions"`
AllowEmptyApply bool `jsonapi:"attribute" json:"allow-empty-apply"`
AutoApply bool `jsonapi:"attribute" json:"auto-apply"`
CreatedAt time.Time `jsonapi:"attribute" json:"created-at"`
ForceCancelAvailableAt *time.Time `jsonapi:"attribute" json:"force-cancel-available-at"`
ExecutionMode string `jsonapi:"attribute" json:"execution-mode"`
HasChanges bool `jsonapi:"attribute" json:"has-changes"`
IsDestroy bool `jsonapi:"attribute" json:"is-destroy"`
Message string `jsonapi:"attribute" json:"message"`
Permissions *TFERunPermissions `jsonapi:"attribute" json:"permissions"`
PlanOnly bool `jsonapi:"attribute" json:"plan-only"`
PositionInQueue int `jsonapi:"attribute" json:"position-in-queue"`
Refresh bool `jsonapi:"attribute" json:"refresh"`
RefreshOnly bool `jsonapi:"attribute" json:"refresh-only"`
ReplaceAddrs []string `jsonapi:"attribute" json:"replace-addrs,omitempty"`
Source string `jsonapi:"attribute" json:"source"`
Status string `jsonapi:"attribute" json:"status"`
StatusTimestamps *TFERunStatusTimestamps `jsonapi:"attribute" json:"status-timestamps"`
TargetAddrs []string `jsonapi:"attribute" json:"target-addrs,omitempty"`
TerraformVersion string `jsonapi:"attribute" json:"terraform-version"`
Variables []TFERunVariable `jsonapi:"attribute" json:"variables"`
// Relations
Apply *TFEApply `jsonapi:"relationship" json:"apply"`
ConfigurationVersion *configversion.TFEConfigurationVersion `jsonapi:"relationship" json:"configuration-version"`
CostEstimate *types.CostEstimate `jsonapi:"relationship" json:"cost-estimate"`
CreatedBy *user.TFEUser `jsonapi:"relationship" json:"created-by"`
Plan *TFEPlan `jsonapi:"relationship" json:"plan"`
Workspace *TFEWorkspace `jsonapi:"relationship" json:"workspace"`
}
TFERun is a terraform run.
type TFERunActions ¶ added in v0.3.17
type TFERunActions struct {
IsCancelable bool `json:"is-cancelable"`
IsConfirmable bool `json:"is-confirmable"`
IsDiscardable bool `json:"is-discardable"`
IsForceCancelable bool `json:"is-force-cancelable"`
}
TFERunActions represents the run actions.
type TFERunCreateOptions ¶ added in v0.3.17
type TFERunCreateOptions struct {
// Type is a public field utilized by JSON:API to set the resource type via
// the field tag. It is not a user-defined value and does not need to be
// set. https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,runs"`
// AllowEmptyApply specifies whether Terraform can apply the run even when the plan contains no changes.
// Often used to upgrade state after upgrading a workspace to a new terraform version.
AllowEmptyApply *bool `jsonapi:"attribute" json:"allow-empty-apply,omitempty"`
// TerraformVersion specifies the Terraform version to use in this run.
// Only valid for plan-only runs; must be a valid Terraform version available to the organization.
TerraformVersion *string `jsonapi:"attribute" json:"terraform-version,omitempty"`
// PlanOnly specifies if this is a speculative, plan-only run that Terraform cannot apply.
PlanOnly *bool `jsonapi:"attribute" json:"plan-only,omitempty"`
// Specifies if this plan is a destroy plan, which will destroy all
// provisioned resources.
IsDestroy *bool `jsonapi:"attribute" json:"is-destroy,omitempty"`
// Refresh determines if the run should
// update the state prior to checking for differences
Refresh *bool `jsonapi:"attribute" json:"refresh,omitempty"`
// RefreshOnly determines whether the run should ignore config changes
// and refresh the state only
RefreshOnly *bool `jsonapi:"attribute" json:"refresh-only,omitempty"`
// Specifies the message to be associated with this run.
Message *string `jsonapi:"attribute" json:"message,omitempty"`
// Specifies the configuration version to use for this run. If the
// configuration version object is omitted, the run will be created using the
// workspace's latest configuration version.
ConfigurationVersion *configversion.TFEConfigurationVersion `jsonapi:"relationship" json:"configuration-version"`
// Specifies the workspace where the run will be executed.
Workspace *workspace.TFEWorkspace `jsonapi:"relationship" json:"workspace"`
// If non-empty, requests that Terraform should create a plan including
// actions only for the given objects (specified using resource address
// syntax) and the objects they depend on.
//
// This capability is provided for exceptional circumstances only, such as
// recovering from mistakes or working around existing Terraform
// limitations. Terraform will generally mention the -target command line
// option in its error messages describing situations where setting this
// argument may be appropriate. This argument should not be used as part
// of routine workflow and Terraform will emit warnings reminding about
// this whenever this property is set.
TargetAddrs []string `jsonapi:"attribute" json:"target-addrs,omitempty"`
// If non-empty, requests that Terraform create a plan that replaces
// (destroys and then re-creates) the objects specified by the given
// resource addresses.
ReplaceAddrs []string `jsonapi:"attribute" json:"replace-addrs,omitempty"`
// AutoApply determines if the run should be applied automatically without
// user confirmation. It defaults to the Workspace.AutoApply setting.
AutoApply *bool `jsonapi:"attribute" json:"auto-apply,omitempty"`
// Variables allows you to specify terraform input variables for
// a particular run, prioritized over variables defined on the workspace.
Variables []*TFERunVariable `jsonapi:"attribute" json:"variables,omitempty"`
}
TFERunCreateOptions represents the options for creating a new run.
type TFERunEvent ¶ added in v0.3.17
type TFERunEvent struct {
ID resource.TfeID `jsonapi:"primary,run-events"`
Action string `jsonapi:"attr,action"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Description string `jsonapi:"attr,description"`
// Relations - Note that `target` is not supported yet
Actor *user.TFEUser `jsonapi:"relation,actor"`
}
TFERunEvent represents a Terraform Enterprise run event.
type TFERunEventList ¶ added in v0.3.17
type TFERunEventList struct {
// Pagination is not supported by the API
*types.Pagination
Items []*TFERunEvent
}
TFERunEventList represents a list of run events.
type TFERunList ¶ added in v0.3.17
type TFERunList struct {
*types.Pagination
Items []*Run
}
TFERunList represents a list of runs.
type TFERunListOptions ¶ added in v0.3.17
type TFERunListOptions struct {
types.ListOptions
Organization *organization.Name `schema:"organization_name,omitempty"`
WorkspaceID *resource.TfeID `schema:"workspace_id,omitempty"`
// Optional: Searches runs that matches the supplied VCS username.
User *string `schema:"search[user],omitempty"`
// Optional: Searches runs that matches the supplied commit sha.
Commit *string `schema:"search[commit],omitempty"`
// Optional: Searches runs that matches the supplied VCS username, commit sha, run_id, and run message.
// The presence of search[commit] or search[user] takes priority over this parameter and will be omitted.
Search string `schema:"search[basic],omitempty"`
// Optional: Comma-separated list of acceptable run statuses.
// Options are listed at https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run#run-states,
// or as constants with the RunStatus string type.
Status string `schema:"filter[status],omitempty"`
// Optional: Comma-separated list of acceptable run sources.
// Options are listed at https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run#run-sources,
// or as constants with the RunSource string type.
Source string `schema:"filter[source],omitempty"`
// Optional: Comma-separated list of acceptable run operation types.
// Options are listed at https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run#run-operations,
// or as constants with the RunOperation string type.
Operation string `schema:"filter[operation],omitempty"`
// Optional: A list of relations to include. See available resources:
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run#available-related-resources
Include []string `schema:"include,omitempty"`
}
TFERunListOptions represents the options for listing runs.
type TFERunOperation ¶ added in v0.3.17
type TFERunOperation string
TFERunOperation represents an operation type of run.
const ( RunOperationPlanApply TFERunOperation = "plan_and_apply" RunOperationPlanOnly TFERunOperation = "plan_only" RunOperationRefreshOnly TFERunOperation = "refresh_only" RunOperationDestroy TFERunOperation = "destroy" RunOperationEmptyApply TFERunOperation = "empty_apply" // **Note: This operation type is still in BETA and subject to change.** RunOperationSavePlan TFERunOperation = "save_plan" )
List all available run operations.
type TFERunPermissions ¶ added in v0.3.17
type TFERunPermissions struct {
CanApply bool `json:"can-apply"`
CanCancel bool `json:"can-cancel"`
CanDiscard bool `json:"can-discard"`
CanForceCancel bool `json:"can-force-cancel"`
CanForceExecute bool `json:"can-force-execute"`
}
TFERunPermissions represents the run permissions.
type TFERunStatusTimestamps ¶ added in v0.3.17
type TFERunStatusTimestamps struct {
AppliedAt *time.Time `json:"applied-at,omitempty"`
ApplyQueuedAt *time.Time `json:"apply-queued-at,omitempty"`
ApplyingAt *time.Time `json:"applying-at,omitempty"`
CanceledAt *time.Time `json:"canceled-at,omitempty"`
ConfirmedAt *time.Time `json:"confirmed-at,omitempty"`
CostEstimatedAt *time.Time `json:"cost-estimated-at,omitempty"`
CostEstimatingAt *time.Time `json:"cost-estimating-at,omitempty"`
DiscardedAt *time.Time `json:"discarded-at,omitempty"`
ErroredAt *time.Time `json:"errored-at,omitempty"`
ForceCanceledAt *time.Time `json:"force-canceled-at,omitempty"`
PlanQueueableAt *time.Time `json:"plan-queueable-at,omitempty"`
PlanQueuedAt *time.Time `json:"plan-queued-at,omitempty"`
PlannedAndFinishedAt *time.Time `json:"planned-and-finished-at,omitempty"`
PlannedAt *time.Time `json:"planned-at,omitempty"`
PlanningAt *time.Time `json:"planning-at,omitempty"`
PolicyCheckedAt *time.Time `json:"policy-checked-at,omitempty"`
PolicySoftFailedAt *time.Time `json:"policy-soft-failed-at,omitempty"`
}
TFERunStatusTimestamps holds the timestamps for individual run statuses.
type TFERunVariable ¶ added in v0.3.17
TFERunVariable represents a variable that can be applied to a run. All values must be expressed as an HCL literal in the same syntax you would use when writing terraform code. See https://developer.hashicorp.com/terraform/language/expressions/types#types for more details.
type TFEWorkspace ¶ added in v0.3.17
type TailOptions ¶ added in v0.3.25
type Timeout ¶ added in v0.3.0
type Timeout struct {
logr.Logger
OverrideCheckInterval time.Duration
PlanningTimeout time.Duration
ApplyingTimeout time.Duration
Runs timeoutRunClient
}
Timeout is a daemon that "times out" runs if one of the phases - planning, applying - exceeds a timeout. This can happen for a number of reasons, for example a terraform plan or apply is stuck talking to an unresponsive API, or if OTF itself has terminated ungracefully and left runs in a planning or applying state.
type VCSProviderService ¶
type WatchOptions ¶
type WatchOptions struct {
Organization *organization.Name `schema:"organization_name,omitempty"` // filter by organization name
WorkspaceID *resource.TfeID `schema:"workspace_id,omitempty"` // filter by workspace ID; mutually exclusive with organization filter
}
WatchOptions filters events returned by the Watch endpoint.