|
| 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] |
0 commit comments