boundless-airport-99052
04/09/2020, 4:00 PMComponentResource
and want to use await
in the initialize
function as below:
export class MyComponent extends pulumi.ComponentResource {
protected async initialize(args: Inputs): Promise<any> {
await pulumi.output(args.inputA).apply(value => ....)
}
}
white-balloon-205
04/10/2020, 4:10 AMboundless-airport-99052
04/10/2020, 8:26 AMComponentResource
, called CustomSubnet
that could be instantiate several times.
Each CustomSubnet
create nested resources, BUT one of them resources should be created only once per vnet
. Let’s call it vnetRouteTable
Let say we can have:
- vnet1
(created by another stack)
- CustomSubnetA
=> must create`vnet1RouteTable`
- CustomSubnetB
- vnet2
(created by another stack)
- CustomSubnetX
=> must create`vnet2RouteTable`
- CustomSubnetY
With pulumi 1.x
, the CustomSubnet
args was taken a string vnetName: string
This value was used as a cache key to know if the corresponding vnetRouteTable
has already been created or not.
The vnetName
was retrieved from another stack output with new StackReference(..).requireOutputSync('vnetName')
With pulumi 2.0
, the method `requireOutputSync`has been removed, so I use requireOutput
which returns a pulumi.Output<string>
My Issue: I can’t use this value anymore as cache key (nor in pulumi resource name which takes a string
).
So I was wondering what I can do 🙂
I understood the usage of pulumi.Output
in resource graph dependency, but it’s not a problem here as the resource has been created by another stack, so loosing it is not an issue.
In tried several things:
1) Use initialize
method with
const vnetName = await (args.vnetName as any).promise()
This seems to work but the code is less cleaner and I don’t know what is the impact of creating other resources asynchronously here (are there impacts on resources graph and dependencies??)
2) Do not use initialize
and defer that part of code (using the cache) in the .apply
function like this :
args.vnetName.apply( name => {
if (!inCache(name)) {
this.vnetRouteTable = new azure.RouteTable(...)
} else {
this.vnetRouteTable = getFromCache(name)
}
})
The vnetRouteTable
resource is created asynchronously and I do not know the impacts but the others resources are created as previously.
AFAIK, I do not have another option.
Sorry for the long explanation but I tried to be concise and to simplify my use case.
1. What are the impact in resource graph dependencies of solution 1 or 2?
2. Do you see another solution?
3. Are you sure you want to remove the requireOutputSync
😂
Best regardspulumi.Output.apply
callback if I know that the pulumi.Output
does not wrap a resource (said differently, if the pulumi.Output
is not used for dependency graph)