| --- |
| # ---------------------------------------------------------------------------- |
| # |
| # *** AUTO GENERATED CODE *** Type: MMv1 *** |
| # |
| # ---------------------------------------------------------------------------- |
| # |
| # This file is automatically generated by Magic Modules and manual |
| # changes will be clobbered when the file is regenerated. |
| # |
| # Please read more about how to change this file in |
| # .github/CONTRIBUTING.md. |
| # |
| # ---------------------------------------------------------------------------- |
| subcategory: "Managed Kafka" |
| description: |- |
| A Managed Service for Apache Kafka topic. |
| --- |
| |
| # google_managed_kafka_topic |
| |
| A Managed Service for Apache Kafka topic. Apache Kafka is a trademark owned by the Apache Software Foundation. |
| |
| ~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider. |
| See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources. |
| |
| |
| <div class = "oics-button" style="float: right; margin: 0 0 -15px"> |
| <a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=managedkafka_topic_basic&open_in_editor=main.tf" target="_blank"> |
| <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;"> |
| </a> |
| </div> |
| ## Example Usage - Managedkafka Topic Basic |
| |
| |
| ```hcl |
| resource "google_managed_kafka_cluster" "cluster" { |
| cluster_id = "my-cluster" |
| location = "us-central1" |
| capacity_config { |
| vcpu_count = 3 |
| memory_bytes = 3221225472 |
| } |
| gcp_config { |
| access_config { |
| network_configs { |
| subnet = "projects/${data.google_project.project.number}/regions/us-central1/subnetworks/default" |
| } |
| } |
| } |
| |
| provider = google-beta |
| } |
| |
| resource "google_managed_kafka_topic" "example" { |
| topic_id = "my-topic" |
| cluster = google_managed_kafka_cluster.cluster.cluster_id |
| location = "us-central1" |
| partition_count = 2 |
| replication_factor = 3 |
| configs = { |
| "cleanup.policy" = "compact" |
| } |
| |
| provider = google-beta |
| } |
| |
| data "google_project" "project" { |
| provider = google-beta |
| } |
| ``` |
| |
| ## Argument Reference |
| |
| The following arguments are supported: |
| |
| |
| * `replication_factor` - |
| (Required) |
| The number of replicas of each partition. A replication factor of 3 is recommended for high availability. |
| |
| * `location` - |
| (Required) |
| ID of the location of the Kafka resource. See https://cloud.google.com/managed-kafka/docs/locations for a list of supported locations. |
| |
| * `cluster` - |
| (Required) |
| The cluster name. |
| |
| * `topic_id` - |
| (Required) |
| The ID to use for the topic, which will become the final component of the topic's name. This value is structured like: `my-topic-name`. |
| |
| |
| - - - |
| |
| |
| * `partition_count` - |
| (Optional) |
| The number of partitions in a topic. You can increase the partition count for a topic, but you cannot decrease it. Increasing partitions for a topic that uses a key might change how messages are distributed. |
| |
| * `configs` - |
| (Optional) |
| Configuration for the topic that are overridden from the cluster defaults. The key of the map is a Kafka topic property name, for example: `cleanup.policy=compact`, `compression.type=producer`. |
| |
| * `project` - (Optional) The ID of the project in which the resource belongs. |
| If it is not provided, the provider project is used. |
| |
| |
| ## Attributes Reference |
| |
| In addition to the arguments listed above, the following computed attributes are exported: |
| |
| * `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/topics/{{topic_id}}` |
| |
| * `name` - |
| The name of the topic. The `topic` segment is used when connecting directly to the cluster. Must be in the format `projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID/topics/TOPIC_ID`. |
| |
| |
| ## Timeouts |
| |
| This resource provides the following |
| [Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: |
| |
| - `create` - Default is 20 minutes. |
| - `update` - Default is 20 minutes. |
| - `delete` - Default is 20 minutes. |
| |
| ## Import |
| |
| |
| Topic can be imported using any of these accepted formats: |
| |
| * `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/topics/{{topic_id}}` |
| * `{{project}}/{{location}}/{{cluster}}/{{topic_id}}` |
| * `{{location}}/{{cluster}}/{{topic_id}}` |
| |
| |
| In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Topic using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/topics/{{topic_id}}" |
| to = google_managed_kafka_topic.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Topic can be imported using one of the formats above. For example: |
| |
| ``` |
| $ terraform import google_managed_kafka_topic.default projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/topics/{{topic_id}} |
| $ terraform import google_managed_kafka_topic.default {{project}}/{{location}}/{{cluster}}/{{topic_id}} |
| $ terraform import google_managed_kafka_topic.default {{location}}/{{cluster}}/{{topic_id}} |
| ``` |
| |
| ## User Project Overrides |
| |
| This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |