-
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
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>
- Loading branch information
Showing
11 changed files
with
183 additions
and
14 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
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,20 @@ | ||
<table> | ||
<tr> | ||
<th>CHANGE</th> | ||
<th>RESOURCE</th> | ||
</tr> | ||
<tr> | ||
<td>add</td> | ||
<td> | ||
<ul> | ||
<li>github_repository.terraform_plan_summary</li> | ||
<li>module.github["demo-repository"].github_branch.development</li> | ||
<li>module.github["demo-repository"].github_branch.main</li> | ||
<li>module.github["demo-repository"].github_repository.repository</li> | ||
<li>module.github["terraform-plan-summary"].github_branch.development</li> | ||
<li>module.github["terraform-plan-summary"].github_branch.main</li> | ||
<li>module.github["terraform-plan-summary"].github_repository.repository</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
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>{{ $o }}</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>{{ $r.Address }}</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 | ||
} |
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