Create a replicated cluster

Create a replicated cluster in the current project.

Code sample


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 cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::Project;
using ::google::cloud::StatusOr;

[](cbta::BigtableInstanceAdminClient instance_admin,
   std::string const& project_id, std::string const& instance_id,
   std::string const& zone_a, std::string const& zone_b) {
  std::string project_name = Project(project_id).FullName();
  std::string c1 = instance_id + "-c1";
  std::string c2 = instance_id + "-c2";

  google::bigtable::admin::v2::Instance in;
  in.set_display_name("Put description here");

  google::bigtable::admin::v2::Cluster cluster1;
  cluster1.set_location(project_name + "/locations/" + zone_a);

  google::bigtable::admin::v2::Cluster cluster2;
  cluster2.set_location(project_name + "/locations/" + zone_b);

  std::map<std::string, google::bigtable::admin::v2::Cluster> cluster_map = {
      {c1, std::move(cluster1)}, {c2, std::move(cluster2)}};

  future<StatusOr<google::bigtable::admin::v2::Instance>> instance_future =
      instance_admin.CreateInstance(project_name, instance_id, std::move(in),
  // Show how to perform additional work while the long running operation
  // completes. The application could use future.then() instead.
  std::cout << "Waiting for instance creation to complete " << std::flush;
  std::cout << '.' << std::flush;
  auto instance = instance_future.get();
  if (!instance) throw std::move(instance).status();
  std::cout << "DONE, details=" << instance->DebugString() << "\n";

What's next

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