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.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

C#

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

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// 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);
}

Java

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

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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

/**
 * 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 {
        $deleteClusterRequest = (new DeleteClusterRequest())
            ->setName($clusterName);
        $instanceAdminClient->deleteCluster($deleteClusterRequest);
        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.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

cluster.delete

What's next

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