Reputation: 677
Is it possible to create a new Google Developer/Cloud project(for an existing Google Account) automatically using a python script ?
If its possible, Can someone please redirect me to some helpful links/references ?
Thanks,
Upvotes: 1
Views: 2079
Reputation: 3893
Is it possible?: Yes, using App Engine's Admin API or the Cloud Resource Manager APIs with although this functionality is currently in beta as of the time of writing this (08-24-2016). You can access them directly or through a client library.
Directly Via REST API:
App Engine Admin API v1beta5:
create POST /v1beta5/apps
Creates an App Engine application for a Google Cloud Platform project. This requires a project that excludes an App Engine application...
More: https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1beta5/apps/create
Cloud Resource Manager API v1beta1:
POST https://cloudresourcemanager.googleapis.com/v1beta1/projects/
Creates a Project resource.
and example request:
{
"name": "project name",
"projectId": "project-id-1",
"labels": {
"environment": "dev"
},
}
More here: https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/create
Via a python client library:
There's the Google Python Client Library
pip install --upgrade google-api-python-client
Then you'll have to build an authenticated service to the api. Every other thing you'll need for the request can be found in this doc
Ideally though, and my personal favorite, you'll want to use this client library to build such a script
pip install --upgrade gcloud
then you'll create the new project with:
from gcloud import resource_manager
client = resource_manager.Client()
# re-doing above REST example
project = client.new_project('project-id-1', name='project name',
labels={'environment': 'dev'})
project.create()
Upvotes: 3