When should you use the <get()> method and when sh...
# python
b
When should you use the get() method and when should you use the specific get_*() method? I cannot think of a reason why I would want to use the former and instead think that I should always prefer the latter. What am I missing?
m
It depends what you're trying to do.
get_eips
allows you to fetch a list of IPs based on conditions/tags/filters, while
Eip.get()
is used to fetch one specific IP by ID. Also note that the
get()
method is common across Pulumi resources while
get_eips()
is a specialized utility function that only exists for Elastic IPs.
b
yes but
get()
also creates a Pulumi resource in my stack which
get_eips()
does not do. For data sources, why would I want a Pulumi resource in my stack?
m
My understanding is that the
.get()
methods are there to have a resource in the stack without controlling the resource in the stack. For example, you could have the user provide an externally managed EIP, or you create one yourself. The downstream code can be the same in both cases. With the resource in the stack, you can track and inspect changes, just as you would with a "regular" resource.