terraform plan/apply result in GitHub comment is parsed as Markdown
dtan4 opened this issue · 3 comments
WHAT
Make terraform plan|apply
result output print in GitHub comment as it is, not to render as Markdown text.
WHY
Currently terraform plan|apply
result notified as GitHub comment is parsed as Markdown text, not as plain text.
This causes transformation from some formatted text, e.g. plugin list, resources to diff and separator line, to HTML lists or separators.
Please look at the below examples.
enclose with <pre><code>
(current state)
Details (Click me)
Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "pagerduty" (1.1.0)...
- Downloading plugin for provider "aws" (1.16.0)...
- Downloading plugin for provider "google" (1.10.0)...
The following providers do not have any version constraints in configuration,
so the latest version was installed.To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
- provider.aws: version = "~> 1.16"
- provider.google: version = "~> 1.10"
- provider.pagerduty: version = "~> 1.1"
Terraform has been successfully initialized!
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-placePlan: 0 to add, 2 to change, 0 to destroy.
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
enclose with backquotes
Since using the same body with above, HTML character entities are appeared as it is.
Details (Click me)
Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "pagerduty" (1.1.0)...
- Downloading plugin for provider "aws" (1.16.0)...
- Downloading plugin for provider "google" (1.10.0)...
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
* provider.aws: version = "~> 1.16"
* provider.google: version = "~> 1.10"
* provider.pagerduty: version = "~> 1.1"
Terraform has been successfully initialized!
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
Plan: 0 to add, 2 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
One solution is using triple backquotes. I prefer this solution.
Another solution is replacing all special characters to HTML character entities.
@dtan4 Thank you for your report.
One solution is using triple backquotes. I prefer this solution.
Yes, I know.
Now, I'm using backquotes for string literals.
tfnotify/terraform/template.go
Lines 45 to 59 in ecebe34
It's true that I'd like to use backquotes in string literals but I don't know how to use it in string literals like this:
DefaultPlanTemplate = `
{{ .Title }}
{{ .Message }}
{{if .Result}}
```
{{ .Result }}
```
{{end}}
<details><summary>Details (Click me)</summary>
```
{{ .Body }}
```
</details>
`
How can I use triple backquotes in backquotes (string literals)?
Yes, triple backquotes cannot be written in raw string literal.
We can concatenate both interpreted string literals and raw string literals.
So how about this:
DefaultPlanTemplate = `
{{ .Title }}
{{ .Message }}
{{if .Result}}
` + "```" + `
{{ .Result }}
` + "```" + `
{{end}}
<details><summary>Details (Click me)</summary>
` + "```" + `
{{ .Body }}
` + "```" + `
</details>
`
Hi. I also suffer from the same problem with the template examples in README.md . This issue would be solved if an empty line is added after the </summary>
tag. Show an example below.
Add no empty lines
Details (Click me)
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
aws_instance.example: Refreshing state...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
aws_instance.example will be created
+ resource "aws_instance" "example" {
+ instance_type = "t3.micro"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
Add an empty line
Details (Click me)
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
aws_instance.example: Refreshing state...
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_instance.example will be created
+ resource "aws_instance" "example" {
+ instance_type = "t3.micro"
}
Plan: 1 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
Pull request #45 is to fix this problem in the all template examples and the default templates within this repository. Please look at it.