https://pulumi.com logo
#dotnet
Title
# dotnet
s

straight-flower-13757

02/22/2020, 4:51 AM
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

tall-librarian-49374

02/22/2020, 8:26 PM
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

straight-flower-13757

02/23/2020, 5:24 AM
Great, thanks for the hint !