Can anyone provide information on how to use a sta...
# dotnet
m
Can anyone provide information on how to use a stack reference with C# and Azure? As an example I have one project that is creating a Log Analytics Workspace (Pulumi.AzureNative.OperationalInsights.Workspace) that I need to reference from additional projects. I have tried outputting the workspace object using
Copy code
[Output]
public Output<Pulumi.AzureNative.OperationalInsights.Workspace> LogAnalyticsWorkspace { get; set; }
That seems to go out OK with the results something like
Copy code
Outputs:
  + LogAnalyticsWorkspace: {
      + URN: "urn:pulumi:<stackname>::<projectname>::azure-native:resources:ResourceGroup$azure-native:operationalinsights:Workspace::<workspacename>"
      + ID : "/subscriptions/<subscriptionid>/resourcegroups/<resourcegroupname>/providers/microsoft.operationalinsights/workspaces/<workspacename>"
      + PackageVersion: ""
    }
However when I try create a stack reference in the second project with the following code I get an error
Copy code
var coreStackReference = new StackReference("coreStackReference", new StackReferenceArgs
{
	Name = "<stackname>",
});
The error is
Copy code
invocation of pulumi:pulumi:getResource returned an error: unknown resource urn:pulumi:<stackname>::<projectname>::azure-native:resources:ResourceGroup$azure-native:operationalinsights:Workspace::<workspacename>
Is it incorrect to try and pass objects in this way? I don't seem to get the errors when just passing strings so do I need to just pass IDs rather than objects and then rehydrate them somehow?
b
Copy code
var other = new StackReference("<stackname>");
var otherOutput = other.GetOutput("x");
m
Thanks @brave-planet-10645. I am still getting the same error using the above syntax though. In the top level project I am creating my workspace and storing it in a variable called workspace (type Pulumi.AzureNative.OperationalInsights.Workspace). In order to pass this to
Copy code
[Output]
public Output<Pulumi.AzureNative.OperationalInsights.Workspace> LogAnalyticsWorkspace { get; set; }
I am using
Copy code
this.LogAnalyticsWorkspace = Pulumi.Output.Create(workspace);
Does that look correct?
b
I think that's because you're passing a resource between stacks. You can't do that. I suggest passing the name of the resource, and then using the
GetWorkspace
method in the second project to get the values you need. https://www.pulumi.com/docs/reference/pkg/azure-native/operationalinsights/getworkspace/
m
OK thanks
@brave-planet-10645 OK I think I'm making progress. I can pass across the names happily now. I am passing the resourceGroupName and the workspaceName as the getWorkspace function seems to need both. They get read into the second project as types Output<string> so I can't pass them to getWorkspace directly as it only accepts strings. I can work around this with some ugly code like
Copy code
var ws = Pulumi.Output.Tuple(resourceGroupName, workspaceName).Apply(names =>
{
	return Pulumi.AzureNative.OperationalInsights.GetWorkspace.InvokeAsync(new Pulumi.AzureNative.OperationalInsights.GetWorkspaceArgs
	{
		ResourceGroupName = names.Item1,
		WorkspaceName = names.Item2
     });
});
Am I overcomplicating things with the above or is that the only way? That still only returns me an Output<GetWorkspaceResult> so I assume I would then need to use something like Pulumi.AzureNative.OperationalInsights.Workspace.Get to get at the actual workspace. If so then I guess I can just pass IDs between projects and skip the getWorkspace piece altogether and just use Workspace.Get...? Am I missing something or does that look like the basic process?
b
if you just need the IDs, just have the IDs as outputs