How would I go from an output --> input? I am ...
# dotnet
v
How would I go from an output --> input? I am getting a stack reference, and trying to pass that into a as a value.
Trying to go from a
Output<InputList<string>>
into a
InputList<string>
The output is coming from a stack reference.
b
How did you get
Output<InputList<string>>
? It shouldn't be coming from a stack reference like that, so did you do an
.Apply(...)
to it?
v
Hey Josh, so from that post from yesterday https://pulumi-community.slack.com/archives/CQ2QFLNFL/p1661196667662129 I have that but now I am trying to pass that into another stack. let’s say
dev
. But when I do the apply should it be something like
Apply(x => x)
this give me an error, it does let me do a
Apply(x => x.ToString())
b
Ok so there is some confusion about how the
Apply(...)
function is meant to be used so checkout this blog post: https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply To be clear,
.Apply(x => x);
is a no-op and doesn't do anything. The delegate that you pass to apply is meant to be used to transform the output of the eventual result, so if you are returning the same output you aren't doing any transformation. If you have an
Output<string> output
and you do
var newOutput = output.Apply(x => x);
than
newOutput
will still be
Output<string>
. However, if you do
var newOutput = output.Apply(x => int.Parse(x))
than you will have converted the
Output<string>
to an
Output<int>
. Note that it is still an output. You cannot get the inner value out of the output. If you have an
Output<string[]>
or an
Output<string>[]
or an
Output<IEnumerable<string>>
, any of these can be implicitly cast to
InputList<string>
without you needing to do anything. Outputs are meant to be able to be passed as inputs out of the box.
v
That is a good resource, so if I am understanding this correctly, I can do something like
StackRefProdUsers = (InputList<string>)Users
b
I don't know what
StackRefProdUsers
is or what
Users
is so it is hard to answer that
But I'm talking about an
implicit
cast, and you are doing an
explicit
cast in that example. So drop the explicit cast, and allow the compiler to tell you whether or not your instance can be cast to the input.
v
ahh I see, when dropping this is what I see.
Copy code
Cannot convert source type 'Pulumi.Output<object?>' to target type 'Pulumi.InputList<string>'
b
Yea so the stack reference is
Output<object?>
so you need to do an
.Apply(...)
where the delegate does some type checking and transformation until you get something like an
Output<List<string>>
that can be cast to
InputList<string>
🙌 1
v
Thanks a bunch!
partypus 8bit 1