A (mishandled) use case would be a function like isPDF(filename), where true and false represent if the file is a PDF and fileNotFound is for if the file doesn't exist. But I agree, it's confusing design, and with the tools we have today we have better ways to handle fileNotFound than as a third value for a boolean enum.
The type and default are sufficient in terraform to do the same, the validation will never be hit I don't believe because terraform itself will throw out the run due to a type mismatch. It also coerces the string "true" to the bool (and vice-versa when the variable is set to a string).
variable "enabled_for_disk_encryption" {
type = bool
default = true
description = "Boolean flag to specify whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys."
validation {
condition = var.enabled_for_disk_encryption == true || var.enabled_for_disk_encryption == false
error_message = "The only allowed values are: true and false"
}
}
2
u/Zitrusfleisch Apr 27 '23
Is this terraform?
65
u/emmettm42 Apr 26 '23
Seems pretty lenient to me
51
u/dopefish86 Apr 26 '23
maybe it could also be null?
43
u/imtn Apr 26 '23
I can understand why someone would write this, since obviously booleans can be True, False, or FileNotFound
33
u/Sanduhr32 Apr 26 '23
If this is a dynamically typed language & dynamically typed from the config, then this excludes all invalid types & null state.
23
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Apr 26 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
3
u/CaitaXD Apr 27 '23
Defaulting to true... You walking on thin ice buddy
1
u/Optical_enigma Apr 28 '23
It looks more like a gui toggle prompt that would be nested in the application/os settings
0
u/Reasonable-Lawyer223 Apr 27 '23
Instead of == it should be !=