Skip to content

samples: Add example on creating instance with tags#2837

Open
dohun-dev wants to merge 6 commits intogoogleapis:mainfrom
dohun-dev:docs2
Open

samples: Add example on creating instance with tags#2837
dohun-dev wants to merge 6 commits intogoogleapis:mainfrom
dohun-dev:docs2

Conversation

@dohun-dev
Copy link
Copy Markdown
Contributor

@dohun-dev dohun-dev commented Mar 10, 2026

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Rollback plan is reviewed and LGTMed
  • All new data plane features have a completed end to end testing plan

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the samples format.

This is dependent on 2.75.0 #2832

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigtable Issues related to the googleapis/java-bigtable API. samples Issues that are directly related to samples. labels Mar 10, 2026
Comment on lines +152 to +153
* <p>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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace addresses with Markdown links: [Creating and managing tags](https://docs.cloud.google.com/bigtable/docs/tags), same change on lines 158, 159.

Correct links are: https://docs.cloud.google.com/bigtable/docs/tags, https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: labels, tag, key, value are not proper names, hence we spell them in lowercase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* https://docs.cloud.google.com/bigtable/docs/tags for more information.
*/
public void createProdInstanceWithTags() {
// Checks if instance exists, creates instance if does not exists.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if doesn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dohun-dev dohun-dev marked this pull request as ready for review March 10, 2026 17:48

public void run() {
createProdInstance();
/* * OPTIONAL: Testing with tags
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, can we pass in an additional argument in main() to create instance with tag?

And looks like createProdInstance() and createProdInstanceWithTags are almost identical. I think you can pass the bool as an param:

main(String[] args) {
    String projectId = args[0];
    boolean createWithTag = false;
    if (args.size() > 1) {
        boolean createWithTag = Boolean.parseBoolean(args[1]);
    }

    ... 

    instanceAdmin.run(createWithTag);
}

run(boolean createWithTag) {
    createProdInstance(createWithTag);
    ...
}


createProdInstance(boolean createWithTag) {
    ...
          Instance.Builder instanceObjBuilder =
          Instance.newBuilder()
              .setDisplayName(instanceId)
              .setType(Instance.Type.PRODUCTION)
              .putLabels("department", "accounting");
          if (createWithTag) {
                instanceObjBuilder.putTags(tagKey, tagValue);
          }
           Instance instanceObj = instanceObjBuilder.build()
          
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the googleapis/java-bigtable API. samples Issues that are directly related to samples. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants