// Why this matters
If you want terraform plan json to markdown in your pull requests, you are probably already feeling the review problem: raw plan output is thousands of lines, reviewers stop reading, and the one resource marked "must be replaced" goes unnoticed. A short, structured summary changes what review is able to catch.
The second tool solves a different but equally daily irritation. Private Kubernetes clusters are the right default, but they turn "run a kubectl command" into a multi-step ritual of VPN, jump host, kubeconfig editing and role activation. Done by hand, people take shortcuts: shared kubeconfigs, public endpoints "just for now", tokens in chat.
Both are small enough to build in a day and pay back every day after. They are also a good example of platform work that is not a product but changes how the team behaves.
// The problem
Plan review fails in predictable ways. A reviewer opens a pipeline log and scrolls through attribute-level diffs. Sensitive values are masked, computed values are noisy, and forced replacements are a single line in a very long page. There is no way to ask "how many resources are being destroyed?" without reading everything.
Cluster access fails in a different way. The API server is private, the bastion lives in a hub network, and the operator needs the right role on the bastion, on the cluster and on the namespace. Credentials produced by az aks get-credentials default to a device-code login that prompts constantly. People leave tunnels running in forgotten terminals and later run commands against the wrong cluster.
We want both to be boring: a single command, a deterministic result, and cleanup that does not depend on the operator's memory.
// The solution
For plan rendering, the tool reads the JSON produced by terraform show -json plan.out. Its resource_changes array has, for each resource, an address, a type and a change.actions list such as ["create"], ["update"], ["delete","create"] (a replacement) or ["no-op"]. The renderer filters no-ops, buckets by action, sorts replacements and deletes first, and writes a Markdown summary table followed by collapsible sections per action. It writes to stdout so the CI step decides where it goes.
We chose Go for the renderer because a single static binary is trivial to pull into any pipeline image and the Terraform plan JSON is easy to model with structs. We rejected parsing the human text plan (format changes between versions) and third-party SaaS plan viewers (data leaves the boundary, and some cost money). Attribute-level diffs are included only for updates, with sensitive values already masked by Terraform.
For cluster access, the script performs the same sequence an operator would, but safely. It discovers the private clusters from the subscriptions the operator can see, asks which one, switches to the hub subscription that owns the Bastion, opens az network bastion tunnel to the cluster's API host on a fixed local port, fetches credentials, rewrites the kubeconfig server to the local port, and traps exit to stop the tunnel and restore the backup. Authentication uses kubelogin in azurecli mode so there is no device-code prompt, and authorisation is Azure RBAC for Kubernetes, so access is a role assignment that can be time-boxed through eligible roles.
Both tools slot into the wider platform: the Markdown output feeds the review gates described in From Form to Running Cluster: Self-Service Team Onboarding and One Reusable Plan/Apply Workflow for Cost-Optimised Autoscaling, and the tunnel is how operators perform the checks in Demolition in Dependency Order: Safe, Re-runnable Offboarding.
- terraform plansaved to a binary plan file
- terraform show -jsonstructured plan document
- RenderGo tool groups by action and type
- CommentMarkdown posted to the pull request
- Gate: human review gatereviewer reads the summary, not 4000 lines
- Operator sign-inaz login with an eligible role activated
- TunnelBastion forwards a local port to the private API
- Kubeconfigserver rewritten to the local port, backup kept
- CleanupCtrl+C restores the old kubeconfig
// Before you start
- Go 1.22+ to build the renderer, or a prebuilt binary in your runner image.
- Terraform 1.5+ with a pipeline that can save a plan file.
- Azure CLI 2.50+ with the
bastionandsshextensions,kubectlandkubelogin. - A Bastion host (Standard SKU or higher, with native client support and tunnelling enabled) in the hub network.
- Azure RBAC for Kubernetes enabled on the clusters, and eligible roles for the operator.
- Permission to comment on pull requests from CI (a GitHub token with
pull-requests: write).
// Step-by-step implementation
01 Produce a machine-readable plan in CI
Everything starts with saving the plan file and converting it to JSON. Use
-outso what you review is what you apply, and-no-colorso any text logs stay clean. The JSON is the contract with the renderer.Keep the plan file as a pipeline artifact; the apply job should consume that exact file.
02 Model the plan JSON in Go
You only need a few fields, so define small structs and ignore the rest. Decoding into
map[string]anyfor the before/after values lets you diff attributes without modelling every provider schema.Classify actions: a change with
deleteandcreateis a replacement, which deserves its own bucket because it is the dangerous one.03 Render the Markdown summary
Lead with counts, then list the risky buckets expanded and the harmless ones collapsed using
<details>. GitHub renders this natively. For updates, list changed attribute names only; values may be large or sensitive.GitHub comments have a size limit (about 65,000 characters), so truncate long lists with a clear "and N more" line.
04 Post the summary to the pull request
In CI, run the renderer and upsert a single comment identified by a hidden marker, so each push updates the comment rather than adding a new one. A sticky comment keeps the thread readable.
Grant only
pull-requests: writeto the job; the plan job does not need repository write access.05 Write the Bastion tunnel script for private AKS
The script must be safe to interrupt. Back up the kubeconfig before touching it, start the tunnel in the background, and register a trap that stops the tunnel and restores the backup on any exit. Use a fixed local port so the rewritten kubeconfig is predictable; the trade-off is one cluster at a time, which is a feature when you are working on production.
The Bastion lives in the hub subscription, the cluster in a workload subscription, so the script must switch subscriptions between steps.
06 Activate roles, then verify and use it
If your Azure roles are eligible (PIM) rather than permanent, activate them first and wait a minute; a stale session looks exactly like missing permissions. Run the script, leave that terminal open, and use a second terminal for
kubectl.In production clusters, grant application teams read-only roles; the tunnel changes the path, not the authority.
// How to verify it works
jqonplan.jsonshowsresource_changes, and the rendered Markdown summary counts match the counts fromterraform planoutput.- A plan that forces replacement lists the resource under the open "replace" section.
- The pull request shows exactly one plan comment that updates in place after a second push.
lsof -nP -iTCP:9999 -sTCP:LISTENshows the tunnel while the script runs and nothing after Ctrl+C.kubectl config current-contextreturns your original context after the script exits, andkubectl get nsworks while it runs without a device-code prompt.
// Design decisions and trade-offs
- Render the plan from the machine-readable JSON, never by parsing the human plan text.
- Summarise by action and resource type first; details fold away so large plans stay reviewable.
- Private cluster access goes through a Bastion tunnel and Azure RBAC, so no API server is ever exposed and no kubeconfig certificate is shared.
- The tunnel script restores the previous kubeconfig on exit; operators never end up pointed at the wrong cluster silently.
- Tools are small, single-binary or single-file, and live in the repo they serve.
// Pitfalls and lessons learned
- Plan JSON contains values marked sensitive as unknown/redacted, but
before/aftercan still hold surprising data. Do not print attribute values by default. - A plan with
-targetor-refresh=falseis not the full picture. Render the same plan you intend to apply and say so in the comment. - Port 9999 already in use (a forgotten tunnel) produces "Tunnel failed to start"; one tunnel at a time is by design, so find and stop the old one.
- Certificate name mismatch when talking through localhost: set
--tls-server-namerather than disabling verification. - Without
kubelogin convert-kubeconfig -l azurecli, every command asks for a device code and operators will hit the wrong prompt and give up. - Bastion needs the Standard SKU with native client support enabled; Basic will not tunnel and the error message does not say why.
- Never paste kubeconfigs or tokens into tickets or chat; the script keeps them local on purpose.
// Frequently asked questions
How do I convert terraform plan json to markdown?
Run terraform plan -out, then terraform show -json on the plan file, and render resource_changes grouped by change.actions; the Go example above does exactly that.
Why not parse the text output of terraform plan?
The human format is not a stable interface and changes between versions; the JSON representation is documented and versioned.
How do I access a private AKS cluster without a VPN?
Use Azure Bastion native-client tunnelling to forward a local port to the private API server and point kubeconfig at that port.
Does kubelogin work with Azure RBAC for Kubernetes?
Yes. Use the azurecli login mode so kubectl reuses your az session and authorisation comes from role assignments.
Can I run the tunnel for two clusters at once?
You can by using different local ports and contexts, but for production access a single fixed port is a deliberate guard against running commands on the wrong cluster.
// The outcome
Pull requests carry a readable summary of what a Terraform change will do, and operators can reach any private cluster they are entitled to with one command, with access governed by role assignments rather than shared credentials.
// Where to take it next
- Add a policy check (OPA or Checkov) over the same plan JSON and fail the job on forbidden deletes.
- Colour-code replacements and attach cost estimates if your pipeline already has pricing data.
- Wrap onboarding and offboarding tasks in scripts that use the same tunnel; see From Form to Running Cluster: Self-Service Team Onboarding.
- See how review gates and guard rails fit together in Guardrails and Engineering Telemetry: Org Policy, Project Factory, Gatekeeper, Four Keys.