From 04778ab39d9abd78dff3ae09fc98292582a04ced Mon Sep 17 00:00:00 2001 From: bra-fsn Date: Wed, 28 Aug 2024 16:31:41 +0200 Subject: [PATCH] Fix again --- pyproject.toml | 2 +- src/sc_runner/runner.py | 46 +++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3a382a3..1b22da2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "sparecores-runner" -version = "0.0.24" +version = "0.0.25" requires-python = ">= 3.9" dependencies = [ "click", diff --git a/src/sc_runner/runner.py b/src/sc_runner/runner.py index 1dd8e1b..08c5ccf 100644 --- a/src/sc_runner/runner.py +++ b/src/sc_runner/runner.py @@ -8,6 +8,7 @@ from pulumi.automation import create_or_select_stack from typing import Annotated, Callable, get_type_hints import click +import copy import os import sentry_sdk @@ -68,54 +69,59 @@ def pulumi_stack( def create(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)): + # don't modify incoming opts + pulumi_opts = copy.deepcopy(pulumi_opts) resource_f = getattr(resources, f"{resources.PREFIX}{vendor}") + if not pulumi_opts.get("stack_name"): + pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts) def pulumi_program(): return resource_f(**resource_opts) - if pulumi_opts.get("stack_name"): - stack = pulumi_stack(pulumi_program, **pulumi_opts) - else: - stack = pulumi_stack(pulumi_program, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts) + stack = pulumi_stack(pulumi_program, **pulumi_opts) stack.up(**stack_opts) def destroy(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)): + # don't modify incoming opts + pulumi_opts = copy.deepcopy(pulumi_opts) resource_f = getattr(resources, f"{resources.PREFIX}{vendor}") + if not pulumi_opts.get("stack_name"): + pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts) - if pulumi_opts.get("stack_name"): - stack = pulumi_stack(lambda: None, **pulumi_opts) - else: - stack = pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts) + stack = pulumi_stack(lambda: None, **pulumi_opts) stack.up(**stack_opts) def destroy_stack(vendor, pulumi_opts, resource_opts, stack_opts=dict(on_output=print)): + # don't modify incoming opts + pulumi_opts = copy.deepcopy(pulumi_opts) resource_f = getattr(resources, f"{resources.PREFIX}{vendor}") + if not pulumi_opts.get("stack_name"): + pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts) - if pulumi_opts.get("stack_name"): - stack = pulumi_stack(lambda: None, **pulumi_opts) - else: - stack = pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts) + stack = pulumi_stack(lambda: None, **pulumi_opts) stack.refresh(**stack_opts) stack.destroy(**stack_opts) stack.workspace.remove_stack(stack.name) def cancel(vendor, pulumi_opts, resource_opts): + # don't modify incoming opts + pulumi_opts = copy.deepcopy(pulumi_opts) resource_f = getattr(resources, f"{resources.PREFIX}{vendor}") + if not pulumi_opts.get("stack_name"): + pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts) - if pulumi_opts.get("stack_name"): - stack = pulumi_stack(lambda: None, **pulumi_opts) - else: - stack = pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts) + stack = pulumi_stack(lambda: None, **pulumi_opts) stack.cancel() def get_stack(vendor, pulumi_opts, resource_opts): + # don't modify incoming opts + pulumi_opts = copy.deepcopy(pulumi_opts) resource_f = getattr(resources, f"{resources.PREFIX}{vendor}") + if not pulumi_opts.get("stack_name"): + pulumi_opts["stack_name"] = get_stack_name(vendor, resource_f, resource_opts) - if pulumi_opts.get("stack_name"): - return pulumi_stack(lambda: None, **pulumi_opts) - else: - return pulumi_stack(lambda: None, stack_name=get_stack_name(vendor, resource_f, resource_opts), **pulumi_opts) + return pulumi_stack(lambda: None, **pulumi_opts)