https://pulumi.com logo
#package-authoring
Title
# package-authoring
s

salmon-helicopter-31908

02/07/2024, 5:59 PM
I'm trying to write a pulumi provider that keeps all of its state directly in the pulumi state. It is very similar to the
random
provider which also does not have its own storage and relies completely on pulumi state. I'm now wondering how an import for such a provider looks like. The schema of the bulk import file does not support specifying the properties: https://www.pulumi.com/docs/using-pulumi/adopting-pulumi/import/#bulk-import-operations I looked into how the
random
provider does it, and afaict, they just use the
id
as the value (btw. isn't that a security risk given the id is not stored encrypted in the state files?) That won't work for me, because my resources are more than just one property. The best I could come up with was to have my own custom import file that acts like the "service" a traditional provider would have when importing. I.e., the provider checks first in that file if the resource exists, and if yes, reads it from there during the create. Note that currently my provider only does Create, maybe I'm missing an action that would solve my issue. Grateful for any pointers 🙏
a

ancient-policeman-24615

02/14/2024, 2:18 AM
Hi @salmon-helicopter-31908. Import can work however you want it to. The
id
is an arbitrary string, so you can communicate anything you want in it. If you wanted to, you have have import take a JSON object representing inputs, and then model the import as a create (computing outputs). For example: Imagine a resource
Sum
with inputs
op1
and
op2
and output
result
. You could allow this:
Copy code
pulumi import pkg:module:resource three '{ "op1": 1, "op2": 2 }'
Read
would then return
{ ID: three, state: { op1: 1, op2: 2, result: 3 } }
. P.S.
Read
is used to model both
import
and
refresh
. An import will have no prior state, while a refresh will. You need to be careful that when
Read
is called for a refresh, it doesn’t change anything.
2 Views