:sos: I'm trying to emit a collection of `Outputst...
# dotnet
f
🆘 I'm trying to emit a collection of
Outputstring
as a stack output and failing hard 😞. The error I get with this is:
Copy code
System.InvalidOperationException: [Output] Global.GlobalStack.UserPasswords contains invalid type Pulumi.Output`1[[System.String, System.Private.CoreLib, Version=4.0.0.0
, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]:
        The only generic types allowed are ImmutableArray... and ImmutableDictionarystring, ...`.
 at Pulumi.Serialization.Converter.CheckTargetType(String context, Type targetType, HashSet`1 seenTypes)
       at Pulumi.Serialization.Converter.CheckTargetType(String context, Type targetType, HashSet`1 seenTypes)
       at Pulumi.Serialization.OutputCompletionSource.InitializeOutputs(Resource resource)
       at Pulumi.Deployment.Pulumi.IDeploymentInternal.ReadOrRegisterResource(Resource resource, ResourceArgs args, ResourceOptions options)
       at Pulumi.Resource..ctor(String type, String name, Boolean custom, ResourceArgs args, ResourceOptions options)
       at Pulumi.ComponentResource..ctor(String type, String name, ComponentResourceOptions options)
       at Pulumi.Stack..ctor(StackOptions options)
       at Global.GlobalStack..ctor() in C:\dev\logicality\cloud-infra\aws\global\Global\GlobalStack.cs:line 13
Any pointers on how to address fix this? Been hacking around and I'm just not seeing it...
t
It must be
Output<ImmutableDictionary<string, string>>
and you have to make some mind-bending output conversions to achieve this, I’m afraid
Copy code
var userPasswords = new List<Output<KeyValuePair<string, string>>>();
    foreach (var username in users)
    {
        //...
        userPasswords.Add(userLoginProfile.EncryptedPassword.Apply(p => new KeyValuePair<string, string>(username, p)));
    }

    UserPasswords = Output.All(userPasswords)
        .Apply(ps => ps.ToImmutableDictionary());
}

[Output("userPasswords")]
public Output<ImmutableDictionary<string, string>> UserPasswords { get; set; }
f
Thank you @tall-librarian-49374, that worked. I knew there was an
Apply
there somewhere but I just couldn't see how to connect the dots. It is a little mind bending and
Output.All()
is new to me. Before I posted this I did thoroughly check the docs and I cloned various repos to splunk code.... I might assert there is a gap in docs / samples around all this ( https://www.pulumi.com/docs/search/?q=Output.All 🤔 ).
t
I do understand this is hard… And yes, we should have more learning material around outputs.
👍 1