【发布时间】:2021-05-18 13:44:05
【问题描述】:
terraform 版本:0.12.20
我想在 terraform 中添加多个具有 set 数据类型的项目,我浏览了 link,其中一个示例展示了如何将简单数据类型添加为 String,但它无法使用 Set 添加
下面是我正在测试的代码
resource "aws_dynamodb_table_item" "items" {
hash_key = "key"
table_name = "test"
for_each = {
"72" = {
test = ["114717","2"],
test1 = []
},
"25" = {
test = ["114717"],
test1 = []
}
}
item = <<EOF
{
"key": {"S": "${each.key}"},
"test": {"SS": "${each.value.test}"},
"test1": {"SS": "${each.value.test1}"}
}
EOF
}
但是,Cannot include the given value in a string template: string required. 失败
我尝试了类似的东西
resource "aws_dynamodb_table_item" "items" {
hash_key = "key"
table_name = "test"
for_each = {
"72" = {
test = "114717,2",
test1 = ""
},
"25" = {
test = "114717",
test1 = ""
}
}
item = <<EOF
{
"key": {"S": "${each.key}"},
"test": {"SS": ["${each.value.test}"]},
"test1": {"SS": ["${each.value.test1}"]}
}
EOF
}
这无法将 "114717,2" 区分为两个不同的项目
在第二个示例中,我什至也尝试了以下部分
{
"key": {"S": "${each.key}"},
"test": {"SS": "${split(",",each.value.test)}"},
"test1": {"SS": "${split(",",each.value.test1)}"}
}
Cannot include the given value in a string template: string required. 也会失败
我希望能够将值拆分为数组["114717","2"]。这将帮助我在 DynamoDB 中将值存储为 Set
【问题讨论】:
-
“这无法将“114717,2”区分为两个不同的项目”是什么意思?实际结果是什么,为什么会出错,预期的结果应该是什么?
-
@Marcin 我已经更新了我的问题以便更好地理解
-
whiteListedCustomers和blackListedCustomers是什么?您的代码中没有定义此类变量。 -
@Marcin 对不起,我做了代码混淆,错过了删除那些,更新了问题
标签: amazon-web-services terraform terraform-provider-aws terraform0.12+