Hi All, I'm hoping someone can help me clean up my...
# dotnet
m
Hi All, I'm hoping someone can help me clean up my code. I'm wondering what the "correct" way to use StackReference to read in an Output from another project is? I am trying to read in the name of an Azure Resource Group and then use it in a GetResourceGroup command. At the moment if I read it in like this...
var rgName = proj.RequireObject("ResourceGroupName").Apply(name => name.ToString());
rgName ends up being of type Output<string?> i.e. it can be null because this is what ToString returns even though I'm using RequireObject When I then cone to use rgName in my code to get the resource group
var rg = rgName.Apply(rgName => GetResourceGroup.InvokeAsyn(new GetResourceGroupArgs { Name = rgName } ));
I get a warning about a possible null reference assignment as I am passing in Output<string?>? rather than Output<string> which is what GetResourceGroupArgs wants for Name. The code works and I can hide the error using ! (i.e. { Name = rgName! }) but is there a cleaner way to do this i.e. get the value from RequireObject as Output<string> in the first place rather than Output<string?>
Looks like a normal cast works instead of the ToString()
name => (string)name
t
What is
proj
in your example? A
Config
?
If so, why not use
Require
instead of
RequireObject<T>
that returns a string directly?
m
Hi Mikhail.
proj
is a StackReference to another project so I am using
RequireOutput
, don't think Require is an option?