3
不知道这是否可能,但我有一个DynamoDb表的模块,我想使global_secondary_index
属性为可选,但我无法弄清楚如何执行此操作。terraform模块中的可选映射变量
我有以下模块
resource "aws_dynamodb_table" "basic_dynamodb_table" {
name = "${var.table_name}"
read_capacity = "${var.read_capacity}"
write_capacity = "${var.write_capacity}"
hash_key = "${var.primary_key}"
attribute {
name = "${var.primary_key}"
type = "${var.primary_key_type}"
}
global_secondary_index = ["${var.global_secondary_index}"]
}
variable "table_name" {}
variable "read_capacity" {
default = "1"
}
variable "write_capacity" {
default = "1"
}
variable "primary_key" {}
variable "primary_key_type" {}
variable "global_secondary_index" {
default = {}
type = "map"
description = "This should be optional"
}
而且,它还将被用来
module "test-table" {
source = "./modules/DynamoDb"
table_name = "test-table"
primary_key = "Id"
primary_key_type = "S"
global_secondary_index = {
name = "by-secondary-id"
hash_key = "secondaryId"
range_key = "type"
projection_type = "INCLUDE"
non_key_attributes = [
"id"
]
write_capacity = 1
read_capacity = 1
}
}
我已经试过:
- 不使用
[]
周围的插值并获得global_secondary_index: should be a list
错误 - just usi纳克的VAR
global_secondary_index = ["${var.global_secondary_index}"]
得到global_secondary_index.0: expected object, got string
错误 - 条件,但显然不支持列表或地图
- 合并地图
global_secondary_index = ["${merge(var.global_secondary_index,map())}"]
也得到global_secondary_index.0: expected object, got string
错误
出如何使这项工作现在