You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are using functions such as (but not limited to) jsondecode within a for_each resource and one of the supplied values is erroneous, you cannot tell which supplied value is erroneous. in more complex scenarios than this contrived example, it can make finding the faulty values extremely tedious and time consuming.
$terraform validate
Error: Error in function call
on test.tf line 6, in locals:
6: key => jsondecode(value)
Call to function "jsondecode" failed: invalid character '}' after object key.
Error: Error in function call
on test.tf line 6, in locals:
6: key => jsondecode(value)
Call to function "jsondecode" failed: EOF.
Attempted Solutions
Proposal
Upon error, dump the input parameters of the particular function failure; even better in this case would be to also dump the variables in scope (key,value).
Potential output:
$terraform validate
Error: Error in function call
on test.tf line 6, in locals:
6: key => jsondecode(value)
Call to function "jsondecode" failed: invalid character '}' after object key. jsonencode called with value '{"x"}'
Error: Error in function call
on test.tf line 6, in locals:
6: key => jsondecode(value)
Call to function "jsondecode" failed: EOF. jsonencode called with value ''.
This would at least give the developer a clue.
References
The text was updated successfully, but these errors were encountered:
The way we typically solve this problem is for the error messages to systematically include either full values (for primitive types) or summaries (for complex types) of all of the external values that contributed to the expression that failed. We do it this way both to make it consistent and comprehensive and because the diagnostic printer is able to take into account when a particular value is marked as sensitive and thus omit it, which the various different functions would not necessarily handle correctly.
I tried something like what you shared here and saw an error message which includes such an annotation:
$ terraform plan
Error: Error in function call
on jsonencode-fails.tf line 6, in output "example":
6: value = jsondecode(local.raw)
|----------------
| local.raw is "{"
Call to function "jsondecode" failed: EOF.
locals {
raw ="{"
}
output"example" {
value =jsondecode(local.raw)
}
However, when I tried your example exactly as you gave it, neither of the error messages included that annotation:
$ terraform plan
Error: Error in function call
on jsonencode-fails.tf line 6, in locals:
6: key => jsondecode(value)
Call to function "jsondecode" failed: invalid character '}' after object key.
Error: Error in function call
on jsonencode-fails.tf line 6, in locals:
6: key => jsondecode(value)
Call to function "jsondecode" failed: EOF.
With that said, I'd like to respond to this request by understanding why Terraform isn't reporting the value of value in your more complex situation. My initial theory is that it's because value belongs to a local scope created by the for expression and so perhaps the language runtime isn't handling that correctly, but from an initial read of the relevant code I wasn't able to quickly determine why that might be. (The EvalContext here should be the same one that was used to evaluate the arguments, and so it should include the value symbol.)
I won't have time to debug this further today, but hopefully what I've written here is useful to either future me or someone else who is motivated to work on this some more in the future.
Current Terraform Version
0.13.5
Use-cases
If you are using functions such as (but not limited to) jsondecode within a for_each resource and one of the supplied values is erroneous, you cannot tell which supplied value is erroneous. in more complex scenarios than this contrived example, it can make finding the faulty values extremely tedious and time consuming.
example:
actual output:
Attempted Solutions
Proposal
Upon error, dump the input parameters of the particular function failure; even better in this case would be to also dump the variables in scope (key,value).
Potential output:
This would at least give the developer a clue.
References
The text was updated successfully, but these errors were encountered: