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:

foo:
     pleh: help
stuff:
     foo:
         foo-2:
              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!

Hi @gowtham .

Sorry for raising this old one, but have you ever found a solution to this? I’m facing this exact challenge at the moment and so far I’m failing to find the answer.

Thanks!

No, there is no way to write this transformation directly in Terraform syntax.

But, neither do you have to do this, as the helm_release resource allows you to pass values YAML as is.

Unfortunately, my scenario was to set_sensitive {} for every key value pair.

I ended up with yamldecode + external_data provider with a bash script allowing the transformation in question.