'Adding labels for GCP App Engine Services
Any suggestion to manage App Engine labels using gcloud command or atleast from the GCP console. I am trying to add a label for an already deployed application
Cannot see any option to update App Engine Service label parameters with gcloud command
$ gcloud app instances
ERROR: (gcloud.app.instances) Command name argument expected.
Available commands for gcloud app instances:
delete Delete a specified instance.
describe Display all data about an existing instance.
disable-debug Disable debug mode for an instance.
enable-debug Enable debug mode for an instance (only works on
the flexible environment).
list List the instances affiliated with the current App
Engine project.
scp SCP from or to the VM of an App Engine Flexible
instance.
ssh SSH into the VM of an App Engine Flexible
instance.
Also any option to manage from terraform ? .
Cannot find any attributes to manage labels anything under
https://www.terraform.io/docs/providers/google/r/app_engine_standard_app_version.html
https://www.terraform.io/docs/providers/google/r/app_engine_application.html
Solution 1:[1]
Labels are now part of the API, but it does not look like it is documented. Using PATCH through the REST API can set labels on services for App Engine.
https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services/patch
The Service type does not include labels, but if you run gcloud app services describe SERVICE --format=json, you will see that labels is included in the response.
Example setting label using curl:
curl \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-X PATCH \
-d '{"labels":{"label_name":"label_value"}}' \
"https://appengine.googleapis.com/v1/apps/${project}/services/${service}?updateMask=labels"
Solution 2:[2]
A little late to the party but we needed to do something similar but using the C# AppEngine client library (Google.Apis.Appengine.v1). This works for us using the latest version of the library, assuming you've already retrieved the AppEngine service object, and you know your target projectId and service name:
var labels = new Dictionary<string,string>(); //Set your labels in here
service.Labels = labels;
var patchRequest = appEngineService.Apps.Services.Patch(service, project,
serviceId);
patchRequest.UpdateMask = "Labels";
return await patchRequest.ExecuteAsync();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | smat |
| Solution 2 | Piers Gwynn |
