Hi all, first of all thanks for the great tool I h...
# dotnet
s
Hi all, first of all thanks for the great tool I have a question regarding async operations in
ComponentResource
I have something similar to this in the
Deployment.RunAsync
like
Copy code
return Deployment.RunAsync(async () =>
{
            var assumeRoleDocument = await Pulumi.Aws.Iam.Invokes.GetPolicyDocument(new Pulumi.Aws.Iam.GetPolicyDocumentArgs
            {
                Statements = {
                    ...
                    }
                }
            });

            var ecsPolicyRole = new Pulumi.Aws.Iam.Role($"{name}-ecs-role", new Pulumi.Aws.Iam.RoleArgs
            {
                AssumeRolePolicy = assumeRoleDocument.Json
            });

});
Now I’m trying to move that into a dedicated module, using
ComponentResource
What is your recommendation for doing that since I can’t await in the constructor of the custom
ComponentResource
? I did this hack, but not sure if I’m missing something that will make it more straight forward:
Copy code
public class EcsService : ComponentResource
    {
        public EcsService(string name, EcsServiceResourceOptions options)
            : base("foo:pulumi:ecs", name, options)
        {
             var assumeRoleDocument = Pulumi.Aws.Iam.Invokes.GetPolicyDocument(new Pulumi.Aws.Iam.GetPolicyDocumentArgs
            {
                Statements = {
                    ...
                    }
                }
            });

            var ecsPolicyRole = new Pulumi.Aws.Iam.Role($"{name}-ecs-role", new Pulumi.Aws.Iam.RoleArgs
            {
                AssumeRolePolicy = Output.Create("").Apply(async _ => (await assumeRoleDocument).Json) //getting advantage of the built in Output type and its Apply func
            }, new CustomResourceOptions { Parent = this });
         }
      }
t
Great question, and I think you are very close. I would do something like
Copy code
AssumeRolePolicy = Output.Create(assumeRoleDocument).Apply(v => v.Json)
Output.Create
has an overload accepting a task.
s
Great, thanks for the hint !