Module: Gcloud::ResourceManager

Defined in:
lib/gcloud/resource_manager.rb,
lib/gcloud/resource_manager/errors.rb,
lib/gcloud/resource_manager/manager.rb,
lib/gcloud/resource_manager/project.rb,
lib/gcloud/resource_manager/connection.rb,
lib/gcloud/resource_manager/credentials.rb,
lib/gcloud/resource_manager/project/list.rb,
lib/gcloud/resource_manager/project/updater.rb

Overview

# Google Cloud Resource Manager

The Resource Manager API provides methods that you can use to programmatically manage your projects in the Google Cloud Platform. You may be familiar with managing projects in the [Developers Console](developers.google.com/console/help/new/). With this API you can do the following:

  • Get a list of all projects associated with an account

  • Create new projects

  • Update existing projects

  • Delete projects

  • Undelete, or recover, projects that you don’t want to delete

The Resource Manager API is a Beta release and is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.

## Accessing the Service

Currently, the full functionality of the Resource Manager API is available only to whitelisted users. (Contact your account manager or a member of the Google Cloud sales team if you are interested in access.) Read-only methods such as Manager#projects and Manager#project are accessible to any user who enables the Resource Manager API in the [Developers Console](console.developers.google.com).

## Authentication

The Resource Manager API currently requires authentication of a [User Account](developers.google.com/identity/protocols/OAuth2), and cannot currently be accessed with a [Service Account](developers.google.com/identity/protocols/OAuth2ServiceAccount). To use a User Account install the [Google Cloud SDK](cloud.google.com/sdk) and authenticate with the following:

“‘ $ gcloud auth login “`

Also make sure all ‘GCLOUD` environment variables are cleared of any service accounts. Then gcloud will be able to detect the user authentication and connect with those credentials.

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager “‘

## Listing Projects

Project is a collection of settings, credentials, and metadata about the application or applications you’re working on. You can retrieve and inspect all projects that you have permissions to. (See Manager#projects)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager resource_manager.projects.each do |project|

puts projects.project_id

end “‘

## Managing Projects with Labels

Labels can be added to or removed from projects. (See Project#labels)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager project = resource_manager.project “tokyo-rain-123” # Label the project as production project.update do |p|

p.labels["env"] = "production"

end “‘

Projects can then be filtered by labels. (See Manager#projects)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager # Find only the productions projects projects = resource_manager.projects filter: “labels.env:production” projects.each do |project|

puts project.project_id

end “‘

## Creating a Project

You can also use the API to create new projects. (See Manager#create_project)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager project = resource_manager.create_project “tokyo-rain-123”,

name: "Todos Development",
labels: {env: :development}

“‘

## Deleting a Project

You can delete projects when they are no longer needed. (See Manager#delete and Project#delete)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager resource_manager.delete “tokyo-rain-123” “‘

## Undeleting a Project

You can also restore a deleted project within the waiting period that starts when the project was deleted. Restoring a project returns it to the state it was in prior to being deleted. (See Manager#undelete and Project#undelete)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager resource_manager.undelete “tokyo-rain-123” “‘

## Managing IAM Policies

Google Cloud Identity and Access Management ([Cloud IAM](cloud.google.com/iam/)) access control policies can be managed on projects. These policies allow project owners to manage who (identity) has access to what (role). See [Cloud IAM Overview](cloud.google.com/iam/docs/overview) for more information.

A project’s access control policy can be retrieved. (See Project#policy)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager project = resource_manager.project “tokyo-rain-123” policy = project.policy “‘

A project’s access control policy can also be set. (See Project#policy=)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager project = resource_manager.project “tokyo-rain-123”

viewer_policy = {

"bindings" => [{
  "role" => "roles/viewer",
  "members" => ["serviceAccount:your-service-account"]
}]

} project.policy = viewer_policy “‘

And permissions can be tested on a project. (See Project#test_permissions)

“‘ruby require “gcloud”

gcloud = Gcloud.new resource_manager = gcloud.resource_manager project = resource_manager.project “tokyo-rain-123” perms = project.test_permissions “resourcemanager.projects.get”,

"resourcemanager.projects.delete"

perms.include? “resourcemanager.projects.get” #=> true perms.include? “resourcemanager.projects.delete” #=> false “‘

For more information about using access control policies see [Managing Policies](cloud.google.com/iam/docs/managing-policies).

Defined Under Namespace

Classes: ApiError, Connection, Credentials, Error, Manager, Project