Delete a cluster

Delete a cluster, given a project ID and instance ID.

Code sample

C#

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

// Deltes cluster "ssd-cluster2" from instance.
// At least one cluster must remain on an instance.
// Initialize request argument(s)
DeleteClusterRequest request = new DeleteClusterRequest
{
    ClusterName = new ClusterName(projectId, instanceId, "ssd-cluster2")
};
try
{
    // Make the request
    Console.WriteLine("Waiting for operation to complete...");
    bigtableInstanceAdminClient.DeleteCluster(request);
}
catch (Exception ex)
{
    Console.WriteLine($"Exception deleting cluster {request.ClusterName.ClusterId} from instance {instanceId}");
    Console.WriteLine(ex.Message);
}

C++

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

namespace cbt = ::google::cloud::bigtable;
[](cbt::InstanceAdmin instance_admin, std::string const& instance_id,
   std::string const& cluster_id) {
  google::cloud::Status status =
      instance_admin.DeleteCluster(instance_id, cluster_id);
  if (!status.ok()) throw std::runtime_error(status.message());
}

Java

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

try {
  adminClient.deleteCluster(instanceId, CLUSTER);
  System.out.printf("Cluster: %s deleted successfully%n", CLUSTER);
} catch (NotFoundException e) {
  System.err.println("Failed to delete a non-existent cluster: " + e.getMessage());
}

Node.js

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

console.log(); //for just a new-line
console.log('Deleting Cluster');
await cluster.delete();
console.log(`Cluster deleted: ${cluster.id}`);

PHP

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
use Google\ApiCore\ApiException;

/**
 * Delete a cluster
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance
 * @param string $clusterId The ID of the cluster to be deleted
 */
function delete_cluster(
    string $projectId,
    string $instanceId,
    string $clusterId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();
    $clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId);

    printf('Deleting Cluster' . PHP_EOL);
    try {
        $instanceAdminClient->deleteCluster($clusterName);
        printf('Cluster %s deleted.' . PHP_EOL, $clusterId);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('Cluster %s does not exist.' . PHP_EOL, $clusterId);
        } else {
            throw $e;
        }
    }
}

Python

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

print("\nDeleting cluster")
if cluster.exists():
    cluster.delete()
    print("Cluster deleted: {}".format(cluster_id))
else:
    print("\nCluster {} does not exist.".format(cluster_id))

Ruby

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

cluster.delete

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.