For anyone coming across this in 2025, there's no solution to this problem as terraform simply doesn't support it. See https://github.com/hashicorp/terraform/issues/26697
The only solution to this I can come up with is to use an "external" data resource (data "external" "generator") that points to a script you write, consumes your configuration data, and generates a terraform file you can then consume in your TF modules.