Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
16d7b2f
docs: Add Managed Kafka Connect terraform sample
salmany Jul 23, 2025
163059e
Update tags in main.tf
salmany Jul 23, 2025
0c1763e
Merge branch 'main' into salman-mkc-code-examples
glasnt Jul 25, 2025
dec3c5a
Addressed PR comments.
salmany Jul 28, 2025
0886c4e
Add comment to clarify memory_bytes value.
salmany Jul 28, 2025
315b503
Fix incorrect Kafka cluster reference.
salmany Jul 28, 2025
be446e6
docs: Add Managed Kafka Connect terraform sample
salmany Jul 29, 2025
ad846d7
Fix typo in memory_bytes for connectors
salmany Jul 29, 2025
9599c11
Fixed formatting.
salmany Jul 29, 2025
7188e27
Fix formatting
salmany Jul 29, 2025
4fdbd4c
Merge branch 'main' into mkc-connector-examples
salmany Jul 29, 2025
30dd507
Fix snippet tags.
salmany Jul 29, 2025
274f08f
Fix tags
salmany Jul 29, 2025
8a162d8
Adding workaround for subnet resource deletion.
salmany Jul 30, 2025
5a99b76
Fixed errors and formatting.
salmany Jul 30, 2025
79d5fc0
Merge branch 'main' into mkc-connector-examples
salmany Aug 7, 2025
34292bd
Disable tests and modify subnet resources.
salmany Aug 7, 2025
bf50178
Updated connector sample configs.
salmany Aug 7, 2025
4217bbe
Fix formatting.
salmany Aug 7, 2025
7887a02
Add comment for MM connector target cluster.
salmany Aug 7, 2025
2094920
Change MM2 example to include 2 GMK clusters.
salmany Aug 11, 2025
9b249fe
Fix connector name to match id.
salmany Aug 11, 2025
7970c79
Fix connector bootstrap server addresses.
salmany Aug 11, 2025
080f2b0
Fix bootstrap server addresses and add comment.
salmany Aug 11, 2025
4571dd6
Fix whitespaces and formatting.
salmany Aug 11, 2025
91d48c7
Add newline.
salmany Aug 11, 2025
ea14a5a
Add comments for access to MM2 clusters and other fixes.
salmany Aug 13, 2025
4aa8823
Formatting fix.
salmany Aug 13, 2025
f28c331
Applying suggestions.
salmany Aug 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions managedkafka/managedkafka_create_connector_bigquery_sink/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

# [START managedkafka_create_connector_bigquery_sink_parent]

resource "google_managed_kafka_cluster" "default" {
project = data.google_project.default.project_id
cluster_id = "my-cluster-id"
location = "us-central1"
capacity_config {
vcpu_count = 3
memory_bytes = 3221225472 # 3 GiB
}
gcp_config {
access_config {
network_configs {
subnet = google_compute_subnetwork.default.id
}
}
}
}

resource "google_managed_kafka_connect_cluster" "default" {
provider = google-beta
project = data.google_project.default.project_id
connect_cluster_id = "my-connect-cluster-id"
location = "us-central1"
kafka_cluster = google_managed_kafka_cluster.default.id
capacity_config {
vcpu_count = 12
memory_bytes = 12884901888 # 12 GiB
}
gcp_config {
access_config {
network_configs {
primary_subnet = google_compute_subnetwork.default.id
}
}
}
}

# Note: Due to a known issue, network attachment resources may not be
# properly deleted, which can cause 'terraform destroy' to hang. It is
# recommended to destroy network resources separately from the Kafka
# Connect resources.
# The documentation elaborates further on the recommended approach.
# [START managedkafka_subnetwork]
resource "google_compute_subnetwork" "default" {
name = "test-subnetwork"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
}

resource "google_compute_network" "default" {
name = "test-network"
auto_create_subnetworks = false
}
# [END managedkafka_subnetwork]

