From 24f0c22be10aed8cef6d1f6a426198b8282c15b8 Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Tue, 10 Mar 2026 00:41:47 +0000 Subject: [PATCH 1/6] samples: Add example on creating instance with tags --- .../bigtable/InstanceAdminExample.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java index 07ae1fe007..523b3f55de 100644 --- a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java +++ b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java @@ -87,6 +87,11 @@ public InstanceAdminExample(String projectId, String instanceId, String clusterI public void run() { createProdInstance(); + /* * OPTIONAL: Testing with Tags + * If you want to test creating an instance with resource tags, comment out + * createProdInstance() above and uncomment createProdInstanceWithTags() below. + */ + // createProdInstanceWithTags(); listInstances(); getInstance(); listClusters(); @@ -141,6 +146,63 @@ public void createProdInstance() { } } + /** + * Demonstrates how to create a Production instance within a provided project with tags. + * + *

Tags are a way to organize and govern resources across Google Cloud, see: + * https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing + * + * + * NOTE: Unlike Labels, a Tag (Key and Value) must be created before it can be + * attached to a resource. + * See: https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing and + * https://docs.cloud.google.com/bigtable/docs/tags for more information. + */ + public void createProdInstanceWithTags() { + // Checks if instance exists, creates instance if does not exists. + if (!adminClient.exists(instanceId)) { + System.out.println("Instance does not exist, creating a PRODUCTION instance with tags"); + + // These are placeholders. You must create these in your GCP Organization/Project first. + String tagKey = "tagKeys/12345"; + String tagValue = "tagValues/6789"; + + // [START bigtable_create_prod_instance_with_tags] + // Creates a Production Instance with the ID "ssd-instance", + // cluster id "ssd-cluster", 3 nodes and location "us-central1-f". + String parent = "projects/" + projectId; + Instance instanceObj = + Instance.newBuilder() + .setDisplayName(instanceId) + .setType(Instance.Type.PRODUCTION) + .putLabels("department", "accounting") + .putTags(tagKey, tagValue) + .build(); + Cluster clusterObj = + Cluster.newBuilder() + .setLocation("projects/" + projectId + "/locations/us-central1-f") + .setServeNodes(3) + .setDefaultStorageType(StorageType.SSD) + .build(); + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(parent) + .setInstanceId(instanceId) + .setInstance(instanceObj) + .putClusters(clusterId, clusterObj) + .build(); + // Creates a production instance with the given request. + try { + Instance instance = adminClient.getBaseClient().createInstanceAsync(request).get(); + System.out.printf("PRODUCTION type instance %s with tags created successfully%n", instance.getName()); + } catch (Exception e) { + System.err.println("Failed to create instance: " + e.getMessage()); + throw new RuntimeException(e); + } + // [END bigtable_create_prod_instance_with_tags] + } + } + /** Demonstrates how to list all instances within a project. */ public void listInstances() { System.out.println("\nListing Instances"); From d8c6d53f93a4fadead346f1aa0025152f142f9d5 Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Tue, 10 Mar 2026 17:46:07 +0000 Subject: [PATCH 2/6] Grammar fixes --- .../com/example/bigtable/InstanceAdminExample.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java index 523b3f55de..784cea0eaa 100644 --- a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java +++ b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java @@ -106,7 +106,7 @@ void close() { adminClient.close(); } - /** Demonstrates how to create a Production instance within a provided project. */ + /** Demonstrates how to create an instance within a provided project. */ public void createProdInstance() { // Checks if instance exists, creates instance if does not exists. if (!adminClient.exists(instanceId)) { @@ -149,17 +149,17 @@ public void createProdInstance() { /** * Demonstrates how to create a Production instance within a provided project with tags. * - *

Tags are a way to organize and govern resources across Google Cloud, see: - * https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing + *

Tags are a way to organize and govern resources across Google Cloud, see + * [Creating and managing tags](https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing) * * - * NOTE: Unlike Labels, a Tag (Key and Value) must be created before it can be + * NOTE: Unlike labels, a tag (Key and Value) must be created before it can be * attached to a resource. - * See: https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing and - * https://docs.cloud.google.com/bigtable/docs/tags for more information. + * See [Creating and managing tags](https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing) + * and [Tags overview](https://docs.cloud.google.com/bigtable/docs/tags) for more information. */ public void createProdInstanceWithTags() { - // Checks if instance exists, creates instance if does not exists. + // Creates an instance if it doesn't exist. if (!adminClient.exists(instanceId)) { System.out.println("Instance does not exist, creating a PRODUCTION instance with tags"); From be54f084f8636a3ee977d9854b6b23d0174b2ecd Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Tue, 10 Mar 2026 17:46:52 +0000 Subject: [PATCH 3/6] lower case tags --- .../main/java/com/example/bigtable/InstanceAdminExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java index 784cea0eaa..1ad46874c5 100644 --- a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java +++ b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java @@ -87,7 +87,7 @@ public InstanceAdminExample(String projectId, String instanceId, String clusterI public void run() { createProdInstance(); - /* * OPTIONAL: Testing with Tags + /* * OPTIONAL: Testing with tags * If you want to test creating an instance with resource tags, comment out * createProdInstance() above and uncomment createProdInstanceWithTags() below. */ From 166069dd57e00bb013fc7cbcf81a16f5dd3926a7 Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Tue, 7 Apr 2026 18:11:30 +0000 Subject: [PATCH 4/6] address pr comments --- .../java/com/example/bigtable/InstanceAdminExample.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java index 1ad46874c5..1d806d2cf1 100644 --- a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java +++ b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java @@ -147,7 +147,7 @@ public void createProdInstance() { } /** - * Demonstrates how to create a Production instance within a provided project with tags. + * Demonstrates how to create an instance within a provided project with tags. * *

Tags are a way to organize and govern resources across Google Cloud, see * [Creating and managing tags](https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing) @@ -161,14 +161,14 @@ public void createProdInstance() { public void createProdInstanceWithTags() { // Creates an instance if it doesn't exist. if (!adminClient.exists(instanceId)) { - System.out.println("Instance does not exist, creating a PRODUCTION instance with tags"); + System.out.println("Instance does not exist, creating an instance with tags"); // These are placeholders. You must create these in your GCP Organization/Project first. String tagKey = "tagKeys/12345"; String tagValue = "tagValues/6789"; // [START bigtable_create_prod_instance_with_tags] - // Creates a Production Instance with the ID "ssd-instance", + // Creates an instance with the ID "ssd-instance", // cluster id "ssd-cluster", 3 nodes and location "us-central1-f". String parent = "projects/" + projectId; Instance instanceObj = @@ -194,7 +194,7 @@ public void createProdInstanceWithTags() { // Creates a production instance with the given request. try { Instance instance = adminClient.getBaseClient().createInstanceAsync(request).get(); - System.out.printf("PRODUCTION type instance %s with tags created successfully%n", instance.getName()); + System.out.printf("Instance %s with tags created successfully%n", instance.getName()); } catch (Exception e) { System.err.println("Failed to create instance: " + e.getMessage()); throw new RuntimeException(e); From 10abeba5308424beaef087ed0d14011a390d1e8d Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Tue, 7 Apr 2026 20:13:17 +0000 Subject: [PATCH 5/6] Fix links in code comment --- .../main/java/com/example/bigtable/InstanceAdminExample.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java index 1d806d2cf1..ef8da40c00 100644 --- a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java +++ b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java @@ -150,12 +150,12 @@ public void createProdInstance() { * Demonstrates how to create an instance within a provided project with tags. * *

Tags are a way to organize and govern resources across Google Cloud, see - * [Creating and managing tags](https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing) + * [Creating and managing tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview) * * * NOTE: Unlike labels, a tag (Key and Value) must be created before it can be * attached to a resource. - * See [Creating and managing tags](https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing) + * See [Creating and managing tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview) * and [Tags overview](https://docs.cloud.google.com/bigtable/docs/tags) for more information. */ public void createProdInstanceWithTags() { From 851c7eb9ac80a3ca5c0516ca3d55ca2df765294c Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Tue, 7 Apr 2026 20:13:59 +0000 Subject: [PATCH 6/6] Fix casing --- .../main/java/com/example/bigtable/InstanceAdminExample.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java index ef8da40c00..9a401d6f7b 100644 --- a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java +++ b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java @@ -153,7 +153,7 @@ public void createProdInstance() { * [Creating and managing tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview) * * - * NOTE: Unlike labels, a tag (Key and Value) must be created before it can be + * NOTE: Unlike labels, a tag (key and value) must be created before it can be * attached to a resource. * See [Creating and managing tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview) * and [Tags overview](https://docs.cloud.google.com/bigtable/docs/tags) for more information.