Anyone figure out a neat design pattern to enable ...
# cloudengineering-support
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.
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
I didn't quite grasp the last part, you call
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?
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
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
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.
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
Yeah that makes sense