Class LocalWorkspace
- All Implemented Interfaces:
AutoCloseable
A 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.
LocalWorkspace relies on Pulumi.yaml and Pulumi.{stack}.yaml as the intermediate format for Project and Stack settings. Modifying ProjectSettings will alter the Workspace Pulumi.yaml file, and setting config on a Stack will modify the Pulumi.{stack}.yaml file. This is identical to the behavior of Pulumi CLI driven workspaces.
If not provided a working directory - causing LocalWorkspace to create a temp
directory, then the temp directory will be cleaned up when close()
is called.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddEnvironments(String stackName, Collection<String> environments) Adds environments to the end of a stack's import list.voidchangeSecretsProvider(String stackName, String newSecretsProvider, SecretsProviderOptions options) Change the secrets provider for a stack.voidclose()static LocalWorkspacecreate()Creates a workspace.static LocalWorkspacecreate(LocalWorkspaceOptions options) Creates a workspace using the specified options.static WorkspaceStackcreateOrSelectStack(String projectName, String stackName, Consumer<Context> program) Creates or selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program.static WorkspaceStackcreateOrSelectStack(String projectName, String stackName, Consumer<Context> program, LocalWorkspaceOptions options) Creates or selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program.static WorkspaceStackcreateOrSelectStack(String stackName, Path workDir) Creates or selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir.static WorkspaceStackcreateOrSelectStack(String stackName, Path workDir, LocalWorkspaceOptions options) Creates or selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir.voidcreateStack(String stackName) Creates and sets a new stack with the specified stack name, failing if one already exists.static WorkspaceStackcreateStack(String projectName, String stackName, Consumer<Context> program) Creates a stack with aLocalWorkspaceutilizing the specified inline (in process)program.static WorkspaceStackcreateStack(String projectName, String stackName, Consumer<Context> program, LocalWorkspaceOptions options) Creates a stack with aLocalWorkspaceutilizing the specified inline (in process)program.static WorkspaceStackcreateStack(String stackName, Path workDir) Creates a Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir.static WorkspaceStackcreateStack(String stackName, Path workDir, LocalWorkspaceOptions options) Creates a Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir.Environment values scoped to the current workspace.exportStack(String stackName) Exports the deployment state of the stack.getAllConfig(String stackName) Returns the config map for the specified stack name, scoped to the current Workspace.Returns the value associated with the specified stack name and key, scoped to the Workspace.Returns project settings for the current project if any.getStackOutputs(String stackName) Gets the current set of Stack outputs from the lastWorkspaceStack.up()call.getStackSettings(String stackName) Returns stack settings for the stack matching the specified stack name if any.Returns the value associated with the stack and key, scoped to the Workspace.voidimportStack(String stackName, StackDeployment state) Imports the specified deployment state into a pre-existing stack.voidinstallPlugin(String name, String version, PluginInstallOptions options) Installs a plugin in the Workspace, for example to use cloud providers like AWS or GCP.Returns a list of all plugins installed in the Workspace.Returns all stacks created under the current project.Returns the tag map for the specified stack name, scoped to the current Workspace.logger()A custom logger instance that will be used for the action.voidpostCommandCallback(String stackName) Hook executed after every command.program()The inline program to be used for Preview/Update operations if any.The directory override for CLI metadata if set.The version of the underlying Pulumi CLI/Engine.refreshConfig(String stackName) Gets and sets the config map used with the last update for the stack matching the specified stack name.voidremoveAllConfig(String stackName, Collection<String> keys, boolean path) Removes all values in the provided key collection from the config map for the specified stack name.voidremoveConfig(String stackName, String key, boolean path) Removes the specified key-value pair from the provided stack's config.voidremoveEnvironment(String stackName, String environment) Removes environments from a stack's import list.voidremovePlugin(PluginRemoveOptions options) Removes a plugin or plugins from the Workspace.voidremoveStack(String stackName) Deletes the stack and all associated configuration and history.voidRemoves the specified key-value pair on the provided stack name.voidsaveProjectSettings(ProjectSettings settings) Overwrites the settings for the current project.voidsaveStackSettings(String stackName, StackSettings settings) Overwrite the settings for the stack matching the specified stack name.The secrets provider to use for encryption and decryption of stack secrets.voidselectStack(String stackName) Selects and sets an existing stack matching the stack name, failing if none exists.static WorkspaceStackselectStack(String projectName, String stackName, Consumer<Context> program) Selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program.static WorkspaceStackselectStack(String projectName, String stackName, Consumer<Context> program, LocalWorkspaceOptions options) Selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program.static WorkspaceStackselectStack(String stackName, Path workDir) Selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir.static WorkspaceStackselectStack(String stackName, Path workDir, LocalWorkspaceOptions options) Selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir.serializeArgsForOp(String stackName) Hook to provide additional args to every CLI command before they are executed.voidsetAllConfig(String stackName, Map<String, ConfigValue> configMap, boolean path) Sets all values in the provided config map for the specified stack name.voidsetConfig(String stackName, String key, ConfigValue value, boolean path) Sets the specified key-value pair in the provided stack's config.voidSets the specified key-value pair on the provided stack name.whoAmI()Returns the currently authenticated user.workDir()The working directory to run Pulumi CLI commands.Methods inherited from class com.pulumi.automation.Workspace
changeSecretsProvider, getConfig, getStack, installPlugin, removeAllConfig, removeConfig, setAllConfig, setConfig
-
Method Details
-
create
Creates a workspace.- Returns:
- the workspace
- Throws:
AutomationException- if an error occurs
-
create
public static LocalWorkspace create(@Nullable LocalWorkspaceOptions options) throws AutomationException Creates a workspace using the specified options. Used for maximal control and customization of the underlying environment before any stacks are created or selected.- Parameters:
options- Options used to configure the workspace- Returns:
- the workspace
- Throws:
AutomationException- if an error occurs
-
createStack
public static WorkspaceStack createStack(String projectName, String stackName, Consumer<Context> program) throws AutomationException Creates a stack with aLocalWorkspaceutilizing the specified inline (in process)program. This program is fully debuggable and runs in process. Default project settings will be created on behalf of the user and the working directory will default to a new temporary directory provided by the OS.- Parameters:
projectName- the name of the projectstackName- the name of the stackprogram- the program to run- Returns:
- the stack
- Throws:
StackAlreadyExistsException- if a stack with the provided name already existsAutomationException- if an error occurs
-
createStack
public static WorkspaceStack createStack(String projectName, String stackName, Consumer<Context> program, LocalWorkspaceOptions options) throws AutomationException Creates a stack with aLocalWorkspaceutilizing the specified inline (in process)program. This program is fully debuggable and runs in process. If noLocalWorkspaceOptions.projectSettings()option is specified, default project settings will be created on behalf of the user. Similarly, unless aLocalWorkspaceOptions.workDir()option is specified, the working directory will default to a new temporary directory provided by the OS.- Parameters:
projectName- the name of the projectstackName- the name of the stackprogram- the program to runoptions- options used to configure the workspace- Returns:
- the stack
- Throws:
StackAlreadyExistsException- if a stack with the provided name already existsAutomationException- if an error occurs
-
createStack
Creates a Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir. This is a way to create drivers on top of pre-existing Pulumi programs. This Workspace will pick up any available Settings files(Pulumi.yaml, Pulumi.{stack}.yaml).- Parameters:
stackName- the name of the stackworkDir- the working directory- Returns:
- the stack
- Throws:
StackAlreadyExistsException- if a stack with the provided name already existsAutomationException- if an error occurs
-
createStack
public static WorkspaceStack createStack(String stackName, Path workDir, LocalWorkspaceOptions options) throws AutomationException Creates a Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir. This is a way to create drivers on top of pre-existing Pulumi programs. This Workspace will pick up any available Settings files(Pulumi.yaml, Pulumi.{stack}.yaml).- Parameters:
stackName- the name of the stackworkDir- the working directoryoptions- options used to configure the workspace- Returns:
- the stack
- Throws:
StackAlreadyExistsException- if a stack with the provided name already existsAutomationException- if an error occurs
-
selectStack
public static WorkspaceStack selectStack(String projectName, String stackName, Consumer<Context> program) throws AutomationException Selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program. This program is fully debuggable and runs in process. Default project settings will be created on behalf of the user and the working directory will default to a new temporary directory provided by the OS.- Parameters:
projectName- the name of the projectstackName- the name of the stackprogram- the program to run- Returns:
- the stack
- Throws:
StackNotFoundException- if a stack with the provided name does not existAutomationException- if an error occurs
-
selectStack
public static WorkspaceStack selectStack(String projectName, String stackName, Consumer<Context> program, LocalWorkspaceOptions options) throws AutomationException Selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program. This program is fully debuggable and runs in process. If noLocalWorkspaceOptions.projectSettings()option is specified, default project settings will be created on behalf of the user. Similarly, unless aLocalWorkspaceOptions.workDir()option is specified, the working directory will default to a new temporary directory provided by the OS.- Parameters:
projectName- the name of the projectstackName- the name of the stackprogram- the program to runoptions- options used to configure the workspace- Returns:
- the stack
- Throws:
StackNotFoundException- if a stack with the provided name does not existAutomationException- if an error occurs
-
selectStack
Selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir. This is a way to create drivers on top of pre-existing Pulumi programs. This Workspace will pick up any available Settings files(Pulumi.yaml, Pulumi.{stack}.yaml).- Parameters:
stackName- the name of the stackworkDir- the working directory- Returns:
- the stack
- Throws:
StackNotFoundException- if a stack with the provided name does not existAutomationException- if an error occurs
-
selectStack
public static WorkspaceStack selectStack(String stackName, Path workDir, LocalWorkspaceOptions options) throws AutomationException Selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir. This is a way to create drivers on top of pre-existing Pulumi programs. This Workspace will pick up any available Settings files(Pulumi.yaml, Pulumi.{stack}.yaml).- Parameters:
stackName- the name of the stackworkDir- the working directoryoptions- options used to configure the workspace- Returns:
- the stack
- Throws:
StackNotFoundException- if a stack with the provided name does not existAutomationException- if an error occurs
-
createOrSelectStack
public static WorkspaceStack createOrSelectStack(String projectName, String stackName, Consumer<Context> program) throws AutomationException Creates or selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program. This program is fully debuggable and runs in process. Default project settings will be created on behalf of the user and the working directory will default to a new temporary directory provided by the OS.- Parameters:
projectName- the name of the projectstackName- the name of the stackprogram- the program to run- Returns:
- the stack
- Throws:
AutomationException- if an error occurs
-
createOrSelectStack
public static WorkspaceStack createOrSelectStack(String projectName, String stackName, Consumer<Context> program, LocalWorkspaceOptions options) throws AutomationException Creates or selects an existing Stack with aLocalWorkspaceutilizing the specified inline (in process)program. This program is fully debuggable and runs in process. If noLocalWorkspaceOptions.projectSettings()option is specified, default project settings will be created on behalf of the user. Similarly, unless aLocalWorkspaceOptions.workDir()option is specified, the working directory will default to a new temporary directory provided by the OS.- Parameters:
projectName- the name of the projectstackName- the name of the stackprogram- the program to runoptions- options used to configure the workspace- Returns:
- the stack
- Throws:
AutomationException- if an error occurs
-
createOrSelectStack
public static WorkspaceStack createOrSelectStack(String stackName, Path workDir) throws AutomationException Creates or selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir. This is a way to create drivers on top of pre-existing Pulumi programs. This Workspace will pick up any available Settings files(Pulumi.yaml, Pulumi.{stack}.yaml).- Parameters:
stackName- the name of the stackworkDir- the working directory- Returns:
- the stack
- Throws:
AutomationException- if an error occurs
-
createOrSelectStack
public static WorkspaceStack createOrSelectStack(String stackName, Path workDir, LocalWorkspaceOptions options) throws AutomationException Creates or selects an existing Stack with aLocalWorkspaceutilizing the local Pulumi CLI program from the specifiedworkDir. This is a way to create drivers on top of pre-existing Pulumi programs. This Workspace will pick up any available Settings files(Pulumi.yaml, Pulumi.{stack}.yaml).- Parameters:
stackName- the name of the stackworkDir- the working directoryoptions- options used to configure the workspace- Returns:
- the stack
- Throws:
AutomationException- if an error occurs
-
workDir
The working directory to run Pulumi CLI commands. -
pulumiHome
The directory override for CLI metadata if set.This customizes the location of $PULUMI_HOME where metadata is stored and plugins are installed.
- Specified by:
pulumiHomein classWorkspace- Returns:
- the directory override
-
pulumiVersion
The version of the underlying Pulumi CLI/Engine.- Specified by:
pulumiVersionin classWorkspace- Returns:
- the version
-
secretsProvider
The secrets provider to use for encryption and decryption of stack secrets.See: https://www.pulumi.com/docs/intro/concepts/secrets/#available-encryption-providers
- Specified by:
secretsProviderin classWorkspace- Returns:
- the secrets provider
-
program
The inline program to be used for Preview/Update operations if any.If non specified, the stack will refer to
ProjectSettingsfor this information. -
logger
A custom logger instance that will be used for the action. Note that it will only be usedWorkspace.program()is also provided. -
environmentVariables
Environment values scoped to the current workspace. These will be supplied to every Pulumi command.- Specified by:
environmentVariablesin classWorkspace- Returns:
- the environment variables
-
getProjectSettings
Returns project settings for the current project if any.- Specified by:
getProjectSettingsin classWorkspace- Returns:
- the project settings
- Throws:
AutomationException- if there was an issue retrieving the project
-
saveProjectSettings
Overwrites the settings for the current project.There can only be a single project per workspace. Fails if new project name does not match old.
- Specified by:
saveProjectSettingsin classWorkspace- Parameters:
settings- the settings object to save- Throws:
AutomationException- if there was an issue saving the project
-
getStackSettings
Returns stack settings for the stack matching the specified stack name if any.- Specified by:
getStackSettingsin classWorkspace- Parameters:
stackName- the name of the stack- Returns:
- the stack settings
- Throws:
AutomationException- if there was an issue retrieving the stack
-
saveStackSettings
Overwrite the settings for the stack matching the specified stack name.- Specified by:
saveStackSettingsin classWorkspace- Parameters:
stackName- the name of the stack to operation onsettings- the settings object to save- Throws:
AutomationException- if there was an issue saving the stack
-
serializeArgsForOp
Hook to provide additional args to every CLI command before they are executed.Provided with a stack name, returns a list of args to append to an invoked command ["--config=...", ].
LocalWorkspacedoes not utilize this extensibility point.- Specified by:
serializeArgsForOpin classWorkspace- Parameters:
stackName- the name of the stack- Returns:
- the list of args to append
-
postCommandCallback
Hook executed after every command. Called with the stack name.An extensibility point to perform workspace cleanup (CLI operations may create/modify a Pulumi.stack.yaml).
LocalWorkspacedoes not utilize this extensibility point.- Specified by:
postCommandCallbackin classWorkspace- Parameters:
stackName- the name of the stack- Throws:
AutomationException- if there was an issue executing the post command
-
whoAmI
Returns the currently authenticated user.- Specified by:
whoAmIin classWorkspace- Returns:
- the currently authenticated user
- Throws:
AutomationException- if there was an issue determining the current user
-
createStack
Creates and sets a new stack with the specified stack name, failing if one already exists.- Specified by:
createStackin classWorkspace- Parameters:
stackName- the stack to create- Throws:
AutomationException- if there was an issue creating the stack
-
selectStack
Selects and sets an existing stack matching the stack name, failing if none exists.- Specified by:
selectStackin classWorkspace- Parameters:
stackName- the stack to select- Throws:
StackNotFoundException- if the stack does not existAutomationException- if there was an issue selecting the stack
-
removeStack
Deletes the stack and all associated configuration and history.- Specified by:
removeStackin classWorkspace- Parameters:
stackName- the stack to remove- Throws:
AutomationException- if there was an issue removing the stack
-
listStacks
Returns all stacks created under the current project.This queries underlying backend and may return stacks not present in the Workspace (as Pulumi.{stack}.yaml files).
- Specified by:
listStacksin classWorkspace- Returns:
- the list of stacks
- Throws:
AutomationException- if there was an issue listing the stacks
-
exportStack
Exports the deployment state of the stack.This can be combined with
Workspace.importStack(java.lang.String, com.pulumi.automation.StackDeployment)to edit a stack's state (such as recovery from failed deployments).- Specified by:
exportStackin classWorkspace- Parameters:
stackName- the stack to export- Returns:
- the deployment state of the stack
- Throws:
AutomationException- if there was an issue exporting the stack
-
importStack
Imports the specified deployment state into a pre-existing stack.This can be combined with
Workspace.exportStack(java.lang.String)to edit a stack's state (such as recovery from failed deployments).- Specified by:
importStackin classWorkspace- Parameters:
stackName- the stack to importstate- the deployment state to import- Throws:
AutomationException- if there was an issue importing the stack
-
addEnvironments
public void addEnvironments(String stackName, Collection<String> environments) throws AutomationException Adds environments to the end of a stack's import list. Imported environments are merged in order per the ESC merge rules. The list of environments behaves as if it were the import list in an anonymous environment.- Specified by:
addEnvironmentsin classWorkspace- Parameters:
stackName- the name of the stackenvironments- list of environments to add to the end of the stack's import list- Throws:
AutomationException- if there was an issue adding the environments
-
removeEnvironment
Removes environments from a stack's import list.- Specified by:
removeEnvironmentin classWorkspace- Parameters:
stackName- the name of the stackenvironment- the name of the environment to remove from the stack's configuration- Throws:
AutomationException- if there was an issue removing the environment
-
getTag
Returns the value associated with the stack and key, scoped to the Workspace.- Specified by:
getTagin classWorkspace- Parameters:
stackName- the name of the stack to read tag metadata fromkey- the key to use for the tag lookup- Returns:
- the value associated with the key
- Throws:
AutomationException- if there was an issue reading the tag
-
setTag
Sets the specified key-value pair on the provided stack name.- Specified by:
setTagin classWorkspace- Parameters:
stackName- the stack to operate onkey- the tag key to setvalue- the tag value to set- Throws:
AutomationException- if there was an issue setting the tag
-
removeTag
Removes the specified key-value pair on the provided stack name.- Specified by:
removeTagin classWorkspace- Parameters:
stackName- the stack to operate onkey- the tag key to remove- Throws:
AutomationException- if there was an issue removing the tag
-
listTags
Returns the tag map for the specified stack name, scoped to the current Workspace.- Specified by:
listTagsin classWorkspace- Parameters:
stackName- the stack to operate on- Returns:
- the tag map for the specified stack name
- Throws:
AutomationException- if there was an issue listing the tags
-
getConfig
Returns the value associated with the specified stack name and key, scoped to the Workspace.- Specified by:
getConfigin classWorkspace- Parameters:
stackName- the name of the stack to read config fromkey- the key to use for the config lookuppath- the key contains a path to a property in a map or list to get- Returns:
- the value associated with the key
- Throws:
AutomationException- if there was an issue reading the config
-
getAllConfig
Returns the config map for the specified stack name, scoped to the current Workspace.- Specified by:
getAllConfigin classWorkspace- Parameters:
stackName- the name of the stack to read config from- Returns:
- the config map for the specified stack name
- Throws:
AutomationException- if there was an issue listing the config
-
setConfig
public void setConfig(String stackName, String key, ConfigValue value, boolean path) throws AutomationException Sets the specified key-value pair in the provided stack's config.- Specified by:
setConfigin classWorkspace- Parameters:
stackName- the name of the stack to operate onkey- the config key to setvalue- the config value to setpath- the key contains a path to a property in a map or list to set- Throws:
AutomationException- if there was an issue setting the config
-
setAllConfig
public void setAllConfig(String stackName, Map<String, ConfigValue> configMap, boolean path) throws AutomationExceptionSets all values in the provided config map for the specified stack name.- Specified by:
setAllConfigin classWorkspace- Parameters:
stackName- the name of the stack to operate onconfigMap- the config map to upsert against the existing configpath- the keys contain a path to a property in a map or list to set- Throws:
AutomationException- if there was an issue setting the config
-
removeConfig
Removes the specified key-value pair from the provided stack's config.- Specified by:
removeConfigin classWorkspace- Parameters:
stackName- the name of the stack to operate onkey- the config key to removepath- the key contains a path to a property in a map or list to remove- Throws:
AutomationException- if there was an issue removing the config
-
removeAllConfig
public void removeAllConfig(String stackName, Collection<String> keys, boolean path) throws AutomationException Removes all values in the provided key collection from the config map for the specified stack name.- Specified by:
removeAllConfigin classWorkspace- Parameters:
stackName- the name of the stack to operate onkeys- the collection of keys to remove from the underlying config mappath- the keys contain a path to a property in a map or list to remove- Throws:
AutomationException- if there was an issue removing the config
-
refreshConfig
Gets and sets the config map used with the last update for the stack matching the specified stack name.- Specified by:
refreshConfigin classWorkspace- Parameters:
stackName- the name of the stack to operate on- Returns:
- the config map used with the last update for the stack
- Throws:
AutomationException- if there was an issue refreshing the config
-
installPlugin
public void installPlugin(String name, String version, PluginInstallOptions options) throws AutomationException Installs a plugin in the Workspace, for example to use cloud providers like AWS or GCP.- Specified by:
installPluginin classWorkspace- Parameters:
name- the name of the pluginversion- the version of the plugin, e.g. "v1.0.0"options- additional plugin installation options- Throws:
AutomationException- if there was an issue installing the plugin
-
removePlugin
Removes a plugin or plugins from the Workspace.- Specified by:
removePluginin classWorkspace- Parameters:
options- plugin removal options- Throws:
AutomationException- if there was an issue removing the plugin
-
listPlugins
Returns a list of all plugins installed in the Workspace.- Specified by:
listPluginsin classWorkspace- Returns:
- the list of plugins
- Throws:
AutomationException- if there was an issue listing the plugins
-
getStackOutputs
Gets the current set of Stack outputs from the lastWorkspaceStack.up()call.- Specified by:
getStackOutputsin classWorkspace- Parameters:
stackName- the name of the stack- Returns:
- the stack outputs
- Throws:
AutomationException- if there was an issue getting the stack outputs
-
changeSecretsProvider
public void changeSecretsProvider(String stackName, String newSecretsProvider, @Nullable SecretsProviderOptions options) throws AutomationException Change the secrets provider for a stack.- Specified by:
changeSecretsProviderin classWorkspace- Parameters:
stackName- the name of the stacknewSecretsProvider- the new secrets provideroptions- the options to change the secrets provider- Throws:
AutomationException- if there was an issue changing the secrets provider
-
close
- Throws:
Exception
-