1414 * limitations under the License.
1515 */
1616
17- # [START managedkafka_create_connector_mirrormaker_source_parent ]
17+ # [START managedkafka_create_connector_mirrormaker2_source_parent ]
1818
19- resource "google_managed_kafka_cluster" "default" {
19+ # Define the target Kafka cluster. This is where data will be replicated to.
20+ resource "google_managed_kafka_cluster" "target" {
2021 project = data. google_project . default . project_id
21- cluster_id = " my-cluster-id"
22+ cluster_id = " mm2-target-cluster-id"
23+ location = " us-central1"
24+ capacity_config {
25+ vcpu_count = 3
26+ memory_bytes = 3221225472 # 3 GiB
27+ }
28+ gcp_config {
29+ access_config {
30+ network_configs {
31+ subnet = google_compute_subnetwork. default . id
32+ }
33+ }
34+ }
35+ }
36+
37+ # Define the source Kafka cluster.
38+ resource "google_managed_kafka_cluster" "source" {
39+ project = data. google_project . default . project_id
40+ cluster_id = " mm2-source-cluster-id"
2241 location = " us-central1"
2342 capacity_config {
2443 vcpu_count = 3
@@ -38,7 +57,8 @@ resource "google_managed_kafka_connect_cluster" "default" {
3857 project = data. google_project . default . project_id
3958 connect_cluster_id = " my-connect-cluster-id"
4059 location = " us-central1"
41- kafka_cluster = google_managed_kafka_cluster. default . id
60+ # The Connect cluster is usually co-located with the target Kafka cluster.
61+ kafka_cluster = google_managed_kafka_cluster. target . id
4262 capacity_config {
4363 vcpu_count = 12
4464 memory_bytes = 12884901888 # 12 GiB
@@ -71,29 +91,33 @@ resource "google_compute_network" "default" {
7191}
7292# [END managedkafka_subnetwork]
7393
74- # [START managedkafka_create_connector_mirrormaker_source]
94+ # [START managedkafka_create_connector_mirrormaker2_source]
95+ # A single MirrorMaker 2 Source Connector to replicate from one source to one target.
7596resource "google_managed_kafka_connector" "default" {
7697 project = data. google_project . default . project_id
77- connector_id = " MM2_CONNECTOR_ID "
98+ connector_id = " mm2-source-to-target-connector-id "
7899 connect_cluster = google_managed_kafka_connect_cluster. default . connect_cluster_id
79100 location = " us-central1"
80101
81102 configs = {
82103 " connector.class" = " org.apache.kafka.connect.mirror.MirrorSourceConnector"
83- " name" = " MM2_CONNECTOR_ID "
104+ " name" = " mm2-source-to-target-connector "
84105 " tasks.max" = " 3"
85106 " source.cluster.alias" = " source"
86- " target.cluster.alias" = " target" # This is usually the primary cluster
87- " topics" = " GMK_TOPIC_NAME"
88- " source.cluster.bootstrap.servers" = " GMK_SOURCE_CLUSTER_DNS"
89- " target.cluster.bootstrap.servers" = " GMK_TARGET_CLUSTER_DNS"
107+ " target.cluster.alias" = " target"
108+ " topics" = " .*" # Replicate all topics from the source
109+ " source.cluster.bootstrap.servers" = google_managed_kafka_cluster.source.bootstrap_servers
110+ " target.cluster.bootstrap.servers" = google_managed_kafka_cluster.target.bootstrap_servers
111+ # Using a replication policy is a good practice to identify mirrored topics.
112+ # It prefixes the topic name with the source alias (e.g., "source.my-topic").
113+ " replication.policy.class" = " org.apache.kafka.connect.mirror.DefaultReplicationPolicy"
90114 }
91115
92116 provider = google- beta
93117}
94- # [END managedkafka_create_connector_mirrormaker_source ]
118+ # [END managedkafka_create_connector_mirrormaker2_source ]
95119
96120data "google_project" "default" {
97121}
98122
99- # [END managedkafka_create_connector_mirrormaker_source_parent ]
123+ # [END managedkafka_create_connector_mirrormaker2_source_parent ]
0 commit comments