Skip to content

Commit

Permalink
Support UseRawOutput in destroy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
dtan4 committed Dec 26, 2019
1 parent 32abc03 commit 58cc54e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
20 changes: 9 additions & 11 deletions terraform/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions terraform/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,33 @@ 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
This plan contains resource delete operation. Please check the plan result very carefully!
<pre><code>result
<pre><code>This is a &#34;result&#34;.
</code></pre>
`,
},
{
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!
<pre><code>This is a "result".
</code></pre>
`,
Expand Down

0 comments on commit 58cc54e

Please sign in to comment.