Skip to content

Commit 7c27ebc

Browse files
authored
feat: Enhanced Markdown Report Formatting and Readability (#30)
* fix(plan_report): move Analysis header after if statement * fix(plan_report): format to CommonMark standards * feat(plan_report): add link to tfsumpy in footer * fix(plan_report): Use Jinja2 whitespace controls (- in {%- and -%}) * style(plan_report): add markdownlint-disable-next-line comments where Jinja2 functions and Markdown headers should be immedialy next to each other, so additional line breaks are not rendered * fix(plan_report): Jinja2 whitespace controls for `--detailed` output * style(plan_report): customize attribute output based on its resource.action only show both before and after attributes when an action is update or replace * style(plan_report): show change.attributes Before and After values in Block Quote Style This is intended to make it easier to read and compare longer values * test(plan_report): update test criteria
1 parent 8979aae commit 7c27ebc

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

tests/plan/test_plan_reporter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ def test_print_report_markdown_with_details(self, reporter, sample_report_data):
134134

135135
# Verify detailed information
136136
assert '## Resource Changes' in written_text
137-
assert '### Details:' in written_text
137+
assert '#### Details for aws_s3_bucket.data_bucket' in written_text
138+
assert '#### Details for aws_instance.web_server' in written_text
139+
assert '#### Details for aws_security_group.old_sg' in written_text
138140
assert '**Provider**:' in written_text
139141
assert '**Module**:' in written_text
140-
assert '**Dependencies**:' in written_text
142+
# Dependencies is optional and only shown if they exist
141143

142144
def test_print_report_json(self, reporter, sample_report_data):
143145
"""Test JSON report generation."""

tfsumpy/templates/plan_report.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,69 @@
11
# Terraform Plan Analysis Report
22

33
## Summary
4+
45
- **Total Resources**: {{ total_resources }}
56
- **Resources to Add**: {{ resources_to_add }}
67
- **Resources to Change**: {{ resources_to_change }}
78
- **Resources to Destroy**: {{ resources_to_destroy }}
89

910
## Resource Changes
11+
1012
{% for resource in resources %}
13+
{# <!-- markdownlint-disable-next-line MD022 --> #}
1114
### {{ resource.resource_type }}.{{ resource.identifier }}
12-
**Action:** {{ resource.action | upper }}
15+
16+
**Action:** {{ resource.action | title }}
17+
1318
{% if resource.replacement and resource.replacement_triggers %}
14-
- **Replacement triggered by:** {{ resource.replacement_triggers | join(', ') }}
19+
{# <!-- markdownlint-disable-next-line MD032 --> #}
20+
**Replacement triggered by:** {{ resource.replacement_triggers | join(', ') }}
1521
{% endif %}
1622
{% if resource.changes %}
17-
#### Changes:
23+
{# <!-- markdownlint-disable-next-line MD022 --> #}
24+
#### Changes for {{ resource.resource_type }}.{{ resource.identifier }}
25+
1826
{% for change in resource.changes %}
19-
- **{{ change.attribute }}**: {{ change.before }} → {{ change.after }}
27+
{# <!-- markdownlint-disable MD032 --> #}
28+
{% if resource.action == 'create' %}
29+
- **{{ change.attribute }}**: {{ change.after }}
30+
{% elif resource.action == 'delete' %}
31+
- **{{ change.attribute }}**: {{ change.before }}
32+
{% else %}
33+
- **{{ change.attribute }}**:
34+
- Before: {{ change.before }}
35+
- After: {{ change.after }}
36+
{% endif %}
37+
{# <!-- markdownlint-enable MD032 --> #}
2038
{% endfor %}
2139
{% endif %}
2240
{% if show_details %}
23-
#### Details:
41+
{# <!-- markdownlint-disable-next-line MD032 --> #}
42+
43+
#### Details for {{ resource.resource_type }}.{{ resource.identifier }}
44+
2445
- **Provider**: {{ resource.provider }}
2546
- **Module**: {{ resource.module }}
47+
{% if resource.dependencies %}
2648
- **Dependencies**: {{ resource.dependencies|join(', ') }}
2749
{% endif %}
50+
{# end if show_details #}
51+
{% endif %}
52+
{# The next line is blank so an empty line is rendered after Details #}
53+
2854
{% endfor %}
2955

56+
{%- if analysis and analysis|length > 0 -%}
57+
{# <!-- markdownlint-disable-next-line MD022 --> #}
3058
## Analysis
31-
{% if analysis %}
32-
{% for item in analysis %}
59+
60+
{%- for item in analysis -%}
61+
{# <!-- markdownlint-disable-next-line MD022 --> #}
3362
### {{ item.title }}
63+
64+
{# <!-- markdownlint-disable-line MD003 MD022 --> #}
3465
{{ item.description }}
3566
{% endfor %}
3667
{% endif %}
37-
3868
---
39-
*Generated by tfsumpy on {{ timestamp }}*
69+
*Generated by [tfsumpy](https://github.com/rafaelherik/tfsumpy) on {{ timestamp }}*

0 commit comments

Comments
 (0)