feat: add export command for pulumi stakcs incl. optional reset, fix pulumi secrets for outputs
This commit is contained in:
parent
65b9282060
commit
129d287ae5
@ -143,6 +143,21 @@ def refresh(cb, stack_name):
|
||||
logger.info('{} uses Cloudformation, refresh skipped.'.format(s.stackname))
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("stack_name")
|
||||
@click.option("--reset", is_flag=True, help="All pending stack operations are removed and the stack will be re-imported")
|
||||
@click.pass_obj
|
||||
def export(cb, stack_name, reset=False):
|
||||
""" Exports a Pulumi stack to repair state """
|
||||
stacks = _find_stacks(cb, [stack_name])
|
||||
|
||||
for s in stacks:
|
||||
if s.mode == 'pulumi':
|
||||
s.export(reset)
|
||||
else:
|
||||
logger.info('{} uses Cloudformation, export skipped.'.format(s.stackname))
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("stack_name")
|
||||
@click.argument("key")
|
||||
@ -331,6 +346,7 @@ cli.add_command(refresh)
|
||||
cli.add_command(preview)
|
||||
cli.add_command(set_config)
|
||||
cli.add_command(get_config)
|
||||
cli.add_command(export)
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli(obj={})
|
||||
|
@ -1,6 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
import hashlib
|
||||
import json
|
||||
import yaml
|
||||
import time
|
||||
import pathlib
|
||||
@ -387,6 +388,11 @@ class Stack(object):
|
||||
stack = pulumi_init(self)
|
||||
self.outputs = stack.outputs()
|
||||
|
||||
# If secrets replace with clear values for now
|
||||
for k in self.outputs.keys():
|
||||
if self.outputs[k].secret:
|
||||
self.outputs[k] = self.outputs[k].value
|
||||
|
||||
else:
|
||||
self.read_template_file()
|
||||
try:
|
||||
@ -664,6 +670,22 @@ class Stack(object):
|
||||
|
||||
return
|
||||
|
||||
@pulumi_ws
|
||||
def export(self, reset):
|
||||
""" Exports a Pulumi stack """
|
||||
|
||||
stack = pulumi_init(self)
|
||||
deployment = stack.export_stack()
|
||||
|
||||
if reset:
|
||||
deployment.deployment.pop('pending_operations', None)
|
||||
stack.import_stack(deployment)
|
||||
logger.info('Removed all pending_operations from %s' % self.stackname)
|
||||
else:
|
||||
print(json.dumps(deployment.deployment))
|
||||
|
||||
return
|
||||
|
||||
@pulumi_ws
|
||||
def set_config(self, key, value, secret):
|
||||
""" Set a config or secret """
|
||||
|
Loading…
Reference in New Issue
Block a user