0

I'm trying to get an existing resource that's not managed by my pulumi stack, and I don't want to import it. In terraform I'd use data to get the resource like so:

data "azuread_group" "apps_service_principals" {
  display_name = "apps-service-principals"
}

but I am unable to find what pulumi practice is here. The documentation from getter-functions doesn't tell you how to achieve the same thing as tf's data.

If I use Group.Get the id parameter says the unique provider id of the resource to lookup which conflicts with the linked document earlier which says:

  1. The physical ID that the resource has in the target cloud.

I'm a little confused at the above there. Is this id created by pulumi, the id of my provider, or is it the id of the AzureAD group that Azure decides?

If I just want to fetch an existing group, how should I achieve this? My code is as follows:

var group = Group.Get("apps_service_principals", "what-goes-here?", new GroupState
        {
            DisplayName = "apps-service-principals"
        });

After messing around a bit I notice there's also GetGroup.Invoke, and I think I've made progress using it like so:

Output<GetGroupResult> grpResult = GetGroup.Invoke(new() 
{ 
    DisplayName = "apps-service-principals",
});

var servicePrincipalsGroup = Group.Get("apps_service_principals", grpResult.Apply(r => r.Id));

Is the above the correct approach?

In any case, I'm still having a hard time clearing up the confusion with these get approaches

  • Is my solution above the 'correct' approach?
  • When to use ResourceType.Get()
  • When to use GetResourceType.Invoke
  • Why does ResourceType.Get() require an id, yet has a GroupState parameter? Does this essentially validate that the resource has those attributes when it finds the resource with the given id?
Bortos
  • 1
  • 1

0 Answers0