feat: add import task to pulumi stacks
Some checks failed
ZeroDownTime/CloudBender/pipeline/head There was a failure building this commit

This commit is contained in:
Stefan Reimer 2024-12-02 12:48:30 +00:00
parent 9a25dc34bb
commit 24c0346864
2 changed files with 29 additions and 0 deletions

View File

@ -212,6 +212,21 @@ def execute(cb, stack_name, function, args):
)
@click.command('import')
@click.argument("stack_name")
@click.argument("pulumi_state_file")
@click.pass_obj
def _import(cb, stack_name, pulumi_state_file):
"""Imports a Pulumi state file as stack"""
stacks = _find_stacks(cb, [stack_name])
for s in stacks:
if s.mode == "pulumi":
s._import(pulumi_state_file)
else:
logger.info("{} uses Cloudformation, export skipped.".format(s.stackname))
@click.command()
@click.argument("stack_name")
@click.option(
@ -482,6 +497,7 @@ cli.add_command(refresh)
cli.add_command(preview)
cli.add_command(set_config)
cli.add_command(get_config)
cli.add_command(_import)
cli.add_command(export)
cli.add_command(assimilate)
cli.add_command(execute)

View File

@ -1024,6 +1024,19 @@ class Stack(object):
return
@pulumi_ws
def _import(self, pulumi_state_file):
"""Imports a Pulumi stack"""
pulumi_stack = self._get_pulumi_stack()
with open(pulumi_state_file, "r") as file:
state = json.loads(file.read())
deployment = pulumi.automation.Deployment(version=3, deployment=state)
pulumi_stack.import_stack(deployment)
return
@pulumi_ws
def set_config(self, key, value, secret):
"""Set a config or secret"""