Skip to content

terraform test crashes when an assertion fails on a deprecation-marked value #39239

Closed as not planned

Description

@SchulteDev

Terraform Version

Terraform v1.16.3
on windows_amd64
+ provider registry.terraform.io/hashicorp/azurerm v3.117.1

Also reproduced with v1.16.1.

Terraform Configuration Files

main.tf:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.117.1"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "rg-example"
  location = "westeurope"
}

# Deprecated in favour of azurerm_static_web_app.
resource "azurerm_static_site" "swa" {
  name                = "swa-example"
  resource_group_name = azurerm_resource_group.rg.name
  location            = azurerm_resource_group.rg.location
}

tests/deprecated.tftest.hcl:

mock_provider "azurerm" {}

run "failing_assertion_on_a_deprecated_resource" {
  command = plan

  assert {
    condition     = azurerm_static_site.swa.name == "never-matches"
    error_message = "expected to read this message"
  }
}

Panic Output

panic: unexpected error marshalling value: value has marks, so it cannot be serialized as JSON
goroutine 118 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/hashicorp/terraform/internal/logging.PanicHandler()
	github.com/hashicorp/terraform/internal/logging/panic.go:84 +0x18a
panic({0x?, 0x?})
	runtime/panic.go:860 +0x13a
github.com/hashicorp/terraform/internal/moduletest/graph.Walk.func1.1()
	github.com/hashicorp/terraform/internal/moduletest/graph/test_graph_builder.go:117 +0x168
panic({0x?, 0x?})
	runtime/panic.go:860 +0x13a
github.com/hashicorp/terraform/internal/command/views/json.NewDiagnostic({0x?, 0x?}, 0x?)
	github.com/hashicorp/terraform/internal/command/views/json/diagnostic.go:278 +0x18de
github.com/hashicorp/terraform/internal/command/format.Diagnostic(...)
	github.com/hashicorp/terraform/internal/command/format/diagnostic.go:35 +0x27
github.com/hashicorp/terraform/internal/command/views.(*View).formatDiagnostic(...)
	github.com/hashicorp/terraform/internal/command/views/view.go:243 +0xd9
github.com/hashicorp/terraform/internal/command/views.(*TestHuman).Run(...)
	github.com/hashicorp/terraform/internal/command/views/test.go:247 +0xa67
github.com/hashicorp/terraform/internal/moduletest/graph.(*NodeTestRun).Execute(...)
	github.com/hashicorp/terraform/internal/moduletest/graph/node_test_run.go:147 +0x4b8

Expected Behavior

The run fails, printing the assertion's error_message and the values involved, as it does for any other failing assertion.

Actual Behavior

Terraform crashes while rendering the failed assertion and exits with code 11. No failure message, no test summary.

Steps to Reproduce

  1. terraform init -backend=false
  2. terraform test

Additional Context

Only an assertion that reads the deprecation-marked value crashes, and only when it fails. In the same configuration, a failing assertion on azurerm_resource_group.rg.name prints normally, deprecation warning included, so the crash is in rendering the diagnostic rather than in evaluating the assertion.

The same crash occurs for a deprecated attribute rather than a whole resource, e.g. storage_account_name on azurerm_storage_container with azurerm 4.x.

In CI this is worse than a lost message: with command = apply, the crash replaces the run's failure output and skips the cleanup of everything the test already created.

Possibly related, same function but a different cause (nil pointer at diagnostic.go:449, fixed in #37071): #37059.

Activity

  1. SchulteDev commented on Sep 17, 2026

    @SchulteDev
    Author

    Closing this for now: I reproduced it against an older azurerm provider, and I'd rather re-check on the current one before asking anyone to spend time on it. If it still crashes there, I'll reopen with a fresh repro.

  2. github-actions commented on Oct 18, 2026

    @github-actions
    Contributor

    I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
    If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

  3. locked as resolved and limited conversation to collaborators on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions