Kafka multiple topics using terraform

Hi Team,

unable to create multiple kafka topics/service accounts/api keys using terraform script.

Thanks,
Ashok

Hi @Ashok,

Which TF provider are you using? What error do you hit?

I ran a quick test to create multiple topics using the Confluent provider and it worked as expected. Specifically, I added the config below to this example when following this quickstart.

resource "confluent_kafka_topic" "orders2" {
  kafka_cluster {
    id = confluent_kafka_cluster.basic.id
  }
  topic_name    = "orders2"
  rest_endpoint = confluent_kafka_cluster.basic.rest_endpoint
  credentials {
    key    = confluent_api_key.app-manager-kafka-api-key.id
    secret = confluent_api_key.app-manager-kafka-api-key.secret
  }
}

HTH,
Dave

Thanks @dtroiano for the update.

but the above piece of script will create only single topic.

Anyhow I got the logic to create multiple topics using foreach.

Now we need to achieve the below scenarios using terraform script.

Scenario 1: I want to create 2 clusters and, in each cluster, want to create 10 topics. (ex: cluster name test-cluster and topic names are test2, …test10).

Scenario2: In future just want to add 5 more topics to the same cluster. (ex: test1…test 15 to the test-cluster).(in this case I want to read the existing cluster name/id).

Will the above scenarios possible in one script in one shot? if yes could you please help.

Thanks,
Ashok

Hey @Ashok , did you get the answer for the above question. I’m dealing with the same situations, any ideas would be appreciated.

Thank you,