$ cat script.sh
#!/usr/bin/env bash
# bash: a script that prints directories
# one per line without duplicates
# that contain one or more files with a '.tf' extension.
find . -type f -name '*.tf' -printf '%h\n' | sort -u
$
Note:
env -Ubuntu 20.04