Hello All,
am using csv decode to create the resources, Currently, I am able to create resources with one to one mapping.
> { for name in local.confluent_values : "${name.service_account}:${name.environment}" => name }
{
"first-test:dev-b1" = {
"service_account" = "first-test"
"environment" = "dev-b1"
"topic_name" = "new-test-topic"
}
how should I be modifying the resource block below to accept list of topics names as inputs from csv decode. kindly let me know if this is possible.
{
"first-test:dev-b1" = {
"environment" = "dev-b1"
"service_account" = "first-test"
"topic_name" = "new-test-topic,new-test-topic-2,new-test-topic-3"
}
module "confluent_topic" {
source = "./modules/confluent_topic"
for_each = { for name in local.confluent_values : "${name.service_account}:${name.topic_name}:${name.environment}" => name }
topic_name = "${each.value.environment}-${each.value.topic_name}"
cluster_name = each.value.cluster_name
}
I used [""new-test-topic"",""new-test-topic-2"",""new-test-topic-3""]
to represent the csv in list format, then I tried using jsondecode and pass the values to the resource block, but am seeing an error in the function call…
tolist(jsondecode("[\"new-test-topic\",\"new-test-topic-2\",\"new-test-topic-3\"]"))
tolist([
"new-test-topic",
"new-test-topic-2",
"new-test-topic-3",
])
Error: Error in function call
│
│ on main.tf line 25, in module "confluent_topic":
│ 25: topic_name = tolist(jsondecode(each.value.topic_name))
│ ├────────────────
│ │ while calling jsondecode(str)
│ │ each.value.topic_name is "new-test-topic-1"
│
│ Call to function "jsondecode" failed: invalid character 'e' in literal null (expecting 'u').
╵
╷
│ Error: Error in function call
│
│ on main.tf line 25, in module "confluent_topic":
│ 25: topic_name = tolist(jsondecode(each.value.topic_name))
│ ├────────────────
│ │ while calling jsondecode(str)
│ │ each.value.topic_name is "new-test-topic"
│
│ Call to function "jsondecode" failed: invalid character 'e' in literal null (expecting 'u').
╵
╷
│ Error: Error in function call
│
│ on main.tf line 25, in module "confluent_topic":
│ 25: topic_name = tolist(jsondecode(each.value.topic_name))
│ ├────────────────
│ │ while calling jsondecode(str)
│ │ each.value.topic_name is "new-test-topic-1"
│
│ Call to function "jsondecode" failed: invalid character 'e' in literal null (expecting 'u').
╵