Looking for a way to render template directories including templated directory names

Is there a way to achieve similar functionality to the way cookiecutter works, where template tags can be used in directory/file names?
Alternatively- any way to force interpolating a string a second time could be a workaround?

Well, could you provide a real world example?

With cookiecutter, I can create the following directory tree from which to render another directory full of files, for example:
– file1. tmpl
– {{docs_dir}}/
---- readme.md.tmpl

Rendering that structure with values - project_dir = “foo”, docs_dir=“bar” would result in:
– file1
– bar/
---- readme.md

With hashicorp/dir/template, the filenames don’t get rendered, only the file contents.
I’m fairly sure the same is true with the template_dir provider but I really don’t want to create local files anyway.

I may have a hacky workaround which is implement the tag replacement manually, looping over the hashicorp/dir/template results and replace each tag with a value but it’s extremely hardcoded.

For example:

module "template_files" {
  source = "hashicorp/dir/template"
  base_dir = "${path.module}/templates"
  template_vars = {
    project_dir = "foo"
    docs_dir = "bar"

locals {
  _iter1 = { for file, values in module.template_files.files : "${replace(file,"{{project_dir}}", "foo")}" => values }
# ... more iters for more variable replacements
  rendered_template_files = { for file, values in module.template_files.files : "${replace(file,"{{docs_dir}}", "bar")}" => values }

It would be great if the module would handle interpolation of the file names itself though i didn’t see a way to do that. Alternatively a templatestring() or interpolatestring() function would seem to solve the problem. We could name a directory something like "${project_dir}/ and then

locals {
  rendered_template_files = { for file, values in module.template_files.files : "${templatestring(file)}" => values }

I guess the main difference between templatestring and interpolatestring would be whether or not you had to pass a map of template vars or would you use the regular var.x syntax.