After a topic is created, you can edit the topic configuration to update these properties: the number of partitions and topic configurations that don't default to the properties already set at the cluster-level. You can only increase the number of partitions, you cannot decrease it.
To update a single topic, you can use the Google Cloud console, the Google Cloud CLI, the client library, the Managed Kafka API, or the open source Apache Kafka APIs.
Required roles and permissions to edit a topic
To get the permissions that you need to edit a topic,
ask your administrator to grant you the
Managed Kafka Topic Editor(roles/managedkafka.topicEditor
)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to edit a topic. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to edit a topic:
-
Update a topic:
managedkafka.topics.update
You might also be able to get these permissions with custom roles or other predefined roles.
For more information about this role, see Managed Service for Apache Kafka predefined roles.
Edit a topic
To edit a topic, follow these steps:
Console
In the Google Cloud console, go to the Clusters page.
- Click the cluster to which the topic that you want to edit belongs.
The Cluster details page opens. In the cluster details page, for the Resources tab, the topics are listed.
- Click the topic that you want to edit.
The Topic details page opens.
- To make your edits, click Edit.
- Click Save after the changes.
The clusters you created in a project are listed.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Run the
gcloud managed-kafka topics update
command:gcloud managed-kafka topics update TOPIC_ID \ --cluster=CLUSTER_ID \ --location=LOCATION_ID \ --partitions=PARTITIONS \ --configs=CONFIGS
This command modifies the configuration of an existing topic in the specified Managed Service for Apache Kafka cluster. You can use this command to increase the number of partitions in the topic or update topic-level configuration settings.
Replace the following:
TOPIC_ID: The ID of the topic.
CLUSTER_ID: The ID of the cluster containing the topic.
LOCATION_ID: The location of the cluster.
PARTITIONS: The updated number of partitions for the topic. You can only increase the number of partitions, you cannot decrease it.
CONFIGS: Topic-level optional configurations. Specify as comma-separated key-value pairs. For example, `compression.type=producer`.