Hey all, where could I find some docs on input/out...
# general
Hey all, where could I find some docs on input/output of provider Read method?
Copy code
func Read(ctx context.Context, m map[string]interface{}) (map[string]interface{}, bool, error)
The protobuf specs are probably the best text on this: https://github.com/pulumi/pulumi/blob/master/sdk/proto/provider.proto We've got plans to see about rebuilding the go interfaces (and other languages) from something like protobuf automatically so all the code documentation would be filled in and kept in sync.
🙌 1
Thanks. So would param
m map[string]interface{}
contain these properties of this struct when read is triggered: https://github.com/pulumi/pulumi/blob/master/sdk/proto/provider.proto#L258
Is there any publicly available example of Read method in custom provider? I’m trying to figure out how to combine Read on new and existing resources for importing.
I mean most of the providers implement Read but they're complex and not the easiest thing to read to learn from. And yes
will the current set of inputs that the engine currently knows about, so it's only filled in for refresh, not for import (because obv on import it's brand new and the engine doesn't know anything)
Hmm, so in case of refresh, it fills the inputs + existing properties in this map?
No just the inputs
The expectation is that Read will be able to get the existing properties, because well that's what its for,
Gotcha. Hmm. This may need some rethinking.
A trick that comes up with this sometimes is people encoding information into the ID of the resource. Your provider can return whatever string it wants for ID and that same string will be passed back for Refresh
So, I have a resource that takes an input field and generates random PGP keys (2 output properties). But I need to migrate some existing keys to Pulumi stack.
As you mentioned, I wanted to encode existing pgp data into ID so Read would work with importing
But I’m not sure how to also set up Read to access data on refresh, since it would not have data in ID, but the keys still exist somewhere in state.
I’m probably just being dumb and missing something obvious.
No it's not dumb, its a tricky use case.
We've had a few things come up where people want something stateful but don't really have anywhere to store that state and want to just use the pulumi state. Currently we don't really have a good way to do that, no defined interfaces at least. You could just manually edit the state file JSON to add your keys, if you've just got a couple of these as a one off that would be my recomendation. If you think this is going to be a recurring scenario it'd be worth raising an issue on our github discussing this, we can then track that and see about adding a feature to have some sort of first class state access.
👍 1
Hmm, that might have some merit. Maybe first generating a resource and then updating generated state JSON manually with correct values? The import should be a one time operation anyway for my migration.
But that probably wouldn’t work with properties marked as secret right? Any way I could manually encrypt them?
Any way I could manually encrypt them?
Again nothing really supported, but just set it as a secret config value with
pulumi config set --secret
then copy the encrypted text out of that
then just delete the config value once done. Again I think there's merit here to giving people first class support to state "somehow" and that would support secrets
Should work yes. Thanks for all your answers, this was super helpful.