First, you need to know the URL of all the api endpoints that you want to enable; you can search for them in the Google APIs Explorer. Usually the URL has the form $api.googleapis.com
; as an example, for PubSub API the URL is pubsub.googleapis.com
.
The Deployment Manager's template to enable the PubSub API would be something like this:
Using Python:
def GenerateConfig(context):
"""Generate configuration."""
resources = []
resources.append({
'name': 'enable_pubsub',
'type': 'deploymentmanager.v2.virtual.enableService',
'properties': {
'consumerId': 'project:' + context.properties['project'],
'serviceName': 'pubsub.googleapis.com'
}
})
return {'resources': resources}
Using Jinja:
resources:
- name: enable_pubsub
type: deploymentmanager.v2.virtual.enableService
properties:
consumerId: "project: {{ properties['project'] }}"
serviceName: pubsub.googleapis.com
And to use this template to enable a particular API, you could use gcloud command:
gcloud deployment-manager deployments create $name --template $template_file --properties project:$project_id
If you want to enable multiple APIs at the same time, you can use the extend method in python and create a list of dictionaries with all the APIs you need to enable, here is the code example to enable pubsub and bigquery APIs in one run:
def GenerateConfig(context):
"""Generate configuration."""
resources = []
resources.extend([{
'name': 'enable_pubsub',
'type': 'deploymentmanager.v2.virtual.enableService',
'properties': {
'consumerId': 'project:' + context.properties['project'],
'serviceName': 'pubsub.googleapis.com'
}},
{
'name': 'enable_bigquery',
'type': 'deploymentmanager.v2.virtual.enableService',
'properties': {
'consumerId': 'project:' + context.properties['project'],
'serviceName': 'bigquery.googleapis.com'
}}]
)
return {'resources': resources}
Using Jinja:
resources:
- name: enable_pubsub
type: deploymentmanager.v2.virtual.enableService
properties:
consumerId: "project: {{ properties['project'] }}"
serviceName: pubsub.googleapis.com
- name: enable_bigquery
type: deploymentmanager.v2.virtual.enableService
properties:
consumerId: "project: {{ properties['project'] }}"
serviceName: bigquery.googleapis.com