# [START managedkafka_create_connector_bigquery_sink]
resource "google_managed_kafka_connector" "example-bigquery-sink-connector" {
project = data.google_project.default.project_id
connector_id = "my-bigquery-sink-connector"
connect_cluster = google_managed_kafka_connect_cluster.default.connect_cluster_id
location = "us-central1"

configs = {
"name" = "my-bigquery-sink-connector"
"project" = "GCP_PROJECT_ID"
Comment on lines +82 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like repeated values from the main resource args. If that's the case, you can use the dynamic project ID rather than hardcoding it here.

Suggested change
"name" = "my-bigquery-sink-connector"
"project" = "GCP_PROJECT_ID"
"name" = "my-bigquery-sink-connector"
"project" = data.google_project.default.project_id

"topics" = "GMK_TOPIC_ID"
"tasks.max" = "3"
"connector.class" = "com.wepay.kafka.connect.bigquery.BigQuerySinkConnector"
"key.converter" = "org.apache.kafka.connect.storage.StringConverter"
"value.converter" = "org.apache.kafka.connect.json.JsonConverter"
"value.converter.schemas.enable" = "false"
"defaultDataset" = "BQ_DATASET_ID"
}

provider = google-beta
}
# [END managedkafka_create_connector_bigquery_sink]

data "google_project" "default" {
}

# [END managedkafka_create_connector_bigquery_sink_parent]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: blueprints.cloud.google.com/v1alpha1
kind: BlueprintTest
metadata:
name: managedkafka_create_connector_bigquery_sink
spec:
# This test is being skipped due to a known issue with leaking Network
# Attachment resources which prevents `terraform destroy` from completing
# successfully in the test environment.
skip: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

# [START managedkafka_create_connector_pubsub_source_parent]

resource "google_managed_kafka_cluster" "default" {
project = data.google_project.default.project_id
cluster_id = "my-cluster-id"
location = "us-central1"
capacity_config {
vcpu_count = 3
memory_bytes = 3221225472 # 3 GiB
}
gcp_config {
access_config {
network_configs {
subnet = google_compute_subnetwork.default.id
}
}
}
}

resource "google_managed_kafka_connect_cluster" "default" {
provider = google-beta
project = data.google_project.default.project_id
connect_cluster_id = "my-connect-cluster-id"
location = "us-central1"
kafka_cluster = google_managed_kafka_cluster.default.id
capacity_config {
vcpu_count = 12
memory_bytes = 12884901888 # 12 GiB
}
gcp_config {
access_config {
network_configs {
primary_subnet = google_compute_subnetwork.default.id
}
}
}
}

# Note: Due to a known issue, network attachment resources may not be
# properly deleted, which can cause 'terraform destroy' to hang. It is
# recommended to destroy network resources separately from the Kafka
# Connect resources.
# The documentation elaborates further on the recommended approach.
# [START managedkafka_subnetwork]
resource "google_compute_subnetwork" "default" {
name = "test-subnetwork"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
}

resource "google_compute_network" "default" {
name = "test-network"
auto_create_subnetworks = false
}
# [END managedkafka_subnetwork]

# [START managedkafka_create_connector_cloud_storage_sink]
resource "google_managed_kafka_connector" "example-cloud-storage-sink-connector" {
project = data.google_project.default.project_id
connector_id = "my-gcs-sink-connector"
connect_cluster = google_managed_kafka_connect_cluster.default.connect_cluster_id
location = "us-central1"

configs = {
"connector.class" = "io.aiven.kafka.connect.gcs.GcsSinkConnector"
"tasks.max" = "3"
"topics" = "GMK_TOPIC_ID"
"gcs.bucket.name" = "GCS_BUCKET_NAME"
"gcs.credentials.default" = "true"
"format.output.type" = "json"
"name" = "my-gcs-sink-connector"
"value.converter" = "org.apache.kafka.connect.json.JsonConverter"
"value.converter.schemas.enable" = "false"
"key.converter" = "org.apache.kafka.connect.storage.StringConverter"
}
provider = google-beta
}
# [END managedkafka_create_connector_cloud_storage_sink]

data "google_project" "default" {
}

# [END managedkafka_create_connector_pubsub_source_parent]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: blueprints.cloud.google.com/v1alpha1
kind: BlueprintTest
metadata:
name: managedkafka_create_connector_cloud_storage_sink
spec:
# This test is being skipped due to a known issue with leaking Network
# Attachment resources which prevents `terraform destroy` from completing
# successfully in the test environment.
skip: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

