加载输入文件转换为 Terraform 中的自定义数组对象

Load input file convert to custom array objects in Terraform

我有一种情况,我想将基于自定义的文件加载到内存并将其作为数组传递给 AWS 资源。

这是我的文件(这是不是JSON)

abc.tmpl

{
 name="Mark"
 age="20"
},
{
 name="Steve"
 age="25"
}

将以上值应用到下面数组中的资源之一

module "elb" {
 custome_elb_settings = [
  {
   name="Mark"
   age="20"
  },
  {
   name="Steve"
   age="25"
  }
 ]
}

当我尝试使用 template_file 时,它以纯文本形式加载并作为 1 个字符串加载,其中包含 \n 和转义字符。

有没有什么方法可以从文件加载为对象,或者在 Terraform 中将字符串转换为数组

提前致谢

将其声明为变量:

variable "custome_elb_settings" {
  type = list(object({name=string,age=number}))
}

module "elb" {
  custome_elb_settings = var.custome_elb_settings
}

然后在命令行中传值:

terraform apply -var custome_elb_settings="[ $(cat abc.tmpl) ]"