https://pulumi.com logo
Title
c

chilly-application-64311

05/03/2023, 10:01 AM
Hi all! Recently, I started developing a Dynamic Resource Provider in Python for a specific platform. My question is: *Is there a way to implement
get
function for a Dynamic Resource? (*https://www.pulumi.com/docs/intro/concepts/resources/get/) I need to fetch data about a particular resource but not necessarily import it into the state. I would really appreciate a short example of how this can be done.
e

echoing-dinner-19531

05/03/2023, 7:48 PM
Implement read:
def read(self, id_: str, props: Any) -> ReadResult:
Get just resolves to a ReadResource operation, which just gets the engine to call "read" on the provider. You'd have to write the get functions by hand because it's not part of the dynamic provider sdk but should be doable from copying how RegisterResource in dynamic.Resource works and how a normal resource get function looks.
Having said all that. It's probably a lot easier to just have a normal dynamic resource that you "Create" but actually just gets the info and doesn't delete the resource.
get
with dynamic isn't really tested and we don't have any examples of it.
c

chilly-application-64311

05/04/2023, 8:11 AM
Thank you very much! I like the idea of Dynamic Resource that retrieves data.
@echoing-dinner-19531, one more question, how can I ensure that I will get the up-to-date information each time I execute
pulumi up
? I assume that my dynamic resource will not get updated once I created it.
e

echoing-dinner-19531

05/04/2023, 8:21 AM
It's a little bit of a hack, but you could implement Diff so that it always returns that there's a change that needs Update so that every
up
the engine calls the Update method.
This is good use cases for us re-thinking dynamic providers and supporting something like this more natively.
c

chilly-application-64311

05/04/2023, 8:27 AM
And what do you think about putting a
timestamp
into the resource ID? IMO this will do the trick 😉
e

echoing-dinner-19531

05/04/2023, 2:15 PM
I think that might trip up some replace logic, I'd lean towards just returning a change from Diff