samples: Add example on creating instance with tags#2837
samples: Add example on creating instance with tags#2837dohun-dev wants to merge 7 commits intogoogleapis:mainfrom
Conversation
| * <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 |
There was a problem hiding this comment.
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
samples/snippets/src/main/java/com/example/bigtable/InstanceAdminExample.java
Outdated
Show resolved
Hide resolved
| * 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 |
There was a problem hiding this comment.
Nit: labels, tag, key, value are not proper names, hence we spell them in lowercase.
| * https://docs.cloud.google.com/bigtable/docs/tags for more information. | ||
| */ | ||
| public void createProdInstanceWithTags() { | ||
| // Checks if instance exists, creates instance if does not exists. |
851c7eb to
984a1d0
Compare
|
|
||
| public void run() { | ||
| createProdInstance(); | ||
| /* * OPTIONAL: Testing with tags |
There was a problem hiding this comment.
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()
...
}
There was a problem hiding this comment.
That sounds good. I made the change. Also, this PR is dependent on #2832. Should that version update to 2.75 in the pom.xml file be included in this CL or is that usually done separately?
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:
Fixes #<issue_number_goes_here> ☕️
If you write sample code, please follow the samples format.
This is dependent on 2.75.0 #2832