TerraformでDynamoDBに対してaws_dynamodb_table_itemでマップを含むアイテムを挿入しようとして
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | resource "aws_dynamodb_table_item" "test_item01" { table_name = "${aws_dynamodb_table.test_table.name}" hash_key = "${aws_dynamodb_table.test_table.hash_key}" item = <<ITEM { "id": {"S": "test01"}, "foo": { "a": {"S": "aaa"}, "b": {"S": "bbb"} } } ITEM } |
こういう表記をすると
aws_dynamodb_table_item.test_item01: Invalid format of “item”: Decoding failed: json: cannot unmarshal object into Go struct field AttributeValue.B of type []uint8
というエラーが出たり、更にマップをネストさせると
aws_dynamodb_table_item.test_item01: ValidationException: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes
というエラーが出ます。
正しくは
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | item = <<ITEM { "id": {"S": "test01"}, "foo": {"M": { "nested": {"M": { "a": {"S": "aaa"}, "b": {"S": "bbb"} }} }}, "bar": {"L": [ {"N": "1"}, {"N": "2"}, {"N": "3"} ]} } ITEM |
こんな感じでマップならM、リストならLのように全てを{“型記述子”: 値}の形式で書く必要があります。
また数値もダブルクオートで囲う必要があります。
データ型記述子については公式ドキュメントのこのページに一覧があります。