Skip to content

fix(provisioner/terraform): decode Terraform action hook log lines - #31701

Draft
sreya wants to merge 1 commit into
mainfrom
fix-terraform-action-hook-logs
Draft

sreya wants to merge 1 commit into
mainfrom
fix-terraform-action-hook-logs

Conversation

@sreya

@sreya sreya commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Terraform 1.14 added actions. Their hook messages (action_start, action_progress, action_complete, action_errored) send hook.action as an object, but terraformProvisionLogHook.Action is a string. json.Unmarshal therefore fails on these lines, and parseTerraformLogLine falls back to logging the raw JSON line. As a result, every action line shows up in workspace build logs as a JSON blob, cut off at 1024 characters, instead of its @message.

This change decodes hook.action from either a string or an object, using the action's addr for objects, so action lines log their @message like other hook lines. Lines whose hook.action is neither shape still fall back to the raw line.

Found while building coder/terraform-provider-kubestream, a provider whose action streams pod startup progress into build logs.

Build log from a local Coder build of a template with an action, before and after

Before:

{"@level":"info","@message":"kubernetes_deployment_v1.main[0].trigger[0]: Action started: action.kubestream_wait.workspace","@module":"terraform.ui","@timestamp":"2026-11-03T07:40:39.822708Z","hook":{"action":{"addr":"action.kubestream_wait.workspace","module":"","action":"action.kubestream_wait.workspace","implied_provider":"ku…
{"@level":"info","@message":"kubernetes_deployment_v1.main[0] (0): action.kubestream_wait.workspace - [+10.0s] still waiting: pod/coder-3d8bf851-…-rkv9l Pending, PodScheduled=False (Unschedulable) for 10.8s","@module":"terraform.ui","@timestamp":"2026-11-03T07:40:49.841839Z","hook":{"action":{…

After:

kubernetes_deployment_v1.main[0].trigger[0]: Action started: action.kubestream_wait.workspace
kubernetes_deployment_v1.main[0] (0): action.kubestream_wait.workspace - [+10.0s] still waiting: pod/coder-ba75ea00-…-8cpx4 Pending, PodScheduled=False (Unschedulable) for 10.3s
kubernetes_deployment_v1.main[0] (0): action.kubestream_wait.workspace - [+17.3s] done in 17.3s: pod/coder-ba75ea00-…-8cpx4 scheduling 17.0s, image pull n/a, init 0s, start-to-ready 0s
kubernetes_deployment_v1.main[0] (0): Action complete: action.kubestream_wait.workspace

Action lines still produce the existing sampled "failed to extract timings" warning, because action_* isn't a timing kind. That is unchanged by this PR.

Note

This PR was written with an AI coding agent (Xum). I verified it with the new unit test (which fails without the fix) and with an end-to-end build on a local Coder deployment, shown above.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants