Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

how can i get labels on boot disk when gcp batch to create vm/instance template/boot disk

I create batch tasks with carefully  chosen labels to track and monitor costs.

I'm using python `google.cloud.batch_v1` to create my batch jobs and I've tried setting the labels field throughout the protobuf structure associated with creating the batch job.

The labels field has been set on:

- batch_v1.Runnable
batch_v1.AllocationPolicy
batch_v1.Job

This gets my labels set on the instances -- which is good, but not on the boot disk attached to the instance.  Any idea how this can be fixed?  It would certainly be nice if google batch would propogate through the labels set on the job to literally everything it creates -- however ... definitely doesn't do that on its own and seems to create some resources that don't have a way to be labeled at all ...

Solved Solved
1 4 304
1 ACCEPTED SOLUTION

Since I posted this the behavior has changed and I now see the labels I desire on the disks and other resources created by the batch service.  That's great! 

View solution in original post

4 REPLIES 4

There's no way to propagate label creation on subsequent resources automatically (btw, can't be neither done with Terraform, since these resources won't be managed by Terraform anyway). You can potentially develop a Python automation script with Google Cloud SDK to label the disks: https://cloud.google.com/python/docs/reference/compute/latest/google.cloud.compute_v1.services.disks...

@breathe Google Batch today does not forward labels in the allocationPolicy to Disks, although that might be a feature for consideration.  Batch does label newly created Disks with job id. Can that be a workaround for you? 

The labeling of the disk by job-id (which I do see on the disk) won't give me what I want/need.  While I can control the job-id when I create the batch job -- there's no way I could use that to fill the need for labels on the resources associated with the job ... The job id needs to uniquely identify the workload and I don't think there would be a way to group on it while also allowing it to serve the role of unique identifier ...  And there definitely would be no way to replicate the (very useful) different kinds of eg billing groupings that I can get with actual labels.

The labels as applied to eg the instance itself is _super nice_ and just would be great if I can get that propogated to all the related resources created by batch -- so that all the costs are associated with the correct labels in the same way that the instance costs are.

Since I posted this the behavior has changed and I now see the labels I desire on the disks and other resources created by the batch service.  That's great!