Skip to content

Commit c60aa2b

Browse files
salmanyglasnt
andauthored
docs: Add Managed Kafka Connect terraform sample for Clusters (#876)
* docs: Add Managed Kafka Connect terraform sample for Clusters * Add sample code for creating a Kafka Connect cluster * Update tags in main.tf Corrected tags. * Addressed PR comments. * Add comment to clarify memory_bytes value. * Fix incorrect Kafka cluster reference. * Workaround for subnet resource deletion. * Disable tests and update network resource creation * Fix lint errors. --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent c66a1f4 commit c60aa2b

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START managedkafka_create_connect_cluster_parent]
18+
resource "google_managed_kafka_cluster" "default" {
19+
project = data.google_project.default.project_id
20+
cluster_id = "my-cluster-id"
21+
location = "us-central1"
22+
capacity_config {
23+
vcpu_count = 3
24+
memory_bytes = 3221225472 # 3 GiB
25+
}
26+
gcp_config {
27+
access_config {
28+
network_configs {
29+
subnet = google_compute_subnetwork.default.id
30+
}
31+
}
32+
}
33+
}
34+
35+
# [START managedkafka_create_connect_cluster]
36+
resource "google_managed_kafka_connect_cluster" "default" {
37+
provider = google-beta
38+
project = data.google_project.default.project_id
39+
connect_cluster_id = "my-connect-cluster-id"
40+
location = "us-central1"
41+
kafka_cluster = google_managed_kafka_cluster.default.id
42+
capacity_config {
43+
vcpu_count = 12
44+
memory_bytes = 12884901888 # 12 GiB
45+
}
46+
gcp_config {
47+
access_config {
48+
network_configs {
49+
primary_subnet = google_compute_subnetwork.default.id
50+
}
51+
}
52+
}
53+
}
54+
# [END managedkafka_create_connect_cluster]
55+
56+
# Note: Due to a known issue, network attachment resources may not be
57+
# properly deleted, which can cause 'terraform destroy' to hang. It is
58+
# recommended to destroy network resources separately from the Kafka
59+
# Connect resources.
60+
# The documentation elaborates further on the recommended approach.
61+
# [START managedkafka_subnetwork]
62+
resource "google_compute_subnetwork" "default" {
63+
name = "test-subnetwork"
64+
ip_cidr_range = "10.2.0.0/16"
65+
region = "us-central1"
66+
network = google_compute_network.default.id
67+
}
68+
69+
resource "google_compute_network" "default" {
70+
name = "test-network"
71+
auto_create_subnetworks = false
72+
}
73+
# [END managedkafka_subnetwork]
74+
75+
data "google_project" "default" {
76+
}
77+
# [END managedkafka_create_connect_cluster_parent]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: managedkafka_create_connect_cluster
19+
spec:
20+
# This test is being skipped due to a known issue with leaking Network
21+
# Attachment resources which prevents `terraform destroy` from completing
22+
# successfully in the test environment.
23+
skip: true

0 commit comments

Comments
 (0)