amazon-web-services - Does terraform support map of list?
问题描述
I want to create a variable that will resemble the following yaml format
Dev:
- name: Michael
type: Senior
- name: Ron
type: Junior
- name: Lex
type: Senior
- name: Rocky
type: Junior
Test:
- name: Rony
type: Junior
- name: Ryan
type: Junior
- name: John
type: Senior
- name: Brad
type: Junior
What is the best way in Terraform to represent the above data structure?.
解决方案
如果您要求每个列表元素都具有这些键name
和type
,但顶级键是任意的,那么接受该数据结构的最直接类型约束将是:
type = map(list(object({
name = string
type = string
}))
我在这里假设列表项的顺序很重要。set(...)
相反,如果这只是一个没有特定顺序的不同对象的集合(例如,如果您打算使用每个对象来声明一个完全独立的对象),那么使用类型种类而不是类型种类可能更有意义list(...)
,更清楚地表明排序并不重要,并且每个项目都必须是唯一的。
推荐阅读
- python - Apache2、modwsgi、Python3.6 和 Bottle 集成的问题,在 Apache2 日志中未找到看到模块错误
- r - 使用行索引向量组合数据帧
- nosql - Oracle NoSQL 数据库云服务的服务控制台是否支持聚合?
- sql-server - 使用 sql 根据存储在另一列中的先前值获取最后一个值
- python - 如何让我的 go 功能正常工作?
- lua - ')' 附近的 LUA 意外符号
- node.js - 如何在打字稿中包含自定义声明文件?
- c# - 如何正确实现 Unity 'XR Simple Interactable'
- php - 使用 HTML 表单运行时,POSTMAN 中的 PHP cURL 请求输出不起作用
- makefile - 如何从 Makefile 中的文本文件中提取值?