Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
add yaml output format, using logical id as group for substack
Browse files Browse the repository at this point in the history
  • Loading branch information
geronimo-iia committed Apr 27, 2017
1 parent a335c63 commit febb492
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
3 changes: 1 addition & 2 deletions brume/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def status():
def outputs():
"""Get the full list of outputs of a CloudFormation stack."""
outputs = Stack(cf_config).outputs()
for o in outputs:
click.echo('{} = {}'.format(o, outputs[o]))
print dump(outputs, default_flow_style=False)


@click.command()
Expand Down
31 changes: 19 additions & 12 deletions brume/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ def make_tags(tags_list):
def make_parameters(tags_list):
return [{"ParameterKey": k, "ParameterValue": v} for k, v in tags_list.items()]

def outputs_for(outputs, stack):
try:
s_outputs = client.describe_stacks(StackName=stack)['Stacks'][0].get('Outputs', [])
for o in s_outputs:
outputs[o['OutputKey']] = o['OutputValue']
return outputs
except ClientError as e:
if 'does not exist' in e.message:
click.secho('Stack [{}] does not exist'.format(stack), err=True, fg='red')
exit(1)
else:
raise e


class Stack():
stack_name = None
Expand Down Expand Up @@ -51,18 +64,12 @@ def get_stacks(self):

def outputs(self):
outputs = {}
try:
for stack in self.get_stacks():
s_outputs = client.describe_stacks(StackName=stack)['Stacks'][0].get('Outputs', [])
for o in s_outputs:
outputs[o['OutputKey']] = o['OutputValue']
return outputs
except ClientError as e:
if 'does not exist' in e.message:
click.secho('Stack [{}] does not exist'.format(self.stack_name), err=True, fg='red')
exit(1)
else:
raise e
outputs_for(outputs, self.stack_name)
substacks = client.describe_stack_resources(StackName=self.stack_name)['StackResources']
for s in substacks:
outputs[s['LogicalResourceId']] = {}
outputs_for(outputs[s['LogicalResourceId']], s['PhysicalResourceId'])
return outputs

def params(self):
parameters = {}
Expand Down

0 comments on commit febb492

Please sign in to comment.