Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null is not equal to null #76

Closed
joshuaspence opened this issue Nov 20, 2024 · 2 comments · Fixed by #83
Closed

Null is not equal to null #76

joshuaspence opened this issue Nov 20, 2024 · 2 comments · Fixed by #83
Assignees
Labels
bug Something isn't working

Comments

@joshuaspence
Copy link

I am seeing provider::assert::null returning false when given a null value. Here is a simple example.

# main.tf
terraform {
  required_providers {
    assert = {
      source  = "hashicorp/assert"
      version = "0.14.0"
    }

    wireguard = {
      source  = "OJFord/wireguard"
      version = "0.3.1"
    }
  }
}

resource "wireguard_asymmetric_key" "main" {}

data "wireguard_config_document" "main" {
  private_key = wireguard_asymmetric_key.main.private_key
}
# tests/main.tftest.hcl
variables {
  null_value = null
}

run "wireguard_config_document" {
  assert {
    condition     = provider::assert::null(var.null_value)
    error_message = "Null should be null."
  }

  assert {
    condition     = provider::assert::null(data.wireguard_config_document.main.addresses)
    error_message = "Wireguard configuration does not have expected addresses."
  }
}

The output from terraform test is as follows:

tests/main.tftest.hcl... in progress
  run "wireguard_config_document"... fail
╷
│ Error: Test assertion failed
│ 
│   on tests/main.tftest.hcl line 12, in run "wireguard_config_document":
│   12:     condition     = provider::assert::null(data.wireguard_config_document.main.addresses)
│     ├────────────────
│     │ data.wireguard_config_document.main.addresses is null
│ 
│ Wireguard configuration does not have expected addresses.
╵
tests/main.tftest.hcl... tearing down
tests/main.tftest.hcl... fail

Failure! 0 passed, 1 failed.
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer label Nov 20, 2024
@bschaatsbergen
Copy link
Member

bschaatsbergen commented Nov 22, 2024

Hey @joshuaspence,

Thanks for reporting this! I’ll take a look at it as soon as possible. At first glance it appears to be a duplicate of #71, but I’ll investigate further and provide more details later, with the possibility of consolidating both issues into one.

@bschaatsbergen bschaatsbergen added bug Something isn't working and removed needs-triage Waiting for first response or review from a maintainer labels Nov 22, 2024
@bschaatsbergen bschaatsbergen self-assigned this Nov 22, 2024
@bschaatsbergen
Copy link
Member

Hi @joshuaspence,

Thank you for reporting this issue. In v0.15.0, we merged a fix to evaluate the underlying value as null, which is necessary for cross-object references. Previously, the dynamic value of an argument was evaluated as either null or not. Additionally, we’ve disabled the allowance of unknown values being passed into not_null, which helps protect users from flaky assertions on argument references that may be unknown but could potentially be null or not.

It would be greatly appreciated if you could test this and let us know if it resolves your issue. I’ve also added a test to the null function that includes your provided Wireguard example, where addresses is always set to null. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants