Add parameters to stack documentation generator

This commit is contained in:
Stefan Reimer 2020-06-22 16:16:38 +01:00
parent b8eca4e94e
commit 9d862b51dd
2 changed files with 13 additions and 9 deletions

View File

@ -357,7 +357,7 @@ class Stack(object):
my_template = pkg_resources.read_text(templates, template) my_template = pkg_resources.read_text(templates, template)
jenv = JinjaEnv() jenv = JinjaEnv()
template = jenv.from_string(my_template) template = jenv.from_string(my_template)
data = {'stackname': "/".join([self.rel_path, self.stackname]), 'timestamp': datetime.now(tzutc()), 'outputs': self.outputs, 'parameters': self.parameters} data = {'stackname': "/".join([self.rel_path, self.stackname]), 'timestamp': datetime.strftime(datetime.now(tzutc()), "%d/%m/%y %H:%M"), 'outputs': self.outputs, 'parameters': self.parameters}
with open(output_file, 'w') as output_contents: with open(output_file, 'w') as output_contents:
output_contents.write(template.render(**data)) output_contents.write(template.render(**data))
@ -388,6 +388,9 @@ class Stack(object):
if 'Parameters' in self.cfn_data: if 'Parameters' in self.cfn_data:
data['parameters'] = self.cfn_data['Parameters'] data['parameters'] = self.cfn_data['Parameters']
set_parameters = self.resolve_parameters()
for p in set_parameters:
data['parameters'][p]['value'] = set_parameters[p]
if 'Outputs' in self.cfn_data: if 'Outputs' in self.cfn_data:
data['outputs'] = self.cfn_data['Outputs'] data['outputs'] = self.cfn_data['Outputs']
@ -459,7 +462,10 @@ class Stack(object):
if _errors: if _errors:
raise ParameterNotFound('Cannot find value for parameters: {0}'.format(_errors)) raise ParameterNotFound('Cannot find value for parameters: {0}'.format(_errors))
logger.info('{} {} Parameters:\n{}'.format(self.region, self.stackname, pprint.pformat(_found, indent=2))) logger.info('{} {} set parameters:\n{}'.format(self.region, self.stackname, pprint.pformat(_found, indent=2)))
# Return dict of explicitly set parameters
return _found
@exec_hooks @exec_hooks
def create(self): def create(self):
@ -467,7 +473,6 @@ class Stack(object):
# Prepare parameters # Prepare parameters
self.resolve_parameters() self.resolve_parameters()
self.read_template_file()
logger.info('Creating {0} {1}'.format(self.region, self.stackname)) logger.info('Creating {0} {1}'.format(self.region, self.stackname))
self.aws_stackid = self.connection_manager.call( self.aws_stackid = self.connection_manager.call(
@ -492,7 +497,6 @@ class Stack(object):
# Prepare parameters # Prepare parameters
self.resolve_parameters() self.resolve_parameters()
self.read_template_file()
logger.info('Updating {0} {1}'.format(self.region, self.stackname)) logger.info('Updating {0} {1}'.format(self.region, self.stackname))
try: try:

View File

@ -11,8 +11,8 @@
{% if parameters %} {% if parameters %}
## Parameters ## Parameters
| Parameter | Type | Default | Format | Description | | Parameter | Type | Default | Format | Description | set value @ {{ timestamp }} |
|-----------|------|---------|--------|-------------| |-----------|------|---------|--------|-------------|-------------------------|
{% for p in parameters.keys() %} {% for p in parameters.keys() %}
{% if parameters[p]['AllowedValues'] or parameters[p]['AllowedPattern'] %} {% if parameters[p]['AllowedValues'] or parameters[p]['AllowedPattern'] %}
{% set format = '`%s%s`' % (parameters[p]['AllowedValues'], parameters[p]['AllowedPattern']) %} {% set format = '`%s%s`' % (parameters[p]['AllowedValues'], parameters[p]['AllowedPattern']) %}
@ -22,14 +22,14 @@
{% else %} {% else %}
{% set def = parameters[p]['Default'] %} {% set def = parameters[p]['Default'] %}
{% endif %} {% endif %}
| {{ p }} | {{ parameters[p]['Type'] | lower }} | {{ def }} | {{ format }} | {{ parameters[p]['Description'] }} | | {{ p }} | {{ parameters[p]['Type'] | lower }} | {{ def }} | {{ format }} | {{ parameters[p]['Description'] }} | {{ parameters[p]['value'] }} |
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if outputs %} {% if outputs %}
## Outputs ## Outputs
| Output | Description | Value as of {{ timestamp }} | | Output | Description | Value @ {{ timestamp }} |
|--------|-------------|-----------------------------| |--------|-------------|-------------------------|
{% for p in outputs.keys() | sort%} {% for p in outputs.keys() | sort%}
| {{ p }} | {{ outputs[p]['Description'] }} | {{ outputs[p]['last_value'] }} | | {{ p }} | {{ outputs[p]['Description'] }} | {{ outputs[p]['last_value'] }} |
{% endfor %} {% endfor %}