Hello, Quick Question: can I use Custom Resource t...
# general
s
Hello, Quick Question: can I use Custom Resource to control state of a resource that I manage in a custom way ? I am working with Atlas MongoDB provider and I'd like to be able to create a database as a part of stack. In order to do it, I need to use Mongo driver. At the same time, I'd like to be able to keep the state of the created databases in Pulumi, as for me a database is part of infra. When I try to use a CustomResource class, I need to provide a type. If I just make up the type, I get exception like
error: unrecognized resource type (Check):
I guess I am doing something incorrectly.
l
As I understand it, a CustomResource is used for resources created by normal providers. I think what you want is a dynamic provider, which will you can use to create "dynamic" Resources (which aren't any more dynamic than normal resources.. they're just created by dynamic providers 🙂 ). There's more detail here: https://www.pulumi.com/docs/intro/concepts/resources/#dynamicproviders
You can also create a full-on non-dynamic provider if you want to support these sorts of resources in multiple languages. But dynamic providers are easier.
The important idea to start with is that you don't put code that interacts with an external provider (like mongo) into a resource class. It always goes into a provider class.