workspace

package
v0.0.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package workspace provides access to terraform workspaces

Index

Constants

View Source
const (
	RemoteExecutionMode ExecutionMode = "remote"
	LocalExecutionMode  ExecutionMode = "local"
	AgentExecutionMode  ExecutionMode = "agent"

	DefaultAllowDestroyPlan    = true
	DefaultFileTriggersEnabled = true

	MinTerraformVersion     = "1.2.0"
	DefaultTerraformVersion = "1.3.7"
)

Variables

View Source
var (
	EventLocked   otf.EventType = "workspace_locked"
	EventUnlocked otf.EventType = "workspace_unlocked"
)
View Source
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

func (c *Client) GetWorkspace(ctx context.Context, workspaceID string) (*Workspace, error)

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 (c *Client) LockWorkspace(ctx context.Context, workspaceID string, runID *string) (*Workspace, error)

func (*Client) UnlockWorkspace added in v0.0.32

func (c *Client) UnlockWorkspace(ctx context.Context, workspaceID string, runID *string, force bool) (*Workspace, error)

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 ConnectOptions struct {
	RepoPath      string `schema:"identifier,required"` // repo id: <owner>/<repo>
	VCSProviderID string `schema:"vcs_provider_id,required"`
}

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

func (*Lock) Locked added in v0.0.32

func (l *Lock) Locked() bool

Locked determines whether lock is locked.

func (*Lock) Unlock added in v0.0.32

func (l *Lock) Unlock(state LockedState, force bool) error

Unlock the lock.

type LockService added in v0.0.32

type LockService interface {
	LockWorkspace(ctx context.Context, workspaceID string, runID *string) (*Workspace, error)
	UnlockWorkspace(ctx context.Context, workspaceID string, runID *string, force bool) (*Workspace, error)
}

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 OrganizationService added in v0.0.32

type OrganizationService organization.Service

type PermissionsService added in v0.0.32

type PermissionsService interface {
	GetPolicy(ctx context.Context, workspaceID string) (otf.WorkspacePolicy, error)

	SetPermission(ctx context.Context, workspaceID, team string, role rbac.Role) error
	UnsetPermission(ctx context.Context, workspaceID, team string) error
}

type QualifiedName added in v0.0.32

type QualifiedName struct {
	Organization string
	Name         string
}

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

func (RunLock) CanUnlock added in v0.0.32

func (RunLock) CanUnlock(lock LockedState, force bool) error

func (RunLock) String added in v0.0.32

func (l RunLock) String() string

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

func (UserLock) CanUnlock added in v0.0.32

func (l UserLock) CanUnlock(state LockedState, force bool) error

func (UserLock) String added in v0.0.32

func (l UserLock) String() string

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

func (ws *Workspace) ExecutionModes() []string

ExecutionModes returns a list of possible execution modes

func (*Workspace) MarshalLog added in v0.0.32

func (ws *Workspace) MarshalLog() any

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) String added in v0.0.32

func (ws *Workspace) String() string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL