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..5bf9fa2e90 100644 --- a/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java +++ b/samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Google Inc. + * Copyright 2026 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ * delete Cloud Bigtable Instances and Clusters. * *
Tags are a way to organize and govern resources across Google Cloud, see + * [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://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 createProdInstance(boolean createWithTags) { // 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"); @@ -110,12 +130,21 @@ public void createProdInstance() { // 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.Builder instanceObjBuilder = Instance.newBuilder() .setDisplayName(instanceId) .setType(Instance.Type.PRODUCTION) - .putLabels("department", "accounting") - .build(); + .putLabels("department", "accounting"); + + if (createWithTags) { + System.out.println("Enabling tags for instance creation."); + // These are placeholders. You must create these in your GCP Organization/Project first. + String tagKey = "tagKeys/12345"; + String tagValue = "tagValues/6789"; + instanceObjBuilder.putTags(tagKey, tagValue); + } + Instance instanceObj = instanceObjBuilder.build(); + Cluster clusterObj = Cluster.newBuilder() .setLocation("projects/" + projectId + "/locations/us-central1-f")