passing function statement as string in terraform

Viewed 27

is it possible to somehow pass and decode the variable in quotes from main.tf to test.tf.

I am trying to do some calculation. But it is different for all the modules. I am wondering is we can pass something like this from one file:

  • main.tf
test = "length(regexall(\"file\", each.key)) > 0 ? [for n in var.dns : n][0] : [for n in var.dns : n][1]"
  • test.tf

Read it in other without quotes and escape character??

test = length(regexall("file", each.key)) > 0 ? [for n in var.dns : n][0] : [for n in var.dns : n][1]

I already tried using replace and trim. It isn't working.

Thank you

1 Answers

Sadly such a thing is not supported in terraform. You can't dynamically pass TF code as strings and then evaluate the string as a code, like eval in other languages.

The closest would to use custom data source which you program yourself. Since you have to develop it, you can program any logic you want.

Related