Hi all! I'm in a situation where I need to rename...
# general
l
Hi all! I'm in a situation where I need to rename a ton of stacks and I'm trying to do it via the automation API, but I'm failing. • Can't seem to find an outright "rename_stack" method via these objects/modules: ◦
LocalWorkspace
Stack
pulumi.automation
• I've tried
pulumi.automation.create_stack
and importing an export via
stack.new_stack
, but it errors out because it requires a
--force
flag due to the fact that the exported stack is still deployed.
Copy code
pulumi.automation.errors.CommandError: 
 code: 255
 stdout: 
 stderr: warning: A new version of Pulumi is available. To upgrade from version '3.44.2' to '3.47.2', visit <https://pulumi.com/docs/reference/install/> for manual instructions and release notes.
error: 'stack-name-redactified' still has resources; removal rejected. Possible actions:
- Make sure that 'stack-name-redactified' is the stack that you want to destroy
- Run `pulumi destroy` to delete the resources, then run `pulumi stack rm`
- Run `pulumi stack rm --force` to override this error
Am I making this more complicated than necessary? Is there a way of passing the
--force
flag such that the methods will acknowledge it?
I should also mention that I've checked the relevant method signatures and it seems that a
force
parameter isn't available.
serialize_args_for_op gave me hope for a moment, but I'm working with LocalWorkspace and....
LocalWorkspace does not utilize this extensibility point.
m
Summoning @limited-rainbow-51650 for this 🙂
l
Thanks! So, I hacked my way around to force things to work. This is probably as dumb as it gets, but it works for my one-off case:
Copy code
from pulumi import automation as auto

class LocalWorkspace(auto.LocalWorkspace):

    def _run_pulumi_cmd_sync(self, args:list, *aargs, **kwargs):

        args.append('--force')
        try:
            return super()._run_pulumi_cmd_sync(args, *aargs, **kwargs)
        except:
            args.pop(args.index('--force'))
            return super()._run_pulumi_cmd_sync(args, *aargs, **kwargs)

auto._local_workspace.LocalWorkspace = LocalWorkspace
Warning: • ^ above block of code blindly pass the
--force
flag to all commands. • I just needed this as a one-off solution, and it shouldn't be considered....for anything ever.