Skip to content

Instantly share code, notes, and snippets.

@flowerinthenight
Last active June 9, 2018 09:48
Show Gist options
  • Save flowerinthenight/5241f3cb96b9dfb9a58e77a16be159fe to your computer and use it in GitHub Desktop.
Save flowerinthenight/5241f3cb96b9dfb9a58e77a16be159fe to your computer and use it in GitHub Desktop.
import (
...
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
compute "google.golang.org/api/compute/v1"
deploymentmgr "google.golang.org/api/deploymentmanager/v2"
)
func main() {
// Error checks are discarded for brevity.
b, _ := ioutil.ReadFile("/tmp/service-acct.json")
conf, _ := google.JWTConfigFromJSON(b, deploymentmgr.CloudPlatformScope)
// Create the client.
client := conf.Client(oauth2.NoContext)
deploymentmgrsvc, _ := deploymentmgr.New(client)
// Sample code to iterate a deployment's resources.
req := deploymentmgrsvc.Resources.List("test-project-id", "sample-deployment-id-name")
err = req.Pages(ctx, func(page *deploymentmgr.ResourcesListResponse) error {
for _, resource := range page.Resources {
computesvc, _ = compute.New(client)
// Using the same client to use the compute library.
if resource.Type == "compute.v1.targetPool" {
tps, _ := computesvc.TargetPools.Get("test-project-id", "asia-northeast1", resource.Name).Do()
...
return nil
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment