This message was deleted.
# dotnet
s
This message was deleted.
t
Yes, you can’t enumarate
InputMap
because it may contain unresolved values.
EcsServiceResourceOptions
is a class of yours, right? If so, you could make
EnvironmentVariables
just a normal C# dictionary and iterate through it. Alternatively, you’d need to use
Apply
on
InputMap
and do the processing inside. However, creating resources inside
Apply
should generally be avoided.
s
for
EcsServiceResourceOptions
correct, it’s mine Thanks for the suggestion on using dictionary
If I want to create a policy document that needs to insert all
arn
of the
ssm parameter
like:
Copy code
public class EcsService : ComponentResource
    {
        public EcsService(string name, EcsServiceResourceOptions options)
            : base("foo:pulumi:ecs", name, options)
        {
             ...
             var parameters = new List<Pulumi.Aws.Ssm.Parameter>();
            foreach (var variable in options.EnvironmentVariables)
            {
                var Parameter = new Pulumi.Aws.Ssm.Parameter(variable.Key, 
                ...
                , new CustomResourceOptions { Parent = this });
                parameters.Add(Parameter);
            }
            ...
            var taskInlineRoleDocument = Pulumi.Aws.Iam.Invokes.GetPolicyDocument(new Pulumi.Aws.Iam.GetPolicyDocumentArgs
            {
                Statements = {
                    new Pulumi.Aws.Iam.Inputs.GetPolicyDocumentStatementsArgs {
                        Effect = "Allow",
                        Resources = parameters.Select(_=>_.Arn.Apply(arn => arn)).ToList(), //what to do here to await all parameters to be created, and then extract their arns ?
                        Actions = { "ssm:GetParameters", "ssm:GetParameter" }
                    }
                  }
                }
            });
            ...
         }
     }
I’m finding it hard to create dynamic resources, can we have more examples were we create multiple resources and then feed them into another resource like the above example Thank in advance !
t
.Apply(arn => arn)
does nothing. You can’t await outputs. Instead, you could convert a list of outputs to an output of list with
Output.All
, however this means that you have to make your
GetPolicyDocument
call inside an
Apply
.
s
@tall-librarian-49374, the Output.All accepts a list of Inputs, not Outputs. Am I missing something ?
t
Each Output is assignable to Input. I guess we may need to add an overload for list of outputs.
s
The final taskInlineRoleDocument would look like
Copy code
var taskInlineRoleDocument = Output.All<string>(parameters.Select(_ => _.Arn).Cast<Input<string>>().ToArray())
            .Apply(async list =>
            {
                return await Pulumi.Aws.Iam.Invokes.GetPolicyDocument(new Pulumi.Aws.Iam.GetPolicyDocumentArgs
                {
                    Statements =
                    {
                        new Pulumi.Aws.Iam.Inputs.GetPolicyDocumentStatementsArgs {
                            Effect = "Allow",
                            Resources = list.ToList(),
                            Actions = { "ssm:GetParameters", "ssm:GetParameter" }
                        },
                    }
                });
            });
But I’m getting `System.InvalidCastException: Unable to cast object of type ‘Pulumi.Output`1[System.String]’ to type ’Pulumi.Input`1[System.String]. ` my understanding that assignable should mean castable.
let me know if I should open an Issue on Github, so you can track.
somehow this one works
Output.All<string>(parameters.Select(_ => (Input<string>)_.Arn).ToArray())
t
Feel free to open an issue to support
Output.All(outputs)
s
Thank @tall-librarian-49374, great work ! I will give it a shot with a PR, let me try contribute 😄