Ouput a list of all modules

Is there a way create an output containing a list of all modules used in the root module of the workspace?

The goal is to share that information with other workspaces (via the remote state) to ensure that modules deployed to “production” are first deployed to “staging” (related question).

I tried a following approach:

output "all_root_modules" {
  value = module[*].name

but it yields an error:

The "module" object cannot be accessed directly. Instead, access one of its attributes.

No, I’m pretty confident this is not possible.

You’d need to independently parse the Terraform HCL with custom code.