-
Notifications
You must be signed in to change notification settings - Fork 907
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
default attribute values of object variables are ignored in tests #2018
Comments
Looking at the example from the original issue, I'd note that as currently written that test ought to also fail for a different reason, because:
If the test harness were correctly setting run "root_disk_var" {
command = plan
variables {
root_disk = {
size = 60
}
}
assert {
# This variation would fail immediately if any new
# attributes were added to the variable's type
# constraint in future.
condition = var.root_disk == {
size = 60
type = "gp3"
iops = tonumber(null)
throughput = tonumber(null)
}
error_message = "Value is incorrect"
}
} run "root_disk_var" {
command = plan
variables {
root_disk = {
size = 60
}
}
# This variation tolerates the addition of new attributes
# without failing, by testing each attribute separately.
assert {
condition = (var.root_disk.size == 60)
error_message = "Size is incorrect"
}
assert {
condition = (var.root_disk.type == "gp3")
error_message = "Type is incorrect"
}
assert {
condition = (var.root_disk.iops == tonumber(null))
error_message = "IOps is incorrect"
}
assert {
condition = (var.root_disk.throughput == tonumber(null))
error_message = "Throughput is incorrect"
}
} It seems like at the moment the bug reported by this issue is masking this problem. I'm mentioning it here only in the hope that it's helpful to someone working on this issue in future, since there is more than one way for the given example to fail and so it starting to fail does not necessarily mean that the bug is fixed. |
Hey @cam72cam, may I take a look at this? |
Hey @AdosH1 thank you for volunteering! Let me assign you, but before opening a PR, please describe your approach here so we can sync on the chosen implementation path. |
@ollevche In terms of the solution, I think the I don't have a strong opinion for ApparentlyMart's assertation methodology, but leaning towards the exact object matching given its for the test command (which we have full control over inputs) |
Hey @AdosH1! Sorry for delay with reply from my side. I think to resolve this particular issue (type defaults are not being applied to test variables), we need to extend Object comparison is out of the scope of this particular bug in my opinion. |
Thanks ollevche, I will take a look in the coming week 🙏 |
OpenTofu Version
OpenTofu Configuration Files
main.tf
tests.tftest.hcl
Debug Output
terraform.tfvars
tofu console
Expected Behavior
Test should fail since
root_disk
object has default value fortype
attribute.Actual Behavior
Test is successful even though the attribute with a default value is missing.
Steps to Reproduce
tofu test
Additional Context
No response
References
No response
The text was updated successfully, but these errors were encountered: