-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support
-html
flag to render output as HTML (#70)
* support `-html` flag to render output as HTML This addresses issue #69 to support HTML output. This also... - updates the README usage docs - validates that multiple, conflicting format flags are not provided - fixes a bug in the tests to properly validate expected tf-summarize errors Signed-off-by: Mike Ball <mikedball@gmail.com> * improve tests to exercise outputs Previously, the tf-summarize tests did not exercise the tool's ability to summarize plan outputs. This fixes that! * ensure 'make help' outputs details on all targets By adding a code comment in association with all Make targets, `make help` now documents all targets: ``` $ make help build build the binary example generate example Terraform plan help prints help (only for tasks with comment) i build and install to /usr/local/bin/ install build and install to /usr/local/bin/ lint lint source code test go test ``` * put HTML resources in <code> within summary This makes the HTML output a bit more consistent with output elsewhere. * protecting against stale tests runs This protects against false positives running the tests. --------- Signed-off-by: Mike Ball <mikedball@gmail.com>
- Loading branch information
Showing
17 changed files
with
231 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<table> | ||
<tr> | ||
<th>CHANGE</th> | ||
<th>RESOURCE</th> | ||
</tr> | ||
<tr> | ||
<td>add</td> | ||
<td> | ||
<ul> | ||
<li><code>github_repository.terraform_plan_summary</code></li> | ||
<li><code>module.github["demo-repository"].github_branch.development</code></li> | ||
<li><code>module.github["demo-repository"].github_branch.main</code></li> | ||
<li><code>module.github["demo-repository"].github_repository.repository</code></li> | ||
<li><code>module.github["terraform-plan-summary"].github_branch.development</code></li> | ||
<li><code>module.github["terraform-plan-summary"].github_branch.main</code></li> | ||
<li><code>module.github["terraform-plan-summary"].github_repository.repository</code></li> | ||
</ul> | ||
</td> | ||
</tr> | ||
</table> | ||
<table> | ||
<tr> | ||
<th>CHANGE</th> | ||
<th>OUTPUT</th> | ||
</tr> | ||
<tr> | ||
<td>add</td> | ||
<td> | ||
<ul> | ||
<li><code>terraform_plan_summary_repository_name</code></li> | ||
</ul> | ||
</td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
invalid input flags: only one of -md, -json, or -html should be provided | ||
|
||
Usage of ./tf-summarize-test [args] [tf-plan.json|tfplan] | ||
|
||
-draw | ||
[Optional, used only with -tree or -separate-tree] draw trees instead of plain tree | ||
-html | ||
[Optional] print changes in html format | ||
-json | ||
[Optional] print changes in json format | ||
-md | ||
[Optional, used only with table view] output table as markdown | ||
-out string | ||
[Optional] write output to file | ||
-separate-tree | ||
[Optional] print changes in tree format for add/delete/change/recreate changes | ||
-tree | ||
[Optional] print changes in tree format | ||
-v print version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package writer | ||
|
||
import ( | ||
"io" | ||
"path" | ||
"text/template" | ||
|
||
"github.com/dineshba/tf-summarize/terraformstate" | ||
) | ||
|
||
// HTMLWriter is a Writer that writes HTML. | ||
type HTMLWriter struct { | ||
ResourceChanges map[string]terraformstate.ResourceChanges | ||
OutputChanges map[string][]string | ||
} | ||
|
||
// Write outputs the HTML summary to the io.Writer it's passed. | ||
func (t HTMLWriter) Write(writer io.Writer) error { | ||
templatesDir := "templates" | ||
rcTmpl := "resourceChanges.html" | ||
tmpl, err := template.New(rcTmpl).ParseFS(templates, path.Join(templatesDir, rcTmpl)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = tmpl.Execute(writer, t) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !hasOutputChanges(t.OutputChanges) { | ||
return nil | ||
} | ||
|
||
ocTmpl := "outputChanges.html" | ||
outputTmpl, err := template.New(ocTmpl).ParseFS(templates, path.Join(templatesDir, ocTmpl)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return outputTmpl.Execute(writer, t) | ||
} | ||
|
||
// NewHTMLWriter returns a new HTMLWriter with the configuration it's passed. | ||
func NewHTMLWriter(changes map[string]terraformstate.ResourceChanges, outputChanges map[string][]string) Writer { | ||
return HTMLWriter{ | ||
ResourceChanges: changes, | ||
OutputChanges: outputChanges, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<table> | ||
<tr> | ||
<th>CHANGE</th> | ||
<th>OUTPUT</th> | ||
</tr>{{ range $change, $outputs := .OutputChanges }}{{ $length := len $outputs }}{{ if gt $length 0 }} | ||
<tr> | ||
<td>{{ $change }}</td> | ||
<td> | ||
<ul>{{ range $i, $o := $outputs }} | ||
<li><code>{{ $o }}</code></li>{{ end }} | ||
</ul> | ||
</td> | ||
</tr>{{ end }}{{ end }} | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<table> | ||
<tr> | ||
<th>CHANGE</th> | ||
<th>RESOURCE</th> | ||
</tr>{{ range $change, $resources := .ResourceChanges }}{{ $length := len $resources }}{{ if gt $length 0 }} | ||
<tr> | ||
<td>{{ $change }}</td> | ||
<td> | ||
<ul>{{ range $i, $r := $resources }} | ||
<li><code>{{ $r.Address }}</code></li>{{ end }} | ||
</ul> | ||
</td> | ||
</tr>{{ end }}{{ end }} | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package writer | ||
|
||
import "embed" | ||
|
||
// Embed the templates directory in the compiled binary. | ||
// | ||
//go:embed templates | ||
var templates embed.FS | ||
|
||
func hasOutputChanges(opChanges map[string][]string) bool { | ||
hasChanges := false | ||
|
||
for _, v := range opChanges { | ||
if len(v) > 0 { | ||
hasChanges = true | ||
break | ||
} | ||
} | ||
|
||
return hasChanges | ||
} |
Oops, something went wrong.