I have a ComponentResource that take as parameter ...
# dotnet
m
I have a ComponentResource that take as parameter an
InputList<string>
, I want to iterate on this list to create different resources. Does someone know how I can dod that ?
m
You can't do directly a foreach on an InputList like for a classical C# list. From what I understood we can do it only in the Apply function which feels a bit ackward. I ended doing that (args.Secrets is of type InputList<Secret>):
Copy code
var secrets = args.Secrets.Apply(secrets =>
        {
            return secrets
                .Select(secret => new Secret(secret.Name, new SecretArgs
                {
                    SecretName = secret.Name,
                    VaultName = args.KeyVaultName,
                    Properties = new SecretPropertiesArgs
                    {
                        Value = secret.Value
                    },
                    ResourceGroupName = args.ResourceGroupName
                }))
                .ToList();
        });
Not sure that is the best way to do but at least that compiles.
t
It's not possible without doing it inside an apply. Do you need to accept an InputList as a parameter or could you accept a plain sting list or array?
m
@tall-librarian-49374 I thought InputList was the proper type I needed but now I am not sure. I need to pass a list of key value pairs (keys are normal string, but values can come from outputs of other resources) to a ComponentResource. What do you think, is InputList what I need. Creating such an InputList seems to be complicated. I have just created a GitHub discussion about this before I saw your reply. Any idea how I could make that easier. https://github.com/pulumi/pulumi/discussions/9307 (For a bit of context, I am creating a Security ComponentResource that will be in charge of creating Azure Key Vault Secrets from key value pairs being passed in parameter).
t
I think you should use a
Dictionary<string, Output<x>>
. This way you can know the number of entries in the constructor and create the right set of resources, while passing outputs in their properties.
m
Okay I see. Thanks for the advice, I will try this way.