Skip to content

emit apply change summary even on failure#38344

Open
purajit wants to merge 2 commits intohashicorp:mainfrom
purajit:20260403-json-summary-apply-error
Open

emit apply change summary even on failure#38344
purajit wants to merge 2 commits intohashicorp:mainfrom
purajit:20260403-json-summary-apply-error

Conversation

@purajit
Copy link
Copy Markdown

@purajit purajit commented Apr 4, 2026

Resolves #38343

Target Release

1.16.x

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

Testing/results

Besides unit tests, ran on my local terraform playground:

With this file

resource "null_resource" "will_succeed" {
}

resource "local_file" "will_fail" {
  filename = "/definitely/does/not/exist/out.txt"
  content  = ""
}

we used to get:

> terraform apply -auto-approve

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:

  # local_file.will_fail will be created
  + resource "local_file" "will_fail" {
      + content_base64sha256 = (known after apply)
      + content_base64sha512 = (known after apply)
      + content_md5          = (known after apply)
      + content_sha1         = (known after apply)
      + content_sha256       = (known after apply)
      + content_sha512       = (known after apply)
      + directory_permission = "0777"
      + file_permission      = "0777"
      + filename             = "/definitely/does/not/exist/out.txt"
      + id                   = (known after apply)
        # (1 unchanged attribute hidden)
    }

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

