How to find local module depdencies of a module


I have written several tests for my Terraform modules, but I only want to run them when there have been changes to the module. I can do this by checking if there have been any file changes in the directory where the module is.

However, several of the modules depends on other local modules. If a child module has changes then I also want to run the tests for the top modules that depends on it.

Is it possible to produce a list of dependencies a module has and filter for only local modules?

I could for example use regex like this:
module "(?<moduleName>.*?)" {\n source = "(?<modulePath>.*?)"

module "sealedsecret" {
  source = "../../sealedsecret"

But that takes assuemptions about formatting of each module.