如何在terraform中向列表中的每个对象添加新属性?

huangapple go评论56阅读模式
英文:

How to add a new property to each object in a list in terraform?

问题

new_list = [for item in list : {...item, newProp = XYZ}]

我假设JavaScript 对象解构在 tf 文件中有效但是它是吗我不想在上面列出 `item` 的所有现有属性
英文:
 new_list = [for item in list : {...item, newProp = XYZ}]

I assumed, javascript object deconstructor works in tf files, but does it? I don't want to list all the existing properties of item above.

答案1

得分: 1

new_list = [for item in list : merge(item, {newProp = "XYZ"})]
英文:

You can use the merge function to add a new property to each object in a list without having to explicitly list all the existing properties. example below:

new_list = [for item in list : merge(item, {newProp = "XYZ"})]

huangapple
  • 本文由 发表于 2023年3月23日 10:08:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75818722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定