workspace

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 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.4.6"
)

Variables

View Source
var (
	EventLocked   pubsub.EventType = "workspace_locked"
	EventUnlocked pubsub.EventType = "workspace_unlocked"
)
View Source
var ErrInvalidTagSpec = errors.New("invalid tag spec: must provide either an ID or a name")
View Source
var ErrNoVCSConnection = errors.New("workspace is not connected to a vcs repo")

Functions

func NewService

func NewService(opts Options) *service

Types

type Client

type Client struct {
	internal.JSONAPIClient
}

func (*Client) GetWorkspace

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

GetWorkspace retrieves a workspace by its ID

func (*Client) GetWorkspaceByName

func (c *Client) GetWorkspaceByName(ctx context.Context, organization, workspace string) (*Workspace, error)

GetWorkspaceByName retrieves a workspace by organization and name.

func (*Client) ListWorkspaces

func (c *Client) ListWorkspaces(ctx context.Context, options ListOptions) (*WorkspaceList, error)

func (*Client) LockWorkspace

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

func (*Client) UnlockWorkspace

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

func (*Client) UpdateWorkspace

func (c *Client) UpdateWorkspace(ctx context.Context, workspaceID string, options UpdateOptions) (*Workspace, error)

UpdateWorkspace updates the settings of an existing workspace.

type ConnectOptions

type ConnectOptions struct {
	RepoPath      string `schema:"identifier,required"` // repo id: <owner>/<repo>
	VCSProviderID string `schema:"vcs_provider_id,required"`
}

type CreateOptions

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
	Tags                       []TagSpec
	TerraformVersion           *string
	TriggerPrefixes            []string
	WorkingDirectory           *string
	Organization               *string `schema:"organization_name,required"`

	*ConnectOptions
}

CreateOptions represents the options for creating a new workspace.

type ExecutionMode

type ExecutionMode string

func ExecutionModePtr

func ExecutionModePtr(m ExecutionMode) *ExecutionMode

ExecutionModePtr returns a pointer to an execution mode.

type LatestRun

type LatestRun struct {
	ID     string
	Status internal.RunStatus
}

LatestRun is a summary of the latest run for a workspace

type ListOptions

type ListOptions struct {
	internal.ListOptions          // Pagination
	Search               string   `schema:"search[name],omitempty"`
	Tags                 []string `schema:"search[tags],omitempty"`
	Organization         *string  `schema:"organization_name,required"`
}

ListOptions are options for paginating and filtering a list of Workspaces

type ListTagsOptions

type ListTagsOptions struct {
	internal.ListOptions
}

ListTagsOptions are options for paginating and filtering a list of tags

type ListWorkspaceTagsOptions

type ListWorkspaceTagsOptions struct {
	internal.ListOptions
}

ListWorkspaceTagsOptions are options for paginating and filtering a list of workspace tags

type Lock

type Lock struct {
	LockKind // kind of entity holding lock
	// contains filtered or unexported fields
}

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

type LockButton

type LockButton struct {
	State    string // locked or unlocked
	Text     string // button text
	Tooltip  string // button tooltip
	Disabled bool   // button greyed out or not
	Message  string // message accompanying button
	Action   string // form URL
}

type LockKind

type LockKind int

kind of entity holding a lock

const (
	UserLock LockKind = iota
	RunLock
)

type LockService

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 OrganizationService

type OrganizationService organization.Service

type PermissionsService

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

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

type QualifiedName

type QualifiedName struct {
	Organization string
	Name         string
}

QualifiedName is the workspace's fully qualified name including the name of its organization

type Service

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)
	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
	TagService
	// contains filtered or unexported methods
}

type Tag

type Tag struct {
	ID            string // ID of the form 'tag-*'. Globally unique.
	Name          string // Meaningful symbol. Unique to an organization.
	InstanceCount int    // Number of workspaces that have this tag
	Organization  string // Organization this tag belongs to.
}

Tag is a symbol associated with one or more workspaces. Helps searching and grouping workspaces.

type TagList

type TagList struct {
	*internal.Pagination
	Items []*Tag
}

TagList is a list of tags.

type TagService

