Skip to content

Test assertion errors suppress values even with nonsensitive() #35961

@xyl0o

Description

@xyl0o

Terraform Version

Terraform v1.9.8
on linux_amd64

Terraform Configuration Files

# main.tf
variable "some_var" {
  type = string
}

variable "another_var" {
  type = string
}

variable "secret_var" {
  type      = string
  sensitive = true
}
# tests/sensitive_values.tftest.hcl
variables {
  some_var         = "some_value"
  another_var      = "another_value"
  secret_var       = "secret_value"
}

run "bare" {
  command = plan

  assert {
    condition     = var.some_var == "doesn't match"
    error_message = "some_var doesn't match static"
  }

  assert {
    condition     = var.some_var == var.another_var
    error_message = "some_var doesn't match another_var"
  }

  assert {
    condition     = var.secret_var == "doesn't match"
    error_message = "secret_var doesn't match static"
  }

  assert {
    condition     = var.some_var == var.secret_var
    error_message = "some_var doesn't match secret_var"
  }
}


run "with_non_sensitive" {
  command = plan

  assert {
    condition     = var.some_var == "doesn't match"
    error_message = "some_var doesn't match static"
  }

  assert {
    condition     = var.some_var == var.another_var
    error_message = "some_var doesn't match another_var"
  }

  assert {
    condition     = nonsensitive(var.secret_var) == "doesn't match"
    error_message = "secret_var doesn't match static"
  }

  assert {
    condition     = var.some_var == nonsensitive(var.secret_var)
    error_message = "some_var doesn't match secret_var"
  }
}

Debug Output

https://gist.github.com/xyl0o/8302b1e48630543b4b21fcf4b50a13db

Expected Behavior

The failed assertion doesn't print values that are sensitive:

╷
│ Error: Test assertion failed
│
│   on tests/sensitive_values.tftest.hcl line 26, in run "bare":
│   26:     condition     = var.some_var == var.secret_var
│     ├────────────────
│     │ var.some_var is "some_value"
│
│ some_var doesn't match secret_var
╵

But I'd expect to be able to see the value of both operands when using nonsensitive() - so something like this:

╷
│ Error: Test assertion failed
│
│   on tests/sensitive_values.tftest.hcl line 50, in run "with_non_sensitive":
│   50:     condition     = var.some_var == nonsensitive(var.secret_var)
│     ├────────────────
│     │ var.some_var is "some_value"
│     │ var.secret_var is "secret_value"
│
│ some_var doesn't match secret_var
╵

Actual Behavior

Using nonsensitive() has no effect:

╷
│ Error: Test assertion failed
│
│   on tests/sensitive_values.tftest.hcl line 50, in run "with_non_sensitive":
│   50:     condition     = var.some_var == nonsensitive(var.secret_var)
│     ├────────────────
│     │ var.some_var is "some_value"
│
│ some_var doesn't match secret_var
╵

Steps to Reproduce

terraform test --filter tests/sensitive_values.tftest.hcl

Additional Context

No response

References

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions