Bag*_*hel 1 amazon-dynamodb terraform terraform-provider-aws
我想编写一个 terraform 模块来创建 dynamoDb 表。这些属性应该从.tfvars默认变量中读取,而不是像此处的.tf资源指南中那样已命名
为了进一步解释,假设使用属性列表来实现此伪代码:
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "GameScores"
... #Other required feilds
...
...
# attributes is a list of names
for(attribute_name:${length(var.attributes)}){
attribute {
name = "${var.attributes[i]}"
type = "N"
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在 terraform plan/apply 期间迭代属性列表并创建属性{ } ?属性块的数量不能像 terraform 文档中所示的那样是静态的,并且它们的名称必须从变量中读取。
小智 5
很晚了,但对于其他正在看的人来说一定有用。我使用这个文档,在那里我可以使用这样的一些
dynamic "attribute" {
for_each = var.table_attributes
content {
name = tag.value["name"]
type = tag.value["type"]
}
}
Run Code Online (Sandbox Code Playgroud)
在我的Variables.tf中,我有变量table_attributes以及要使用的对象映射。也许它对某人有帮助。
| 归档时间: |
|
| 查看次数: |
4051 次 |
| 最近记录: |