type TagService interface {
	// ListTags lists tags within an organization
	ListTags(ctx context.Context, organization string, opts ListTagsOptions) (*TagList, error)

	// DeleteTags deletes tags from an organization
	DeleteTags(ctx context.Context, organization string, tagIDs []string) error

	// TagWorkspaces adds an existing tag to a list of workspaces
	TagWorkspaces(ctx context.Context, tagID string, workspaceIDs []string) error

	// AddTags appends tags to a workspace. Any tag specified by ID must
	// exist. Any tag specified by name is created if it does not
	// exist.
	AddTags(ctx context.Context, workspaceID string, tags []TagSpec) error

	// RemoveTags removes tags from a workspace. The workspace must already
	// exist. Any tag specifying an ID must exist. Any tag specifying a name
	// need not exist and no action is taken. If a tag is no longer
	// associated with any workspaces it is removed.
	RemoveTags(ctx context.Context, workspaceID string, tags []TagSpec) error

	// ListWorkspaceTags lists the tags for a workspace.
	ListWorkspaceTags(ctx context.Context, workspaceID string, options ListWorkspaceTagsOptions) (*TagList, error)
	// contains filtered or unexported methods
}

type TagSpec

type TagSpec struct {
	ID   string
	Name string
}

TagSpec specifies a tag. Either ID or Name must be non-nil for it to valid.

func (TagSpec) Valid

func (s TagSpec) Valid() error

type TagSpecs

type TagSpecs []TagSpec

func (TagSpecs) LogValue

func (specs TagSpecs) LogValue() slog.Value

type UpdateOptions

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 VCSProviderService

type VCSProviderService vcsprovider.Service

type Workspace

type Workspace struct {
	ID                         string           `json:"id"`
	CreatedAt                  time.Time        `json:"created_at"`
	UpdatedAt                  time.Time        `json:"updated_at"`
	AllowDestroyPlan           bool             `json:"allow_destroy_plan"`
	AutoApply                  bool             `json:"auto_apply"`
	Branch                     string           `json:"branch"`
	CanQueueDestroyPlan        bool             `json:"can_queue_destroy_plan"`
	Description                string           `json:"description"`
	Environment                string           `json:"environment"`
	ExecutionMode              ExecutionMode    `json:"execution_mode"`
	FileTriggersEnabled        bool             `json:"file_triggers_enabled"`
	GlobalRemoteState          bool             `json:"global_remote_state"`
	MigrationEnvironment       string           `json:"migration_environment"`
	Name                       string           `json:"name"`
	QueueAllRuns               bool             `json:"queue_all_runs"`
	SpeculativeEnabled         bool             `json:"speculative_enabled"`
	StructuredRunOutputEnabled bool             `json:"structured_run_output_enabled"`
	SourceName                 string           `json:"source_name"`
	SourceURL                  string           `json:"source_url"`
	TerraformVersion           string           `json:"terraform_version"`
	TriggerPrefixes            []string         `json:"trigger_prefixes"`
	WorkingDirectory           string           `json:"working_directory"`
	Organization               string           `json:"organization"`
	Connection                 *repo.Connection `json:"connection"`
	LatestRun                  *LatestRun       `json:"latest_run"`
	Tags                       []string         `json:"tags"`
	Lock                       *Lock            `json:"lock"`
}

Workspace is a terraform workspace.

func NewWorkspace

func NewWorkspace(opts CreateOptions) (*Workspace, error)

func (*Workspace) Enlock

func (ws *Workspace) Enlock(id string, kind LockKind) error

Enlock locks the workspace

func (*Workspace) ExecutionModes

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

ExecutionModes returns a list of possible execution modes

func (*Workspace) Locked

func (ws *Workspace) Locked() bool

Locked determines whether workspace is locked.

func (*Workspace) LogValue

func (ws *Workspace) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (*Workspace) QualifiedName

func (ws *Workspace) QualifiedName() QualifiedName

QualifiedName returns the workspace's qualified name including the name of its organization

func (*Workspace) String

func (ws *Workspace) String() string

func (*Workspace) Unlock

func (ws *Workspace) Unlock(id string, kind LockKind, force bool) error

Unlock the workspace.

func (*Workspace) Update

func (ws *Workspace) Update(opts UpdateOptions) error

Update updates the workspace with the given options.

type WorkspaceList

type WorkspaceList struct {
	*internal.Pagination
	Items []*Workspace
}

WorkspaceList is a list of workspaces.

type WorkspacePage

type WorkspacePage struct {
	organization.OrganizationPage

	Workspace *Workspace
}

WorkspacePage contains data shared by all workspace-based pages.

func NewPage

func NewPage(r *http.Request, title string, workspace *Workspace) WorkspacePage

type WorkspaceService

type WorkspaceService = Service

Jump to

Keyboard shortcuts

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