Closed mdb closed 3 months ago
@mdb Buildkite prints our own terraform plans as a build annotation, so I had a look to see what we do that seems to work.
It's done via a ruby script so the syntax is slightly different, but :
summary = capture!("terraform", "show", "plan.out")
# Terraform 0.15 introduced a whole lot of useless noisy output about
# drift which has been ignored before the actual plan output. Throw
# away the noise. There's a big horizontal rule of `-----` in the middle.
summary = summary.split(/^─{10,}(?:\e\[0m)?\n/).last.strip
annotation = <<~MARKDOWN
Terraform determines the following changes need to be made:
\```term
#{summary}
\```
MARKDOWN
system!("buildkite-agent", "annotate", "--style", "warning", stdin_data: annotation)
Could you use the term
code block as a workaround, maybe with using terraform show
as well?
Hi @mdb, if @yob's suggestion doesn't work for you, we'd be interested in taking a look at the job or at least the raw annotation data. You can email support@buildkite.com with the details, and refer to this issue, so we can see the specifics of your case.
Hi @mdb, if @yob's suggestion doesn't work for you, we'd be interested in taking a look at the job or at least the raw annotation data. You can email support@buildkite.com with the details, and refer to this issue, so we can see the specifics of your case.
Unfortunately, @yob 's suggestion doesn't work, as I'd like to also include a <details>
HTML dropdown in the annotation, yet it seems Buildkite fails to properly render markdown inside annotations that include a mix of markdown code fences and HTML.
However, after lotsa lotsa lotsa trial/error, I was able to accomplish what I'm after via echo -e
😄 :
html_plan="$(terminal-to-html < plan.log)"
plan_annotation=$(echo -e "<h4>Terraform plan</h4> \
<details>
<summary>Terraform Plan</summary> \
<pre class=\"term\"> \
<code> \
${html_plan} \
</code> \
</pre> \
</details>")
buildkite-agent annotate \
"${plan_annotation}" \
--style "info" \
--context "plan"
Thanks for your work on
terminal-to-html
! I'd like to surface ansi-color-encoded Terraformplan
s as Buildkite annotations, and am using the terraform-to-html CLI to do so via bash similar to the following, whereplan.log
is the output of aterraform plan
invocation:However, the plan formatting gets a bit mangled and over-styled, and looks like the following example within the annotation (note the inconsistent text size/styling, as well as odd indentation). Ideally, the annotation would depict the
plan
output just as it appears in the Buildkite step output (and how it renders in my terminal when I invoketerraform plan
).Thanks!