Depends a little on what type of data you are trying to get and use.
All methods require a custom script to get the data from the database and format it, unless a provider was written with database data sources. The MySQL provider currently doesn't have data sources.
- Wrapper or pre-terraform scripts
- This could create a .tfvar or .tf file (hcl or json)
- Could create TF_VAR_ environment variables
- As a wrapper, would build the terraform command line with all the variables
- external/data_source provider
- In this case terraform runs your script and the output must be json, which Terraform will read in and can be referenced
All of these methods work for string variables.
If you need something other than strings, then there can be differences in the methods.
Terraform json parser is not true json, which prevents it's use for complex data structures.
I'd advise against uses complex data structures. But if you do need them, you may be forced to generate a hcl file
They are other obscure methods, that I'd recommend not using.