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) (*resource.Page[*Workspace], 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 Connection
- type CreateOptions
- type ExecutionMode
- type LatestRun
- type ListOptions
- type ListTagsOptions
- type ListWorkspaceTagsOptions
- type Lock
- type LockButton
- type LockKind
- type LockService
- type Options
- type OrganizationService
- type PermissionsService
- type Service
- type Tag
- type TagService
- type TagSpec
- type TagSpecs
- type UpdateOptions
- type VCSProviderService
- type VCSTriggerStrategy
- type Workspace
- func (ws *Workspace) Enlock(id string, kind LockKind) error
- func (ws *Workspace) ExecutionModes() []string
- func (ws *Workspace) Locked() bool
- func (ws *Workspace) LogValue() slog.Value
- func (ws *Workspace) String() string
- func (ws *Workspace) Unlock(id string, kind LockKind, force bool) error
- func (ws *Workspace) Update(opts UpdateOptions) (*bool, error)
- type WorkspacePage
- type WorkspaceService
Constants ¶
const ( // // VCS trigger strategies to present to the user. // // every vcs event trigger runs VCSTriggerAlways string = "always" // only vcs events with changed files matching a set of glob patterns // triggers run VCSTriggerPatterns string = "patterns" // only push tag vcs events trigger runs VCSTriggerTags string = "tags" )
const ( RemoteExecutionMode ExecutionMode = "remote" LocalExecutionMode ExecutionMode = "local" AgentExecutionMode ExecutionMode = "agent" DefaultAllowDestroyPlan = true MinTerraformVersion = "1.2.0" DefaultTerraformVersion = "1.5.2" )
Variables ¶
var ( ErrTagsRegexAndTriggerPatterns = errors.New("cannot specify both tags-regex and trigger-patterns") ErrTagsRegexAndAlwaysTrigger = errors.New("cannot specify both tags-regex and always-trigger") ErrTriggerPatternsAndAlwaysTrigger = errors.New("cannot specify both trigger-patterns and always-trigger") ErrInvalidTriggerPattern = errors.New("invalid trigger glob pattern") ErrInvalidTagsRegex = errors.New("invalid vcs tags regular expression") )
var ErrInvalidTagSpec = errors.New("invalid tag spec: must provide either an ID or a name")
Functions ¶
func NewService ¶
func NewService(opts Options) *service
Types ¶
type Client ¶
type Client struct {
internal.JSONAPIClient
}
func (*Client) GetWorkspace ¶
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 (*Client) LockWorkspace ¶
func (*Client) UnlockWorkspace ¶
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 Connection ¶ added in v0.1.4
type Connection struct {
// Pushes to this VCS branch trigger runs. Empty string means the default
// branch is used. Ignored if TagsRegex is non-empty.
Branch string
// Pushed tags matching this regular expression trigger runs. Mutually
// exclusive with TriggerPatterns.
TagsRegex string
VCSProviderID string
Repo string
}
type CreateOptions ¶
type CreateOptions struct {
AllowDestroyPlan *bool
AutoApply *bool
Description *string
ExecutionMode *ExecutionMode
GlobalRemoteState *bool
MigrationEnvironment *string
Name *string
QueueAllRuns *bool
SpeculativeEnabled *bool
SourceName *string
SourceURL *string
StructuredRunOutputEnabled *bool
Tags []TagSpec
TerraformVersion *string
TriggerPrefixes []string
TriggerPatterns []string
WorkingDirectory *string
Organization *string
// Always trigger runs. A value of true is mutually exclusive with
// setting TriggerPatterns or ConnectOptions.TagsRegex.
AlwaysTrigger *bool
*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 ListOptions ¶
type ListOptions struct {
Search string
Tags []string
Organization *string
resource.PageOptions
}
ListOptions are options for paginating and filtering a list of Workspaces
type ListTagsOptions ¶
type ListTagsOptions struct {
resource.PageOptions
}
ListTagsOptions are options for paginating and filtering a list of tags
type ListWorkspaceTagsOptions ¶
type ListWorkspaceTagsOptions struct {
resource.PageOptions
}
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 LockService ¶
type Options ¶
type Options struct {
*sql.DB
*pubsub.Broker
html.Renderer
organization.OrganizationService
vcsprovider.VCSProviderService
state.StateService
repo.RepoService
auth.TeamService
logr.Logger
}
type OrganizationService ¶
type OrganizationService organization.Service
type PermissionsService ¶
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) (*resource.Page[*Workspace], 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
}
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 TagService ¶
type TagService interface {
// ListTags lists tags within an organization
ListTags(ctx context.Context, organization string, opts ListTagsOptions) (*resource.Page[*Tag], 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) (*resource.Page[*Tag], error)
}
type UpdateOptions ¶
type UpdateOptions struct {
AllowDestroyPlan *bool
AutoApply *bool
Name *string
Description *string
ExecutionMode *ExecutionMode
GlobalRemoteState *bool
Operations *bool
QueueAllRuns *bool
SpeculativeEnabled *bool
StructuredRunOutputEnabled *bool
TerraformVersion *string
TriggerPrefixes []string
TriggerPatterns []string
WorkingDirectory *string
// Always trigger runs. A value of true is mutually exclusive with
// setting TriggerPatterns or ConnectOptions.TagsRegex.
AlwaysTrigger *bool
// Disconnect workspace from repo. It is invalid to specify true for an
// already disconnected workspace.
Disconnect bool
// Specifying ConnectOptions either connects a currently
// disconnected workspace, or modifies a connection if already
// connected.
*ConnectOptions
}
type VCSProviderService ¶
type VCSProviderService vcsprovider.Service
type VCSTriggerStrategy ¶ added in v0.1.4
type VCSTriggerStrategy string
VCS trigger strategy determines which VCS events trigger runs
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"`
CanQueueDestroyPlan bool `json:"can_queue_destroy_plan"`
Description string `json:"description"`
Environment string `json:"environment"`
ExecutionMode ExecutionMode `json:"execution_mode"`
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"`
WorkingDirectory string `json:"working_directory"`
Organization string `json:"organization"`
LatestRun *LatestRun `json:"latest_run"`
Tags []string `json:"tags"`
Lock *Lock `json:"lock"`
// VCS Connection; nil means the workspace is not connected.
Connection *Connection
// TriggerPatterns is mutually exclusive with Connection.TagsRegex.
//
// Note: TriggerPatterns ought to belong in Connection but it is included at
// the root of Workspace because the go-tfe integration tests set
// this field without setting the connection!
TriggerPatterns []string
// TriggerPrefixes exists only to pass the go-tfe integration tests and
// is not used when determining whether to trigger runs. Use
// TriggerPatterns instead.
TriggerPrefixes []string
}
Workspace is a terraform workspace.
func NewWorkspace ¶
func NewWorkspace(opts CreateOptions) (*Workspace, error)
func (*Workspace) ExecutionModes ¶
ExecutionModes returns a list of possible execution modes
type WorkspacePage ¶
type WorkspacePage struct {
organization.OrganizationPage
Workspace *Workspace
}
WorkspacePage contains data shared by all workspace-based pages.
type WorkspaceService ¶
type WorkspaceService = Service