suzuki-shunsuke / tfcmt

tfcmt enhances mercari/tfnotify in many ways, including Terraform >= v0.15 support and advanced formatting options
https://suzuki-shunsuke.github.io/tfcmt/
Other
419 stars 45 forks source link

"tfcmt failed" error="html/template:default:12:11: no such template \"error_message\" #1490

Closed sonatard closed 6 days ago

sonatard commented 1 week ago

tfcmt version

$ tfcmt -v
v4.14.0

Environment

Overview

I set up the configuration referring to the example, but it resulted in an error.

https://suzuki-shunsuke.github.io/tfcmt/config#example-configuration

How to reproduce

  tfcmt \
            -var target:${{ env.GOOGLE_CLOUD_PROJECT }} \
            -config .tfcmt.yaml \
            plan -patch -skip-no-changes \
            -- terraform plan -lock=false
terraform:
  templates:
    changed_result: |
      {{if .ChangedResult}}
      <details><summary>Change Result (Click me)</summary>
      {{wrapCode .ChangedResult}}
      </details>
      {{end}}
    change_outside_terraform: |
      {{if .ChangeOutsideTerraform}}
      <details><summary>:warning: Note: Objects have changed outside of Terraform</summary>
      {{wrapCode .ChangeOutsideTerraform}}
      </details>
      {{end}}
    warning: |
      {{if .Warning}}
      ## :warning: Warnings :warning:
      {{wrapCode .Warning}}
      {{end}}
    error_message: |
      {{if .ErrorMessages}}
      ## :warning: Errors
      {{range .ErrorMessages}}
      * {{. -}}
      {{- end}}{{end}}
  plan:
    template: |
      aiueo
      {{template "plan_title" .}}

      {{if .Link}}[CI link]({{.Link}}){{end}}

      {{template "result" .}}
      {{template "updated_resources" .}}

      {{template "changed_result" .}}
      {{template "change_outside_terraform" .}}
      {{template "warning" .}}
      {{template "error_message" .}}
    when_destroy:
      template: |
        abcde
        {{template "plan_title" .}}

        {{if .Link}}[CI link]({{.Link}}){{end}}

        {{template "deletion_warning" .}}

        {{template "result" .}}
        {{template "updated_resources" .}}

        {{template "changed_result" .}}
        {{template "change_outside_terraform" .}}
        {{template "warning" .}}
        {{template "error_message" .}}
    when_no_changes:
      disable_label: true

Debug output

$ 

Expected behaviour

no error

Actual behaviour

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now. time="2024-11-23T16:41:33Z" level=error msg="tfcmt failed" error="html/template:default:12:11: no such template \"error_message\"" Error: Process completed with exit code 1.

Important Factoids

No response

Note

No response

suzuki-shunsuke commented 1 week ago

Thank you for your report!

  1. I could reproduce the issue.

tfcmt.yaml

terraform:
  templates:
    error_message: |
      {{if .ErrorMessages}}
      ## :warning: Errors
      {{range .ErrorMessages}}
      * {{. -}}
      {{- end}}{{end}}
  plan:
    template: |
      {{template "error_message" .}}

main.tf

resource "null_resource" "foo" {}
terraform init
$ tfcmt plan -- terraform plan

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # null_resource.foo will be created
  + resource "null_resource" "foo" {
      + id = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.
ERRO[0001] tfcmt failed                                  error="html/template:default:1:11: no such template \"error_message\""
  1. I found the document is wrong. I could resolve the issue by modifying the configuration file.
templates:
  error_message: |
    {{if .ErrorMessages}}
    ## :warning: Errors
    {{range .ErrorMessages}}
    * {{. -}}
    {{- end}}{{end}}
terraform:
  plan:
    template: |
      {{template "error_message" .}}
suzuki-shunsuke commented 6 days ago

I found the document is wrong.

This was my misunderstanding. The document is correct.