Flatten nested map of maps to a single map with dotted notation

I’m reading yaml file contents using yamldecode function, but the yaml file rather gets deep and need to pass the contents of the file to a dynamic block. I can’t find a way to merge/flatten map of maps with dotted notation.

Yaml file content:

     pleh: help
              foo-3: bar
     bar: foo

Expected output:

"foo.pleh": help
"stuff.foo.foo-2.foo-3: bar"
"stuf.bar": foo

Terraform usage:

variable "chart_vars" {
  type = map(string)

dynamic "set" {
  for_each = var.chart_vars
   content {
    name  = set.key
    value = set.value

Is there any way to do this in terraform? Yaml file contents and depth are unknown i.e., file will keep growing as more value are added.

Thanks in advance!