diff --git a/terraform/template.go b/terraform/template.go index c355791..b542f50 100644 --- a/terraform/template.go +++ b/terraform/template.go @@ -3,6 +3,7 @@ package terraform import ( "bytes" htmltemplate "html/template" + texttemplate "text/template" ) const ( @@ -207,7 +208,13 @@ func (t *DefaultTemplate) Execute() (resp string, err error) { var b bytes.Buffer if t.UseRawOutput { - // do nothing + tpl, err := texttemplate.New("default").Parse(t.Template) + if err != nil { + return resp, err + } + if err := tpl.Execute(&b, data); err != nil { + return resp, err + } } else { tpl, err := htmltemplate.New("default").Parse(t.Template) if err != nil { @@ -235,7 +242,14 @@ func (t *FmtTemplate) Execute() (resp string, err error) { var b bytes.Buffer if t.UseRawOutput { - // do nothing + tpl, err := texttemplate.New("fmt").Parse(t.Template) + if err != nil { + return resp, err + } + + if err := tpl.Execute(&b, data); err != nil { + return resp, err + } } else { tpl, err := htmltemplate.New("fmt").Parse(t.Template) if err != nil { @@ -264,7 +278,14 @@ func (t *PlanTemplate) Execute() (resp string, err error) { var b bytes.Buffer if t.UseRawOutput { - // do nothing + tpl, err := texttemplate.New("plan").Parse(t.Template) + if err != nil { + return resp, err + } + + if err := tpl.Execute(&b, data); err != nil { + return resp, err + } } else { tpl, err := htmltemplate.New("plan").Parse(t.Template) if err != nil { @@ -313,7 +334,14 @@ func (t *ApplyTemplate) Execute() (resp string, err error) { var b bytes.Buffer if t.UseRawOutput { - // do nothing + tpl, err := texttemplate.New("apply").Parse(t.Template) + if err != nil { + return resp, err + } + + if err := tpl.Execute(&b, data); err != nil { + return resp, err + } } else { tpl, err := htmltemplate.New("apply").Parse(t.Template) if err != nil { diff --git a/terraform/template_test.go b/terraform/template_test.go index 97ce46c..fd98d8f 100644 --- a/terraform/template_test.go +++ b/terraform/template_test.go @@ -107,6 +107,50 @@ b
This is a "result".
 
+`, + }, + { + template: "", + value: CommonTemplate{ + Title: "a", + Message: "b", + Result: `This is a "result".`, + Body: "d", + UseRawOutput: true, + }, + resp: ` +a + +b + + + +
Details (Click me) + +
This is a "result".
+
+`, + }, + { + template: "", + value: CommonTemplate{ + Title: "a", + Message: "b", + Result: `This is a "result".`, + Body: "d", + UseRawOutput: true, + }, + resp: ` +a + +b + + + +
Details (Click me) + +
This is a "result".
+
`, }, { @@ -220,6 +264,25 @@ b This is a "result". +`, + }, + { + template: "", + value: CommonTemplate{ + Title: "a", + Message: "b", + Result: `This is a "result".`, + Body: "d", + UseRawOutput: true, + }, + resp: ` +a + +b + + + +This is a "result". `, }, { @@ -332,6 +395,28 @@ message
This is a "body".
 
+`, + }, + { + template: DefaultPlanTemplate, + value: CommonTemplate{ + Title: "title", + Message: "message", + Result: "", + Body: `This is a "body".`, + UseRawOutput: true, + }, + resp: ` +title + +message + + + +
Details (Click me) + +
This is a "body".
+
`, }, { @@ -572,6 +657,28 @@ message
This is a "body".
 
+`, + }, + { + template: "", + value: CommonTemplate{ + Title: "title", + Message: "message", + Result: "", + Body: `This is a "body".`, + UseRawOutput: true, + }, + resp: ` +title + +message + + + +
Details (Click me) + +
This is a "body".
+
`, }, {