2020-08-27 19:43:23 +02:00
|
|
|
// Copyright 2016-2020, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-08-18 20:07:03 +02:00
|
|
|
package auto
|
|
|
|
|
|
|
|
import (
|
2020-08-22 07:20:32 +02:00
|
|
|
"context"
|
|
|
|
|
2021-03-17 14:20:05 +01:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
2020-08-18 20:07:03 +02:00
|
|
|
)
|
|
|
|
|
2020-08-25 20:16:54 +02:00
|
|
|
// Workspace is the execution context containing a single Pulumi project, a program, and multiple stacks.
|
|
|
|
// Workspaces are used to manage the execution environment, providing various utilities such as plugin
|
|
|
|
// installation, environment configuration ($PULUMI_HOME), and creation, deletion, and listing of Stacks.
|
2020-08-18 20:07:03 +02:00
|
|
|
type Workspace interface {
|
2020-08-28 23:21:56 +02:00
|
|
|
// ProjectSettings returns the settings object for the current project if any.
|
2020-08-22 07:20:32 +02:00
|
|
|
ProjectSettings(context.Context) (*workspace.Project, error)
|
2020-08-29 04:10:39 +02:00
|
|
|
// SaveProjectSettings overwrites the settings object in the current project.
|
2020-08-18 20:07:03 +02:00
|
|
|
// There can only be a single project per workspace. Fails is new project name does not match old.
|
2020-08-29 04:10:39 +02:00
|
|
|
SaveProjectSettings(context.Context, *workspace.Project) error
|
2020-09-15 02:45:07 +02:00
|
|
|
// StackSettings returns the settings object for the stack matching the specified stack name if any.
|
2020-08-22 07:20:32 +02:00
|
|
|
StackSettings(context.Context, string) (*workspace.ProjectStack, error)
|
2020-09-15 02:45:07 +02:00
|
|
|
// SaveStackSettings overwrites the settings object for the stack matching the specified stack name.
|
2020-08-29 04:10:39 +02:00
|
|
|
SaveStackSettings(context.Context, string, *workspace.ProjectStack) error
|
2020-08-18 20:07:03 +02:00
|
|
|
// SerializeArgsForOp is hook to provide additional args to every CLI commands before they are executed.
|
2020-09-15 02:45:07 +02:00
|
|
|
// Provided with stack name,
|
2020-08-28 23:21:56 +02:00
|
|
|
// returns a list of args to append to an invoked command ["--config=...", ].
|
2020-08-22 07:20:32 +02:00
|
|
|
SerializeArgsForOp(context.Context, string) ([]string, error)
|
2020-09-15 02:45:07 +02:00
|
|
|
// PostCommandCallback is a hook executed after every command. Called with the stack name.
|
2020-08-29 04:10:39 +02:00
|
|
|
// An extensibility point to perform workspace cleanup (CLI operations may create/modify a Pulumi.stack.yaml).
|
|
|
|
PostCommandCallback(context.Context, string) error
|
2020-09-15 02:45:07 +02:00
|
|
|
// GetConfig returns the value associated with the specified stack name and key,
|
2020-08-18 20:07:03 +02:00
|
|
|
// scoped to the current workspace.
|
2020-08-22 07:20:32 +02:00
|
|
|
GetConfig(context.Context, string, string) (ConfigValue, error)
|
2020-09-15 02:45:07 +02:00
|
|
|
// GetAllConfig returns the config map for the specified stack name, scoped to the current workspace.
|
2020-08-22 07:20:32 +02:00
|
|
|
GetAllConfig(context.Context, string) (ConfigMap, error)
|
2020-09-15 02:45:07 +02:00
|
|
|
// SetConfig sets the specified key-value pair on the provided stack name.
|
2020-08-22 07:20:32 +02:00
|
|
|
SetConfig(context.Context, string, string, ConfigValue) error
|
2020-09-15 02:45:07 +02:00
|
|
|
// SetAllConfig sets all values in the provided config map for the specified stack name.
|
2020-08-22 07:20:32 +02:00
|
|
|
SetAllConfig(context.Context, string, ConfigMap) error
|
2020-09-15 02:45:07 +02:00
|
|
|
// RemoveConfig removes the specified key-value pair on the provided stack name.
|
2020-08-22 07:20:32 +02:00
|
|
|
RemoveConfig(context.Context, string, string) error
|
2020-09-15 02:45:07 +02:00
|
|
|
// RemoveAllConfig removes all values in the provided key list for the specified stack name.
|
2020-08-22 07:20:32 +02:00
|
|
|
RemoveAllConfig(context.Context, string, []string) error
|
2020-09-15 02:45:07 +02:00
|
|
|
// RefreshConfig gets and sets the config map used with the last Update for Stack matching stack name.
|
2020-08-22 07:20:32 +02:00
|
|
|
RefreshConfig(context.Context, string) (ConfigMap, error)
|
2020-09-02 01:34:27 +02:00
|
|
|
// GetEnvVars returns the environment values scoped to the current workspace.
|
|
|
|
GetEnvVars() map[string]string
|
|
|
|
// SetEnvVars sets the specified map of environment values scoped to the current workspace.
|
|
|
|
// These values will be passed to all Workspace and Stack level commands.
|
|
|
|
SetEnvVars(map[string]string) error
|
|
|
|
// SetEnvVar sets the specified environment value scoped to the current workspace.
|
|
|
|
// This value will be passed to all Workspace and Stack level commands.
|
|
|
|
SetEnvVar(string, string)
|
|
|
|
// UnsetEnvVar unsets the specified environment value scoped to the current workspace.
|
|
|
|
// This value will be removed from all Workspace and Stack level commands.
|
|
|
|
UnsetEnvVar(string)
|
2020-08-18 20:07:03 +02:00
|
|
|
// WorkDir returns the working directory to run Pulumi CLI commands.
|
|
|
|
WorkDir() string
|
|
|
|
// PulumiHome returns the directory override for CLI metadata if set.
|
2020-08-29 04:10:39 +02:00
|
|
|
// This customizes the location of $PULUMI_HOME where metadata is stored and plugins are installed.
|
|
|
|
PulumiHome() string
|
2021-03-23 07:04:14 +01:00
|
|
|
// PulumiVersion returns the version of the underlying Pulumi CLI/Engine.
|
2021-03-23 23:09:50 +01:00
|
|
|
PulumiVersion() string
|
2020-08-28 23:21:56 +02:00
|
|
|
// WhoAmI returns the currently authenticated user.
|
2020-08-22 07:20:32 +02:00
|
|
|
WhoAmI(context.Context) (string, error)
|
2020-08-25 20:16:54 +02:00
|
|
|
// Stack returns a summary of the currently selected stack, if any.
|
2020-08-22 07:20:32 +02:00
|
|
|
Stack(context.Context) (*StackSummary, error)
|
2020-09-15 02:45:07 +02:00
|
|
|
// CreateStack creates and sets a new stack with the stack name, failing if one already exists.
|
2020-08-22 07:20:32 +02:00
|
|
|
CreateStack(context.Context, string) error
|
2020-09-15 02:45:07 +02:00
|
|
|
// SelectStack selects and sets an existing stack matching the stack name, failing if none exists.
|
2020-08-22 07:20:32 +02:00
|
|
|
SelectStack(context.Context, string) error
|
2020-08-20 06:23:53 +02:00
|
|
|
// RemoveStack deletes the stack and all associated configuration and history.
|
2020-08-22 07:20:32 +02:00
|
|
|
RemoveStack(context.Context, string) error
|
2020-08-20 06:23:53 +02:00
|
|
|
// ListStacks returns all Stacks created under the current Project.
|
2020-08-18 20:07:03 +02:00
|
|
|
// This queries underlying backend and may return stacks not present in the Workspace.
|
2020-08-22 07:20:32 +02:00
|
|
|
ListStacks(context.Context) ([]StackSummary, error)
|
2020-08-28 23:21:56 +02:00
|
|
|
// InstallPlugin acquires the plugin matching the specified name and version.
|
2020-08-22 07:20:32 +02:00
|
|
|
InstallPlugin(context.Context, string, string) error
|
2021-03-23 07:04:14 +01:00
|
|
|
// RemovePlugin deletes the plugin matching the specified name and version.
|
2020-08-22 07:20:32 +02:00
|
|
|
RemovePlugin(context.Context, string, string) error
|
2020-08-18 20:07:03 +02:00
|
|
|
// ListPlugins lists all installed plugins.
|
2020-08-22 07:20:32 +02:00
|
|
|
ListPlugins(context.Context) ([]workspace.PluginInfo, error)
|
2020-08-21 04:37:39 +02:00
|
|
|
// Program returns the program `pulumi.RunFunc` to be used for Preview/Update if any.
|
2020-08-28 23:21:56 +02:00
|
|
|
// If none is specified, the stack will refer to ProjectSettings for this information.
|
2020-08-21 04:37:39 +02:00
|
|
|
Program() pulumi.RunFunc
|
2020-08-28 23:21:56 +02:00
|
|
|
// SetProgram sets the program associated with the Workspace to the specified `pulumi.RunFunc`.
|
2020-08-21 04:37:39 +02:00
|
|
|
SetProgram(pulumi.RunFunc)
|
2020-09-15 23:20:58 +02:00
|
|
|
// ExportStack exports the deployment state of the stack matching the given name.
|
|
|
|
// This can be combined with ImportStack to edit a stack's state (such as recovery from failed deployments).
|
|
|
|
ExportStack(context.Context, string) (apitype.UntypedDeployment, error)
|
|
|
|
// ImportStack imports the specified deployment state into a pre-existing stack.
|
|
|
|
// This can be combined with ExportStack to edit a stack's state (such as recovery from failed deployments).
|
|
|
|
ImportStack(context.Context, string, apitype.UntypedDeployment) error
|
2020-08-18 20:07:03 +02:00
|
|
|
}
|
2020-08-20 06:23:53 +02:00
|
|
|
|
2020-08-25 20:16:54 +02:00
|
|
|
// ConfigValue is a configuration value used by a Pulumi program.
|
|
|
|
// Allows differentiating between secret and plaintext values by setting the `Secret` property.
|
2020-08-20 06:23:53 +02:00
|
|
|
type ConfigValue struct {
|
|
|
|
Value string
|
|
|
|
Secret bool
|
|
|
|
}
|
|
|
|
|
2020-08-25 20:16:54 +02:00
|
|
|
// ConfigMap is a map of ConfigValue used by Pulumi programs.
|
|
|
|
// Allows differentiating between secret and plaintext values.
|
2020-08-20 06:23:53 +02:00
|
|
|
type ConfigMap map[string]ConfigValue
|
|
|
|
|
2020-08-25 20:16:54 +02:00
|
|
|
// StackSummary is a description of a stack and its current status.
|
2020-08-20 06:23:53 +02:00
|
|
|
type StackSummary struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Current bool `json:"current"`
|
|
|
|
LastUpdate string `json:"lastUpdate,omitempty"`
|
|
|
|
UpdateInProgress bool `json:"updateInProgress"`
|
|
|
|
ResourceCount *int `json:"resourceCount,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
}
|