From 7695311d799f47a3cf13e6019d135eec4bb886bd Mon Sep 17 00:00:00 2001 From: Dennis Webb Date: Fri, 21 Oct 2022 15:11:54 -0500 Subject: [PATCH 1/2] attempts to select the stack before creating Creating a stack requires admin permissions, where selecting does not. --- ...empts-to-select-the-stack-before-attempting-to-create.yaml | 4 ++++ sdk/python/lib/pulumi/automation/_stack.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog/pending/20221021--sdk-python--pulumi-automation-create_or_select_stack-attempts-to-select-the-stack-before-attempting-to-create.yaml diff --git a/changelog/pending/20221021--sdk-python--pulumi-automation-create_or_select_stack-attempts-to-select-the-stack-before-attempting-to-create.yaml b/changelog/pending/20221021--sdk-python--pulumi-automation-create_or_select_stack-attempts-to-select-the-stack-before-attempting-to-create.yaml new file mode 100644 index 000000000000..25d6599a89ff --- /dev/null +++ b/changelog/pending/20221021--sdk-python--pulumi-automation-create_or_select_stack-attempts-to-select-the-stack-before-attempting-to-create.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: sdk/python + description: pulumi.automation.create_or_select_stack() attempts to select the stack before attempting to create diff --git a/sdk/python/lib/pulumi/automation/_stack.py b/sdk/python/lib/pulumi/automation/_stack.py index 00b86bc038ad..b04d1651a273 100644 --- a/sdk/python/lib/pulumi/automation/_stack.py +++ b/sdk/python/lib/pulumi/automation/_stack.py @@ -186,9 +186,9 @@ def __init__(self, name: str, workspace: Workspace, mode: StackInitMode) -> None workspace.select_stack(name) elif mode is StackInitMode.CREATE_OR_SELECT: try: - workspace.create_stack(name) - except StackAlreadyExistsError: workspace.select_stack(name) + except StackNotFoundError: + workspace.create_stack(name) def __repr__(self): return f"Stack(stack_name={self.name!r}, workspace={self.workspace!r}, mode={self._mode!r})" From 340c4c9e75ffc669694f487133b322ceab03f5b6 Mon Sep 17 00:00:00 2001 From: Lee Briggs Date: Fri, 21 Oct 2022 14:13:42 -0700 Subject: [PATCH 2/2] add missing `StackNotFoundError` import --- sdk/python/lib/pulumi/automation/_stack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/python/lib/pulumi/automation/_stack.py b/sdk/python/lib/pulumi/automation/_stack.py index b04d1651a273..6c59d64586a0 100644 --- a/sdk/python/lib/pulumi/automation/_stack.py +++ b/sdk/python/lib/pulumi/automation/_stack.py @@ -25,7 +25,7 @@ from ._cmd import CommandResult, _run_pulumi_cmd, OnOutput from ._config import ConfigValue, ConfigMap -from .errors import StackAlreadyExistsError +from .errors import StackAlreadyExistsError, StackNotFoundError from .events import OpMap, EngineEvent, SummaryEvent from ._output import OutputMap from ._server import LanguageServer