Hi,
I have a question about whether its possible to build a terraform data type (specifically a ‘set of objects’) using the rendered output of the templatefile() function …and then use this output as an input value to be passed into a module? …I cant seem to get it to work
So to explain , I have a pipelines.tmpl
file that looks like this
pipelines_rendered = [
%{~ for p in pipelines ~}
{
name = "${p.name}"
project = "blah"
version = "${p.ver}"
branch = "something"
description = "blah"
...
...
},
%{~ endfor ~}
]
This is fed from local.pipelines
that looks like this
locals {
pipelines = [
{ name = "foo", ver = "1" },
{ name = "bar", ver = "1" },
...
]
}
The final rendered output of this templatefile() forms, what looks exactly like, the ‘set of objects’ structure that I need . I now want to feed this resultant ‘set of objects’ created by the template into a module as an input (to be interpolated) … Specifically, as the value of a variable called ‘pipelines_in’ (this variable is declared as type ‘set of objects’ in the target module)
So as you can see below, when calling the module, I am invoking the templatefile() function to return the rendered output (set of objects) … to form the value of the 'pipelines_in` variable
module "build_pipelines" {
source = "somewhere:/mymodule"
pipelines_in = templatefile("${path.module}/pipelines.tmpl", { pipelines = local.pipelines })
}
But whatever I try here, I seem to get the same error when running a plan
│ Error: Invalid value for input variable
│
│ The given value is not suitable for module.mymodule.var.pipelines
│ declared at
│ .terraform/modules/mymodule/terraform/variables.tf:35,1-21: set of
│ object required.
Is there is an issue when taking the output of templatefile() as in input to be interpolated ?
Is there another way i should be doing this (the brief is to remove the need for developers to have to build a full ‘set of objects’ , but instead just add a few variables and let the template build the full set of objects