Vini
Vini

Reputation: 11

Create GCP tags and attach it to VM using google sdk client library

Need help with google client lib for creating tags and attach to VM

            InstanceTagDetails instanceTagDetails = new InstanceTagDetails();
            instanceTagDetails.setKey("tagKeys/281475895256801");
            instanceTagDetails.setValue("tagValues/281479362924118");
            createData.setTagDetails(List.of(instanceTagDetails));

            // set tags
            Map<String, String> tags = new HashMap<>();
            if(createData.getTagDetails() != null && !createData.getTagDetails().isEmpty()) {
                for (InstanceTagDetails tagDetail : createData.getTagDetails()) {
                    tags.put(tagDetail.getKey(), tagDetail.getValue());
                }
            }

            Instance instanceResource =
                    Instance.newBuilder()
                    .setName(applianceName)
                    .setMachineType(machineType.getSelfLink())
                    .addDisks(disk)
                    .addAllNetworkInterfaces(interfaceList)
                    .setCanIpForward(Boolean.TRUE) // as pass thru VM. Important parameter. Need to check if need to be set on interface to0.
                    .setMetadata(metaData)
                    .setZone(createData.getAvailabilityZone())
//                          .setParams(InstanceParams.newBuilder().putAllResourceManagerTags(tags))
                    .build();

I have tried creating the tags manualyy from GCP and attaching it while creating the VM instance . But I need help with API for creating the tags . Any help much appreciated

Upvotes: 1

Views: 42

Answers (0)

Related Questions