-
Notifications
You must be signed in to change notification settings - Fork 33
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 Signed-off-by: Mike Ball <mikedball@gmail.com>
- Loading branch information
Showing
10 changed files
with
151 additions
and
7 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,55 @@ | ||
package writer | ||
|
||
import ( | ||
"embed" | ||
"io" | ||
"path" | ||
"text/template" | ||
|
||
"github.com/dineshba/tf-summarize/terraformstate" | ||
) | ||
|
||
type HTMLWriter struct { | ||
ResourceChanges map[string]terraformstate.ResourceChanges | ||
OutputChanges map[string][]string | ||
} | ||
|
||
// Embed the entire templates directory in the compiled binary. | ||
// | ||
//go:embed templates | ||
var templates embed.FS | ||
|
||
// 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, $resources := .OutputChanges }}{{ $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,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,14 @@ | ||
package writer | ||
|
||
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