英文:
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"})]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论