<p>We have account on GCP which contain valid cloud Nat, now we want to get those values via
GCP sdk, I've tried the following and get empty response (maybe I use the wrong API and it not <code>ListExternalVpnGatewaysRequest</code>)</p>
<pre><code>package main

import (
    &quot;context&quot;
    &quot;fmt&quot;

    compute &quot;cloud.google.com/go/compute/apiv1&quot;
    &quot;google.golang.org/api/iterator&quot;
    computepb &quot;google.golang.org/genproto/googleapis/cloud/compute/v1&quot;
)

func main() {
    ctx := context.Background()
    c, err := compute.NewExternalVpnGatewaysRESTClient(ctx)
    if err != nil {
        fmt.Println(err)
    }
    defer c.Close()
    proj := &quot;dev-proj&quot;

    req := &amp;computepb.ListExternalVpnGatewaysRequest{
        //Filter:               new(string),
        //MaxResults:           new(uint32),
        //OrderBy:              new(string),
        //PageToken:            new(string),
        Project: proj,
        //ReturnPartialSuccess: new(bool),
    }
    it := c.List(ctx, req)
    for {
        resp, err := it.Next()
        if err == iterator.Done {
            break
        }
        if err != nil {
            fmt.Println(err)
        }
        // TODO: Use resp.
        _ = resp
        fmt.Println(resp)
    }
}
</code></pre>
<p>I need to get the following values using GCP GO SDK</p>
<p><a href="https://i.stack.imgur.com/fIGmo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fIGmo.png" alt="enter image description here" /></a></p>
<p><strong>update</strong></p>
<p>I tried the following as-is and I got error</p>
<pre><code>package main

import (
    &quot;context&quot;
    &quot;fmt&quot;
    &quot;google.golang.org/api/compute/v1&quot;
    &quot;log&quot;
)

func main() {
    project := &quot;my-proj&quot;

    region := &quot;my-region&quot;
    ctx := context.Background()

    computeService, err := compute.New(ctx)
    if err != nil {
        log.Fatal(err)
    }

    req := computeService.Routers.List(project, region)
    if err := req.Pages(ctx, func(page *compute.RouterList) error {
        for _, router := range page.Items {
            // process each `router` resource:
            fmt.Printf(&quot;%#v\n&quot;, router)
            // NAT Gateways are found in router.nats
        }
        return nil
    }); err != nil {
        log.Fatal(err)
    }

}

Error is: ./main.go:16:36: cannot use ctx (type context.Context) as type *http.Client in argument to compute.New
</code></pre>

Jenney
<p>A VPN Gateway is not the same as a NAT Gateway.</p>
<p>Use this code to list routers. Within the list of routers, is the NAT Gateways</p>
<pre><code>import &quot;google.golang.org/api/compute/v1&quot;

// Replace with valid values for your project
project := &quot;my-project&quot;
region := &quot;my-region&quot;

ctx := context.Background()

c, err := google.DefaultClient(ctx, compute.CloudPlatformScope)
if err != nil {
    log.Fatal(err)
}

computeService, err := compute.New(c)
if err != nil {
    log.Fatal(err)
}

req := computeService.Routers.List(project, region)
if err := req.Pages(ctx, func(page *compute.RouterList) error {
    for _, router := range page.Items {
        // process each `router` resource:
        fmt.Printf(&quot;%#v\n&quot;, router)
        // NAT Gateways are found in router.nats
    }
    return nil
}); err != nil {
    log.Fatal(err)
}
</code></pre>
<p><a href="https://pkg.go.dev/google.golang.org/api/compute/v1" rel="nofollow noreferrer">SDK Documentation</a></p>