Plan: 2 to add, 0 to change, 0 to destroy.
null_resource.will_succeed: Creating...
local_file.will_fail: Creating...
null_resource.will_succeed: Creation complete after 0s [id=2020311957725937646]
╷
│ Error: Create local file error
│
│   with local_file.will_fail,
│   on main.tf line 4, in resource "local_file" "will_fail":
│    4: resource "local_file" "will_fail" {
│
│ An unexpected error occurred while creating file directory
│
│ +Original Error: mkdir /definitely: read-only file system
╵

> terraform apply -auto-approve -json
{"@level":"info","@message":"Terraform 1.14.7","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.435670-07:00","terraform":"1.14.7","type":"version","ui":"1.2"}
{"@level":"info","@message":"null_resource.will_succeed: Plan to create","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.559405-07:00","change":{"resource":{"addr":"null_resource.will_succeed","module":"","resource":"null_resource.will_succeed","implied_provider":"null","resource_type":"null_resource","resource_name":"will_succeed","resource_key":null},"action":"create"},"type":"planned_change"}
{"@level":"info","@message":"local_file.will_fail: Plan to create","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.559444-07:00","change":{"resource":{"addr":"local_file.will_fail","module":"","resource":"local_file.will_fail","implied_provider":"local","resource_type":"local_file","resource_name":"will_fail","resource_key":null},"action":"create"},"type":"planned_change"}
{"@level":"info","@message":"Plan: 2 to add, 0 to change, 0 to destroy.","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.559448-07:00","changes":{"add":2,"change":0,"import":0,"remove":0,"action_invocation":0,"operation":"plan"},"type":"change_summary"}
{"@level":"info","@message":"null_resource.will_succeed: Creating...","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.592476-07:00","hook":{"resource":{"addr":"null_resource.will_succeed","module":"","resource":"null_resource.will_succeed","implied_provider":"null","resource_type":"null_resource","resource_name":"will_succeed","resource_key":null},"action":"create"},"type":"apply_start"}
{"@level":"info","@message":"null_resource.will_succeed: Creation complete after 0s [id=2809849765760413623]","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.593045-07:00","hook":{"resource":{"addr":"null_resource.will_succeed","module":"","resource":"null_resource.will_succeed","implied_provider":"null","resource_type":"null_resource","resource_name":"will_succeed","resource_key":null},"action":"create","id_key":"id","id_value":"2809849765760413623","elapsed_seconds":0},"type":"apply_complete"}
{"@level":"info","@message":"local_file.will_fail: Creating...","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.593285-07:00","hook":{"resource":{"addr":"local_file.will_fail","module":"","resource":"local_file.will_fail","implied_provider":"local","resource_type":"local_file","resource_name":"will_fail","resource_key":null},"action":"create"},"type":"apply_start"}
{"@level":"info","@message":"local_file.will_fail: Creation errored after 0s","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.602363-07:00","hook":{"resource":{"addr":"local_file.will_fail","module":"","resource":"local_file.will_fail","implied_provider":"local","resource_type":"local_file","resource_name":"will_fail","resource_key":null},"action":"create","elapsed_seconds":0},"type":"apply_errored"}
{"@level":"error","@message":"Error: Create local file error","@module":"terraform.ui","@timestamp":"2026-04-03T16:18:38.610577-07:00","diagnostic":{"severity":"error","summary":"Create local file error","detail":"An unexpected error occurred while creating file directory\n\n+Original Error: mkdir /definitely: read-only file system","address":"local_file.will_fail","range":{"filename":"main.tf","start":{"line":4,"column":35,"byte":79},"end":{"line":4,"column":36,"byte":80}},"snippet":{"context":"resource \"local_file\" \"will_fail\"","code":"resource \"local_file\" \"will_fail\" {","start_line":4,"highlight_start_offset":34,"highlight_end_offset":35,"values":[]}},"type":"diagnostic"}

Now we get:

> ../../hashicorp/terraform/bin/terraform apply -auto-approve
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:

  # local_file.will_fail will be created
  + resource "local_file" "will_fail" {
      + content_base64sha256 = (known after apply)
      + content_base64sha512 = (known after apply)
      + content_md5          = (known after apply)
      + content_sha1         = (known after apply)
      + content_sha256       = (known after apply)
      + content_sha512       = (known after apply)
      + directory_permission = "0777"
      + file_permission      = "0777"
      + filename             = "/definitely/does/not/exist/out.txt"
      + id                   = (known after apply)
        # (1 unchanged attribute hidden)
    }

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

Plan: 2 to add, 0 to change, 0 to destroy.
null_resource.will_succeed: Creating...
null_resource.will_succeed: Creation complete after 0s [id=3755547938556189260]
local_file.will_fail: Creating...
╷
│ Error: Create local file error
│
│   with local_file.will_fail,
│   on main.tf line 4, in resource "local_file" "will_fail":
│    4: resource "local_file" "will_fail" {
│
│ An unexpected error occurred while creating file directory
│
│ +Original Error: mkdir /definitely: read-only file system
╵

Apply incomplete with errors! Resources: 1 added, 0 changed, 0 destroyed.

> echo $?
1

> ../../hashicorp/terraform/bin/terraform apply -auto-approve -json
{"@level":"info","@message":"Terraform 1.16.0-dev","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.220957-07:00","terraform":"1.16.0-dev","type":"version","ui":"1.3"}
{"@level":"info","@message":"null_resource.will_succeed: Plan to create","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.892383-07:00","change":{"resource":{"addr":"null_resource.will_succeed","module":"","resource":"null_resource.will_succeed","implied_provider":"null","resource_type":"null_resource","resource_name":"will_succeed","resource_key":null},"action":"create"},"type":"planned_change"}
{"@level":"info","@message":"local_file.will_fail: Plan to create","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.892441-07:00","change":{"resource":{"addr":"local_file.will_fail","module":"","resource":"local_file.will_fail","implied_provider":"local","resource_type":"local_file","resource_name":"will_fail","resource_key":null},"action":"create"},"type":"planned_change"}
{"@level":"info","@message":"Plan: 2 to add, 0 to change, 0 to destroy.","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.892447-07:00","changes":{"add":2,"change":0,"import":0,"remove":0,"action_invocation":0,"operation":"plan"},"type":"change_summary"}
{"@level":"info","@message":"null_resource.will_succeed: Creating...","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.929490-07:00","hook":{"resource":{"addr":"null_resource.will_succeed","module":"","resource":"null_resource.will_succeed","implied_provider":"null","resource_type":"null_resource","resource_name":"will_succeed","resource_key":null},"action":"create"},"type":"apply_start"}
{"@level":"info","@message":"local_file.will_fail: Creating...","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.929979-07:00","hook":{"resource":{"addr":"local_file.will_fail","module":"","resource":"local_file.will_fail","implied_provider":"local","resource_type":"local_file","resource_name":"will_fail","resource_key":null},"action":"create"},"type":"apply_start"}
{"@level":"info","@message":"null_resource.will_succeed: Creation complete after 0s [id=8397979251889827490]","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.930005-07:00","hook":{"resource":{"addr":"null_resource.will_succeed","module":"","resource":"null_resource.will_succeed","implied_provider":"null","resource_type":"null_resource","resource_name":"will_succeed","resource_key":null},"action":"create","id_key":"id","id_value":"8397979251889827490","elapsed_seconds":0},"type":"apply_complete"}
{"@level":"info","@message":"local_file.will_fail: Creation errored after 0s","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.937911-07:00","hook":{"resource":{"addr":"local_file.will_fail","module":"","resource":"local_file.will_fail","implied_provider":"local","resource_type":"local_file","resource_name":"will_fail","resource_key":null},"action":"create","elapsed_seconds":0},"type":"apply_errored"}
{"@level":"error","@message":"Error: Create local file error","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.945866-07:00","diagnostic":{"severity":"error","summary":"Create local file error","detail":"An unexpected error occurred while creating file directory\n\n+Original Error: mkdir /definitely: read-only file system","address":"local_file.will_fail","range":{"filename":"main.tf","start":{"line":4,"column":35,"byte":79},"end":{"line":4,"column":36,"byte":80}},"snippet":{"context":"resource \"local_file\" \"will_fail\"","code":"resource \"local_file\" \"will_fail\" {","start_line":4,"highlight_start_offset":34,"highlight_end_offset":35,"values":[]}},"type":"diagnostic"}
{"@level":"info","@message":"Apply incomplete with errors! Resources: 1 added, 0 changed, 0 destroyed.","@module":"terraform.ui","@timestamp":"2026-04-03T16:55:34.946403-07:00","changes":{"add":1,"change":0,"import":0,"remove":0,"action_invocation":0,"operation":"apply","errored":true},"type":"change_summary"}

> echo $?
1

@purajit purajit requested a review from a team as a code owner April 4, 2026 00:08
@hashicorp-cla-app
Copy link
Copy Markdown

hashicorp-cla-app Bot commented Apr 4, 2026

CLA assistant check
All committers have signed the CLA.

@crw
Copy link
Copy Markdown
Contributor

crw commented Apr 6, 2026

@purajit thanks for this submission. As a heads up, per our Contributing.md guide, any solution must be proposed in an issue and the solution accepted by a maintainer before opening a PR. Also per our Contributing.md guide, if you are using an LLM in any manner as part of this contribution, you need to disclose this information. Can you confirm this is or is not employing LLM-assisted coding tools? Thanks, this will help us proceed with triage!

@purajit
Copy link
Copy Markdown
Author

purajit commented Apr 15, 2026

As a heads up, per our Contributing.md guide, any solution must be proposed in an issue and the solution accepted by a maintainer before opening a PR.

Ah apologies for that; I read that as being for larger changes, though I understand as it
says that small changes could end up have larger implications. Shall I close this PR and
just post the logic diff in the issue?

if you are using an LLM in any manner as part of this contribution, you need to disclose this information. Can you confirm this is or is not employing LLM-assisted coding tools?

I used an LLM to confirm I hadn't missed any output format locations, but the code itself
was written by me (I'm still unsure how much I want to let them into my workflows). The
tests were mostly written by copy-paste-adjusting existing ones :P

@crw
Copy link
Copy Markdown
Contributor

crw commented Apr 16, 2026

Let's leave it open and I will bring it to triage. Thanks!

@purajit purajit changed the title emit apply change summary on failure emit apply change summary even on failure Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terraform apply should show summaries even on failures

2 participants