Stop a Compute Engine instance through an HTTP request

Makes an authenticated request within a workflow, using OAuth 2.0 to stop a Compute Engine instance.

Code sample

YAML

- initialize:
    assign:
      - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_NUMBER")}
      - zone: "us-central1-a"
      - vm_to_stop: "examplevm"
- stop_instance:
    call: http.post
    args:
      url: ${"https://compute.googleapis.com/compute/v1/projects/"+project+"/zones/"+zone+"/instances/"+vm_to_stop+"/stop"}
      auth:
        type: OAuth2
    result: stop_result

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.