https://pulumi.com logo
#general
Title
# general
a

agreeable-hair-34658

07/29/2021, 7:57 PM
hi guys, is there any guidance on when to use the resource getter, e.g.
AzureNative.Resources.ResourceGroup.Get(name, id)
and when to use the getresource function, e.g. https://www.pulumi.com/docs/reference/pkg/azure/network/getvirtualnetwork/#example-usage? I am not sure, when to use which of both.
b

bored-oyster-3147

07/29/2021, 8:15 PM
If you look at the Get reference: https://www.pulumi.com/docs/reference/pkg/azure/network/virtualnetwork/#look-up It says:
Get an existing VirtualNetwork resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
Which makes more sense when you see that the Get method is asking for a
string name
meaning the
name
that you gave the pulumi resource, so the name that it is known by in your pulumi state. So in that case the resource must already exist in your stack. While the GetResource reference says:
Use this data source to access information about an existing Virtual Network.
So this will be making an API call to Azure to retrieve a resource that may or may not even be part of your pulumi stack.
a

agreeable-hair-34658

07/30/2021, 8:06 AM
basically, this makes sense. Still, my feeling is that this article https://www.pulumi.com/docs/intro/concepts/resources/#resource-get is a bit contrary to your opinion, because it states, that You can use the 
get
 function to consume properties from a resource that was provisioned elsewhere.
b

bored-oyster-3147

07/30/2021, 12:59 PM
That is still in line with what I said. You can use the Get method to consume properties from a resource that was provisioned elsewhere within the same stack.
Meaning elsewhere in your code. Without having to pass the resource around. So you can just pass around the name
Get is just reading your Pulumi state, as opposed to the GetResource method which is hitting your cloud provider
2 Views