gpt4 book ai didi

amazon-web-services - 地形计划 'string required' dynamodb_table_item

转载 作者:行者123 更新时间:2023-12-04 07:43:38 25 4
gpt4 key购买 nike

我需要向 dynamodb_table_item 资源添加一组字符串。

# my.tfvars

client_days = [
"2021-05-08", # May
"2021-06-12", "2021-06-26", # June
]

# main.tf
variable "client_days" {
type = set(string)
description = "Client days."
}

resource "aws_dynamodb_table_item" "client_days" {
table_name = aws_dynamodb_table.periods.name
hash_key = "name"

item = <<EOF
{
"name": { "S": "client-days" },
"days": {
"SS" : "${client_days}"
}
}
EOF
}
结果如下所示:
 32:   item = <<EOF
33: {
34: "name": { "S": "client-days" },
35: "days": {
36: "SS" : "${var.client_days}"
37: }
38: }
39: EOF
|----------------
| var.client_days is set of string with 11 elements

Cannot include the given value in a string template: string required.
我不知道如何解决这个问题。
我还尝试使用 join() 将该列表转换为字符串。

最佳答案

您必须使用 jsonencode :

resource "aws_dynamodb_table_item" "client_days" {
table_name = "testdb"
hash_key = "name"

item = <<EOF
{
"name": { "S": "client-days" },
"days": {
"SS" : ${jsonencode(var.client_days)}
}
}
EOF
}

关于amazon-web-services - 地形计划 'string required' dynamodb_table_item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67315751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com