Search code examples
google-cloud-platformgoogle-compute-engine

GCP API - How could you determine that a VM was created via Marketplace?


I'm trying to make an API call in Python (inside a Cloud Function) to do some various things and as part of the information I'd like to pass along is whether the VM was created from something in the Marketplace.

The use case is this: The user is in the GCP Console in Compute Engine. They click on Marketplace in the left column of the display which then brings up VMs to choose from. The user picks one (say "Ubuntu 20.4 LTS (Focal)"). The display shows information about the VM with a "Launch" button. When they click that, they are then taken to the "Create an instance" page and they continue making choices and eventually create the VM.

This creates a log entry that the client's security group checks inside of a cloud function. When I look at the log entry for beta.compute.instances.insert, I don't see anything about it being created via Marketplace. If I make an API call to get the instance, there's nothing in the object returned that shows that either. Anyone know of any way to determine this?


Solution

  • It depends on what you mean by "via Marketplace". In general, the Marketplace offer is usually a Deployment Manager template and an image in a public project (public projects are available only to partners publishing to Marketplace). So if you deploy a Marketplace VM solution you will have:

    1. a VM with source image in some project outside your org; but this will also match VMs created manually using that image (does it match your "via Marketplace" definition?) and VMs created from custom images your individual users have access to. Hint: your service account assigned to function will also have access to all public images, but usually not to images shared between users.
    2. Deployment Manager deployment - that's a nice one as such deployments have some marketplace-specific labels. The problem is that deployment metadata can be deleted without deleting the deployed resources. And there's the case you mentioned with some marketplace listings being just redirections to deploying a single VM.

    I'm afraid there's no way to detect if an Ubuntu VM was deployed after visiting Marketplace, or after clicking add VM button or using CLI or terraform - for the GCE it was simply an API call to insert a new instance.