May I know how to prevent the defined output not to display based on condition.?

I have a output defined something like:
output “example” {
value = {
try(module.example[0].id,"")
}
}
I want to avoid displaying this output if the module has count=0.please suggest.

I don’t think you can. Usually, in the consuming module, you handle the case where the output has a non-zero value (like an empty string in your example).

Thanks. when the number of output grows it looks messy in displaying all the outputs which has empty value. If the module run is avoided using count then it would be good to have something to avoid the outputs of that module from displayed based on some dependency. @apparentlymart do you have any suggestions.

There is nothing special about an “empty value” - it is just a value. Outputs will always have some value (even if empty string), which is important as there is a difference between an output not existing at all and it existing with a value of “” - if you try to reference a non-existent output (e.g. via remote state) you will get an error.

There is no way to switch on/off the creation of an output (in the same way that is isn’t possible to do so for a variable either). It is a static construct of the code, so if the block exists it will always have a value.

Remember also that “” as a value could have significance, rather than just being a placeholder for “no value”.

Thanks Stuart. I agree with you that the output is static similar to variables now. I am just curious If I pass count =0 to a module call to avoid it to be executed based on some condition , the outputs of that module will have no values. I have defined my output because in some scenarios it exist and in some scenario it won’t exist. I am forced to give “” value for output as the original output will not be available when the count for the module is set to 0 and it will throw error for non - existence.