What is the best way to share values between Terraform and external programs?

How do you share data between Terraform and other applications for automation? For example, Ansible, shell scripts, Python…etc.

What I can see are:

  1. 3rd party tools write the outputs to a local file, and then Terraform read the file content with file block.
  2. Use external data block. However, the outputs in 3rd party tools must be the JSON format.