bored-activity-40468
07/10/2020, 2:15 PMDeployment.RunAsync<T>
what's the preferred method of awaiting in `T`'s ctor since a ctor can't be async. Doing people do Task.Run
or is there another way? An example would be wanting to call await someStack.GetValueAsync()
tall-librarian-49374
07/10/2020, 2:26 PMGetOutput
instead of GetValueAsync
. Second, there is a pattern of
1. Using a helper async method.
2. Returning outputs from it.
3. Invoking it from the constructor and assigning the result to an Output<T>
property.
This way, Pulumi would know how to await it properly using the output.
See an example here: https://github.com/pulumi/pulumi/blob/master/pkg/codegen/internal/test/testdata/aws-eks.pp.cs#L13-L17bored-activity-40468
07/10/2020, 2:54 PMnamespace StackReferenceExample {
public class SimpleStack : Stack {
[Output( "vpc" )]
public Output<Output<object?>> Vpc { get; set; }
public SimpleStack( ) {
Vpc = Output.Create( Initialize( ) );
}
private async Task<Output<object?>> Initialize( ) {
var vpcStack = new StackReference( "orionadvisortech/vpc/sandbox" );
var vpc = vpcStack.GetOutput( "vpc" );
return vpc;
}
}
}
tall-librarian-49374
07/10/2020, 5:06 PMOutput<Output<object?>>
doesnโt look correctbored-activity-40468
07/10/2020, 6:51 PMtall-librarian-49374
07/10/2020, 7:11 PMpublic class SimpleStack : Stack {
[Output( "vpc" )]
public Output<object?> Vpc { get; set; }
public SimpleStack( ) {
Vpc = Output.Create( Initialize( ) );
}
private async Task<object?> Initialize( ) {
var vpcStack = new StackReference( "orionadvisortech/vpc/sandbox" );
var vpc = await vpcStack.GetValueAsync( "vpc" );
return vpc;
}
}
if you need async
for something elsepublic SimpleStack( ) {
var vpcStack = new StackReference( "orionadvisortech/vpc/sandbox" );
this.Vpc = vpcStack.GetOutput( "vpc" );
}
otherwisepublic SimpleStack( ) {
Vpc = Output.Create( Initialize( ) ).Apply(v => v);
}
private async Task<Output<object?>> Initialize( ) {
var vpcStack = new StackReference( "orionadvisortech/vpc/sandbox" );
var vpc = vpcStack.GetOutput( "vpc" );
return vpc;
}
If vpc
is a secret and you need async for something elsebored-activity-40468
07/12/2020, 3:56 PMpulumi preview
Vpc = vpcStack.GetOutput( "vpc" ).Apply(x => (string)x);