Documentation
¶
Overview ¶
Package workspace provides access to terraform workspaces
Index ¶
- Constants
- Variables
- func NewService(opts Options) *service
- type Client
- func (c *Client) GetWorkspace(ctx context.Context, workspaceID string) (*Workspace, error)
- func (c *Client) GetWorkspaceByName(ctx context.Context, organization, workspace string) (*Workspace, error)
- func (c *Client) ListWorkspaces(ctx context.Context, options ListOptions) (*WorkspaceList, error)
- func (c *Client) LockWorkspace(ctx context.Context, workspaceID string, runID *string) (*Workspace, error)
- func (c *Client) UnlockWorkspace(ctx context.Context, workspaceID string, runID *string, force bool) (*Workspace, error)
- func (c *Client) UpdateWorkspace(ctx context.Context, workspaceID string, options UpdateOptions) (*Workspace, error)
- type ConnectOptions
- type CreateOptions
- type ExecutionMode
- type ListOptions
- type Lock
- type LockService
- type LockedState
- type Options
- type OrganizationService
- type PermissionsService
- type QualifiedName
- type RunLock
- type Service
- type UpdateOptions
- type UserLock
- type VCSProviderService
- type Workspace
- type WorkspaceList
- type WorkspaceService
Constants ¶
const ( RemoteExecutionMode ExecutionMode = "remote" LocalExecutionMode ExecutionMode = "local" AgentExecutionMode ExecutionMode = "agent" DefaultAllowDestroyPlan = true DefaultFileTriggersEnabled = true MinTerraformVersion = "1.2.0" DefaultTerraformVersion = "1.3.7" )
Variables ¶
var ( EventLocked otf.EventType = "workspace_locked" EventUnlocked otf.EventType = "workspace_unlocked" )
var ( ErrWorkspaceAlreadyLocked = errors.New("workspace already locked") ErrWorkspaceLockedByDifferentUser = errors.New("workspace locked by different user") ErrWorkspaceAlreadyUnlocked = errors.New("workspace already unlocked") ErrWorkspaceUnlockDenied = errors.New("unauthorized to unlock workspace") ErrWorkspaceInvalidLock = errors.New("invalid workspace lock") ErrUnsupportedTerraformVersion = fmt.Errorf("only terraform versions >= %s are supported", MinTerraformVersion) )
Functions ¶
func NewService ¶ added in v0.0.32
func NewService(opts Options) *service
Types ¶
type Client ¶ added in v0.0.32
type Client struct {
otf.JSONAPIClient
}
func (*Client) GetWorkspace ¶ added in v0.0.32
GetWorkspace retrieves a workspace by its ID
func (*Client) GetWorkspaceByName ¶ added in v0.0.32
func (c *Client) GetWorkspaceByName(ctx context.Context, organization, workspace string) (*Workspace, error)
GetWorkspaceByName retrieves a workspace by organization and name.
func (*Client) ListWorkspaces ¶ added in v0.0.32
func (c *Client) ListWorkspaces(ctx context.Context, options ListOptions) (*WorkspaceList, error)
func (*Client) LockWorkspace ¶ added in v0.0.32
func (*Client) UnlockWorkspace ¶ added in v0.0.32
func (*Client) UpdateWorkspace ¶ added in v0.0.32
func (c *Client) UpdateWorkspace(ctx context.Context, workspaceID string, options UpdateOptions) (*Workspace, error)
UpdateWorkspace updates the settings of an existing workspace.
type ConnectOptions ¶ added in v0.0.32
type CreateOptions ¶ added in v0.0.32
type CreateOptions struct {
AllowDestroyPlan *bool
AutoApply *bool
Branch *string
Description *string
ExecutionMode *ExecutionMode
FileTriggersEnabled *bool
GlobalRemoteState *bool
MigrationEnvironment *string
Name *string `schema:"name,required"`
QueueAllRuns *bool
SpeculativeEnabled *bool
SourceName *string
SourceURL *string
StructuredRunOutputEnabled *bool
TerraformVersion *string
TriggerPrefixes []string
WorkingDirectory *string
Organization *string `schema:"organization_name,required"`
*ConnectOptions
}
CreateOptions represents the options for creating a new workspace.
type ExecutionMode ¶ added in v0.0.32
type ExecutionMode string
func ExecutionModePtr ¶ added in v0.0.32
func ExecutionModePtr(m ExecutionMode) *ExecutionMode
ExecutionModePtr returns a pointer to an execution mode.
type ListOptions ¶ added in v0.0.32
type ListOptions struct {
otf.ListOptions // Pagination
Prefix string `schema:"search[name],omitempty"`
Organization *string `schema:"organization_name,required"`
}
ListOptions are options for paginating and filtering a list of Workspaces
type Lock ¶ added in v0.0.32
type Lock struct {
LockedState // nil means unlocked
}
Lock is a workspace lock, which blocks runs from running and prevents state from being uploaded.
https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings#locking
func (*Lock) Lock ¶ added in v0.0.32
func (l *Lock) Lock(state LockedState) error
Lock transfers a workspace into the given locked state
type LockService ¶ added in v0.0.32
type LockedState ¶ added in v0.0.32
type LockedState interface {
// CanLock checks whether it can be replaced with the given locked state
CanLock(lock LockedState) error
// CanUnlock checks whether subject is permitted to transfer it into the,
// unlocked state, forceably or not.
CanUnlock(lock LockedState, force bool) error
}
LockedState is the workspace lock in a locked state, revealing who/what has locked it and whether it can be locked/unlocked.
func GetLockedState ¶ added in v0.0.32
func GetLockedState(subject otf.Subject, runID *string) (LockedState, error)
type Options ¶ added in v0.0.32
type Options struct {
otf.DB
pubsub.Broker
otf.Renderer
organization.OrganizationService
vcsprovider.VCSProviderService
repo.RepoService
auth.TeamService
logr.Logger
}
type OrganizationService ¶ added in v0.0.32
type OrganizationService organization.Service
type PermissionsService ¶ added in v0.0.32
type QualifiedName ¶ added in v0.0.32
QualifiedName is the workspace's fully qualified name including the name of its organization
type RunLock ¶ added in v0.0.32
type RunLock struct {
ID string
}
RunLock is a workspace lock held by a run
func (RunLock) CanLock ¶ added in v0.0.32
func (RunLock) CanLock(lock LockedState) error
type Service ¶ added in v0.0.32
type Service interface {
CreateWorkspace(ctx context.Context, opts CreateOptions) (*Workspace, error)
UpdateWorkspace(ctx context.Context, workspaceID string, opts UpdateOptions) (*Workspace, error)
GetWorkspace(ctx context.Context, workspaceID string) (*Workspace, error)
GetWorkspaceByName(ctx context.Context, organization, workspace string) (*Workspace, error)
GetWorkspaceJSONAPI(ctx context.Context, workspaceID string, r *http.Request) (*jsonapi.Workspace, error)
ListWorkspaces(ctx context.Context, opts ListOptions) (*WorkspaceList, error)
// ListWorkspacesByWebhookID retrieves workspaces by webhook ID.
//
// TODO: rename to ListConnectedWorkspaces
ListWorkspacesByRepoID(ctx context.Context, repoID uuid.UUID) ([]*Workspace, error)
DeleteWorkspace(ctx context.Context, workspaceID string) (*Workspace, error)
SetCurrentRun(ctx context.Context, workspaceID, runID string) (*Workspace, error)
LockService
PermissionsService
// contains filtered or unexported methods
}
type UpdateOptions ¶ added in v0.0.32
type UpdateOptions struct {
AllowDestroyPlan *bool
AutoApply *bool
Name *string
Description *string
ExecutionMode *ExecutionMode `schema:"execution_mode"`
FileTriggersEnabled *bool
GlobalRemoteState *bool
Operations *bool
QueueAllRuns *bool
SpeculativeEnabled *bool
StructuredRunOutputEnabled *bool
TerraformVersion *string `schema:"terraform_version"`
TriggerPrefixes []string
WorkingDirectory *string
}
type UserLock ¶ added in v0.0.32
type UserLock struct {
ID, Username string
}
UserLock is a lock held by a user
func (UserLock) CanLock ¶ added in v0.0.32
func (l UserLock) CanLock(lock LockedState) error
type VCSProviderService ¶ added in v0.0.32
type VCSProviderService vcsprovider.Service
type Workspace ¶ added in v0.0.32
type Workspace struct {
ID string
CreatedAt time.Time
UpdatedAt time.Time
AllowDestroyPlan bool
AutoApply bool
Branch string
CanQueueDestroyPlan bool
Description string
Environment string
ExecutionMode ExecutionMode
FileTriggersEnabled bool
GlobalRemoteState bool
MigrationEnvironment string
Name string
QueueAllRuns bool
SpeculativeEnabled bool
StructuredRunOutputEnabled bool
SourceName string
SourceURL string
TerraformVersion string
TriggerPrefixes []string
WorkingDirectory string
Organization string
LatestRunID *string
Connection *repo.Connection
Permissions []otf.WorkspacePermission
Lock
}
Workspace is a terraform workspace.
func NewWorkspace ¶ added in v0.0.32
func NewWorkspace(opts CreateOptions) (*Workspace, error)
func (*Workspace) ExecutionModes ¶ added in v0.0.32
ExecutionModes returns a list of possible execution modes
func (*Workspace) MarshalLog ¶ added in v0.0.32
func (*Workspace) QualifiedName ¶ added in v0.0.32
func (ws *Workspace) QualifiedName() QualifiedName
QualifiedName returns the workspace's qualified name including the name of its organization
func (*Workspace) Update ¶ added in v0.0.32
func (ws *Workspace) Update(opts UpdateOptions) error
Update updates the workspace with the given options.
type WorkspaceList ¶ added in v0.0.32
type WorkspaceList struct {
*otf.Pagination
Items []*Workspace
}
WorkspaceList is a list of workspaces.
type WorkspaceService ¶ added in v0.0.32
type WorkspaceService = Service