Problem
Terraform apply fails with: "Call to function coalesce
failed: no non-null, non-empty-string arguments"
As per the documentation, the function coalesce has the following syntax:
0.11 coalesce(string1, string2, ...) -> Returns the first non-empty value from the given arguments. At least two arguments must be provided.
0.12 coalesce takes any number of arguments and returns the first one that isn't null or an empty string.
Example Output
It seems all values being passed are null or empty.
aws_dynamodb_table.globaltable is empty tuple
aws_dynamodb_table.dynamodbtable is empty tuple
aws_s3_bucket.no_lifecycle is empty tuple
aws_s3_bucket.with_lifecycle is empty tuple
Call to function "coalesce" failed: no non-null, non-empty-string arguments.
Example Terraform Configuration and Apply Output
If one of the values is nulls/empty, coalesce() will fail.
$ cat main.tf
variable mynull {
default = null
}
variable myempty {
default = ""
}
output mycoalesce {
value = coalesce(var.mynull, var.myempty)
}
$ terraform apply
Error: Error in function call
on main.tf line 9, in output "mycoalesce":
18: value = coalesce(var.mynull, var.myempty)
|----------------
| var.myempty is ""
| var.mynull is null
Call to function "coalesce" failed: no non-null, non-empty-string arguments
Solution
Fix: not have null or empty values fed into the coalesce function.
Workaround: If you have a default value that is not null or non-empty, you can add this default to the list of coalesce.
$ cat main.tf
variable mynull { default = null } variable myempty { default = "" } output mycoalesce { value = coalesce(var.mynull, var.myempty, "default-value") }
$ terraform apply
Changes to Outputs:
+ mycoalesce = "default-value"
Documentation coalesce function