Skip to content

Commit 2094920

Browse files
committed
Change MM2 example to include 2 GMK clusters.
1 parent 7887a02 commit 2094920

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

managedkafka/managedkafka_create_connector_mirrormaker_source/main.tf renamed to managedkafka/managedkafka_create_connector_mirrormaker2_source/main.tf

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,30 @@
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.
7596
resource "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

96120
data "google_project" "default" {
97121
}
98122

99-
# [END managedkafka_create_connector_mirrormaker_source_parent]
123+
# [END managedkafka_create_connector_mirrormaker2_source_parent]

managedkafka/managedkafka_create_connector_mirrormaker_source/test.yaml renamed to managedkafka/managedkafka_create_connector_mirrormaker2_source/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
apiVersion: blueprints.cloud.google.com/v1alpha1
1616
kind: BlueprintTest
1717
metadata:
18-
name: managedkafka_create_connector_mirrormaker_source
18+
name: managedkafka_create_connector_mirrormaker2_source
1919
spec:
2020
# This test is being skipped due to a known issue with leaking Network
2121
# Attachment resources which prevents `terraform destroy` from completing

0 commit comments

Comments
 (0)