fast-arm-63150
12/28/2021, 8:58 AMquiet-wolf-18467
12/28/2021, 9:08 AMfast-arm-63150
12/28/2021, 9:10 AMquiet-wolf-18467
12/28/2021, 9:15 AMprehistoric-activity-61023
12/28/2021, 10:43 AMfast-arm-63150
12/28/2021, 6:01 PMtall-photographer-1935
12/28/2021, 9:22 PMfrom pulumi import Config
import pulumi_google_native as gcp
import pulumi_gcp as gcp_classic
# Returns a map of the enabled apis for a given project
def enable_apis(project_name: str, api_list: list):
"""Method to bulk enable APIs in a given project
Args:
project_name (str): The name of the Google Cloud Project to enable APIs in.
api_list (list): The list of APIs to enable. Ex. ['<http://cloudresourcemanager.googleapis.com|cloudresourcemanager.googleapis.com>', '<http://cloudbilling.googleapis.com|cloudbilling.googleapis.com>', '<http://sqladmin.googleapis.com|sqladmin.googleapis.com>', '<http://servicenetworking.googleapis.com|servicenetworking.googleapis.com>']
Returns:
[dict]: A map of API name => Pulumi Object of the enabled APIs. Potentially useful to put in the `depends_on`
section when deploying a resource.
Ex. {
'cloudresourcemanager': Pulumi Object for Cloud Resource Manager API
}
"""
# TODO probably some data validity checks
enabled_apis = dict()
for api in api_list:
api_name = api.split(".")[0]
api_pulumi_ref = gcp_classic.projects.Service("Enable {} API in {}".format(api_name, project_name),
disable_dependent_services=True,
project=project_name,
service=api)
enabled_apis[api_name] = api_pulumi_ref
return enabled_apis
fast-arm-63150
12/29/2021, 2:36 AMprehistoric-activity-61023
12/29/2021, 3:33 PMtall-photographer-1935
12/29/2021, 9:23 PMdepends_on
in order to have the pulumi resource create after the api was enabled.fast-arm-63150
12/30/2021, 4:59 PM