Hi everybody, I'm new to Pulumi, and I'm using C#....
# dotnet
l
Hi everybody, I'm new to Pulumi, and I'm using C#. Is there a straightforward way to get a value from an
Output<string>
? I tried to do an assignment in the
Apply
method, but even though the resource has been provisioned, it doesn't seem to execute:
Copy code
var env = new CCloud.Environment(envName, args);
string envId = "Not set";
env.Id.Apply(v => envId = $"env-id = {v}");
File.WriteAllText(@"env-id.txt", envId);

File contains "Not set".
Is there some sort of
Wait
that I need to wrap the
Apply
call in?
b
@late-ability-31616 you need to do the
File.WriteAllText
inside the
Apply
so that the value has resolved
see https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply for a different way of explaining iut
right now you're assigning the variable inside the apply, you need to do the entire operation inside it
l
@billowy-army-68599 Thank you! I tried that but couldn't get it to compile, because File.WriteAllText doesn't return a string:
b
you can change the
Apply
to return a string, but still do some stuff inside the apply, right?
I'm very weak in C# so can't fix it for you
l
I could do something like this:
Copy code
env.Id.Apply(v => { File.WriteAllText(@"env-id.txt", $"env-id = {v}"); return string.Empty; });
b
yup
l
ah okay
k that works, thanks!