https://pulumi.com logo
#cloudengineering-support
Title
# cloudengineering-support
n

narrow-area-20379

10/26/2020, 4:23 PM
Anyone figure out a neat design pattern to enable GCP service api's needed per project? Like an idempotent operation to skip and proceed if already enabled.
g

green-school-95910

10/26/2020, 4:29 PM
I made named singletons by the project id and service api
On every resource I add all the apis required as dependencies, those will be created only once and as soon as a service is not depended by any resource the service will be removed
n

narrow-area-20379

10/26/2020, 6:13 PM
I didn't quite grasp the last part, you call
projectService
for each required service. When it is no longer required, do you mean it will no longer be called or it will disable that api too?
g

green-school-95910

10/26/2020, 7:06 PM
The Pulumi resource of that API will be gone
If you configured it to disable the api once the resource is deleted then yes, the api will be disabled
It is the
disableOnDestroy
option
I set it to false to prevent breaking things. None of my resources might be using that API, but some of the google services might depend on them indirectly, like Cloud Scheduler, that depends on AppEngine, that depends on Cloud Storage
n

narrow-area-20379

10/27/2020, 11:12 PM
It works but I am hesitant to bring singleton pattern to JS. I just ask myself if it would be better to have code that checks before enabling the api instead of a singleton pattern.
g

green-school-95910

10/27/2020, 11:29 PM
What you need is the behaviour. If you have a global map of projectIds pointing to maps of services you could just return the service if it is there.
The singleton method that I went with is waay overengineered for this use case. I used it because I already had the singleton class being used in some other resources, so it made sense for the context
n

narrow-area-20379

10/27/2020, 11:32 PM
Yeah that makes sense
7 Views