https://pulumi.com logo
#dotnet
Title
# dotnet
l

late-ability-31616

06/11/2022, 8:24 PM
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

billowy-army-68599

06/11/2022, 8:34 PM
@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

late-ability-31616

06/11/2022, 8:38 PM
@billowy-army-68599 Thank you! I tried that but couldn't get it to compile, because File.WriteAllText doesn't return a string:
b

billowy-army-68599

06/11/2022, 8:39 PM
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

late-ability-31616

06/11/2022, 8:40 PM
I could do something like this:
Copy code
env.Id.Apply(v => { File.WriteAllText(@"env-id.txt", $"env-id = {v}"); return string.Empty; });
b

billowy-army-68599

06/11/2022, 8:40 PM
yup
l

late-ability-31616

06/11/2022, 8:40 PM
ah okay
k that works, thanks!
4 Views