From 58cc54e063eec886435b008a35b1dcb0e1016dc9 Mon Sep 17 00:00:00 2001 From: Daisuke Fujita Date: Thu, 26 Dec 2019 12:30:49 +0900 Subject: [PATCH] Support UseRawOutput in destroy warning --- terraform/template.go | 20 +++++++++----------- terraform/template_test.go | 22 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/terraform/template.go b/terraform/template.go index 9eaba92..490b946 100644 --- a/terraform/template.go +++ b/terraform/template.go @@ -274,23 +274,21 @@ func (t *PlanTemplate) Execute() (string, error) { } // Execute binds the execution result of terraform plan into template -func (t *DestroyWarningTemplate) Execute() (resp string, err error) { - tpl, err := htmltemplate.New("destroy_warning").Parse(t.Template) - if err != nil { - return resp, err - } - var b bytes.Buffer - if err := tpl.Execute(&b, map[string]interface{}{ +func (t *DestroyWarningTemplate) Execute() (string, error) { + data := map[string]interface{}{ "Title": t.Title, "Message": t.Message, "Result": t.Result, "Body": t.Body, "Link": t.Link, - }); err != nil { - return resp, err } - resp = b.String() - return resp, err + + resp, err := generateOutput("destroy_warning", t.Template, data, t.UseRawOutput) + if err != nil { + return "", err + } + + return resp, nil } // Execute binds the execution result of terraform apply into tepmlate diff --git a/terraform/template_test.go b/terraform/template_test.go index fd98d8f..c947061 100644 --- a/terraform/template_test.go +++ b/terraform/template_test.go @@ -485,7 +485,7 @@ This plan contains resource delete operation. Please check the plan result very template: DefaultDestroyWarningTemplate, value: CommonTemplate{ Title: "title", - Result: "result", + Result: `This is a "result".`, }, resp: ` title @@ -493,7 +493,25 @@ title This plan contains resource delete operation. Please check the plan result very carefully! -
result
+
This is a "result".
+
+ +`, + }, + { + template: DefaultDestroyWarningTemplate, + value: CommonTemplate{ + Title: "title", + Result: `This is a "result".`, + UseRawOutput: true, + }, + resp: ` +title + +This plan contains resource delete operation. Please check the plan result very carefully! + + +
This is a "result".
 
`,