# [START managedkafka_create_connector_mirrormaker2_source_parent]

# Define the target Kafka cluster. This is where data will be replicated to.
resource "google_managed_kafka_cluster" "target" {
project = data.google_project.default.project_id
cluster_id = "mm2-target-cluster-id"
location = "us-central1"
capacity_config {
vcpu_count = 3
memory_bytes = 3221225472 # 3 GiB
}
gcp_config {
access_config {
network_configs {
subnet = google_compute_subnetwork.default.id
}
}
}
}

# Define the source Kafka cluster.
resource "google_managed_kafka_cluster" "source" {
project = data.google_project.default.project_id
cluster_id = "mm2-source-cluster-id"
location = "us-central1"
capacity_config {
vcpu_count = 3
memory_bytes = 3221225472 # 3 GiB
}
gcp_config {
access_config {
network_configs {
subnet = google_compute_subnetwork.default.id
}
}
}
}

resource "google_managed_kafka_connect_cluster" "default" {
provider = google-beta
project = data.google_project.default.project_id
connect_cluster_id = "my-connect-cluster-id"
location = "us-central1"
# The Connect cluster is usually co-located with the target Kafka cluster.
kafka_cluster = google_managed_kafka_cluster.target.id
capacity_config {
vcpu_count = 12
memory_bytes = 12884901888 # 12 GiB
}
gcp_config {
access_config {
network_configs {
primary_subnet = google_compute_subnetwork.default.id
# As part of the configuration, ensure the Connect cluster has necessary access
# to all MM2 source/target Kafka clusters. For more information on configuring access,
# see the documentation:
# (https://cloud.google.com/managed-service-for-apache-kafka/docs/connect-cluster/create-mirrormaker-connector)
# As an example, we enable network access to Kafka Clusters below using DNS domain names.
# The format for DNS name should be:
# "GMK_CLUSTER_ID.REGION.managedkafka.PROJECT_ID.cloud.goog.*"
# Please note that we do NOT need to add the DNS name of the primary Kafka cluster to the
# `dns_domain_names` list, as our Connect cluster configures that automatically.
dns_domain_names = ["DNS_DOMAIN_NAME"]
}
}
}
}

# Note: Due to a known issue, network attachment resources may not be
# properly deleted, which can cause 'terraform destroy' to hang. It is
# recommended to destroy network resources separately from the Kafka
# Connect resources.
# The documentation elaborates further on the recommended approach.
# [START managedkafka_subnetwork]
resource "google_compute_subnetwork" "default" {
name = "test-subnetwork"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
}

resource "google_compute_network" "default" {
name = "test-network"
auto_create_subnetworks = false
}
# [END managedkafka_subnetwork]

# [START managedkafka_create_connector_mirrormaker2_source]
# A single MirrorMaker 2 Source Connector to replicate from one source to one target.
resource "google_managed_kafka_connector" "default" {
project = data.google_project.default.project_id
connector_id = "mm2-source-to-target-connector-id"
connect_cluster = google_managed_kafka_connect_cluster.default.connect_cluster_id
location = "us-central1"

configs = {
"connector.class" = "org.apache.kafka.connect.mirror.MirrorSourceConnector"
"name" = "mm2-source-to-target-connector-id"
"tasks.max" = "3"
"source.cluster.alias" = "source"
"target.cluster.alias" = "target"
"topics" = ".*" # Replicate all topics from the source
# The value for bootstrap.servers is a comma-separated list of hostname:port pairs
# for one or more Kafka brokers in the source/target cluster.
"source.cluster.bootstrap.servers" = "source_cluster_dns"
"target.cluster.bootstrap.servers" = "target_cluster_dns"
# You can define an exclusion policy for topics as follows:
# To exclude internal MirrorMaker 2 topics, internal topics and replicated topics,.
"topics.exclude" = "mm2.*\\.internal,.*\\.replica,__.*"
}

provider = google-beta
}
# [END managedkafka_create_connector_mirrormaker2_source]

data "google_project" "default" {
}

# [END managedkafka_create_connector_mirrormaker2_source_parent]
Loading