public synchronized void createInstance(List<BigtableResourceManagerCluster> clusters)
      throws BigtableResourceManagerException {

    // Check to see if instance already exists, and throw error if it does
    if (hasInstance) {
      LOG.warn(
          "Skipping instance creation. Instance was already created or static instance was passed. Reusing : {}.",
          instanceId);
      return;
    }

    LOG.info("Creating instance {} in project {}.", instanceId, projectId);

    // Create instance request object and add all the given clusters to the request
    CreateInstanceRequest request = CreateInstanceRequest.of(instanceId);
    for (BigtableResourceManagerCluster cluster : clusters) {
      request.addCluster(
          cluster.clusterId(), cluster.zone(), cluster.numNodes(), cluster.storageType());
    }

    // Send the instance request to Google Cloud
    try (BigtableInstanceAdminClient instanceAdminClient =
        bigtableResourceManagerClientFactory.bigtableInstanceAdminClient()) {
      instanceAdminClient.createInstance(request);
    } catch (Exception e) {
      throw new BigtableResourceManagerException(
          "Failed to create instance " + instanceId + ".", e);
    }
    hasInstance = true;
    this.clusters = clusters;

    LOG.info("Successfully created instance {}.", instanceId);
  }
@Test
  public void testCreateInstanceShouldThrowExceptionWhenClientFailsToCreateInstance() {
    when(bigtableResourceManagerClientFactory.bigtableInstanceAdminClient().createInstance(any()))
        .thenThrow(IllegalStateException.class);

    assertThrows(BigtableResourceManagerException.class, () -> testManager.createInstance(cluster));
  }