But where you have your ternary expression it is inside the first map as another item, rather than a separate map to merge with it.
Example 2
> merge({a="b", c="d",{ e = { f="g" }}})
╷
│ Error: Missing key/value separator
│
│ on <console-input> line 1:
│ (source code not available)
│
│ Expected an equals sign ("=") to mark the beginning of the attribute value.
When the ternary expression is moved outside of the first map you get the desired behaviour (As per Example 1):
aws_dynamodb_table_item item argument does require a JSON representation so you will still need the jsonencode as follows:
item = jsonencode(merge({
id = {
S = "${var.account_email_address}"
}
accountType = {
S = "${var.account_type}"
}
appName = {
S = "${var.domain_name}"
}
costCenter = {
S = "${var.cost_center}"
}
},
var.account_type == "sandbox" ? {
datadogEnabled = {
BOOL = var.datadog_enabled
}
} : {}
))
Apologies, I missed this from my example.
If my answers worked for you, can you please mark the relevant reply as the solution, to help others that may have the same issue fid the solution more easily.