When creating a resource you can provide CustomRes...
# general
p
When creating a resource you can provide CustomResourceOptions where you can specify that it DependsOn another resource. But when you use one of the Get/Invoke methods, to get a value from a resource to use for something else you don't have this options in InvokeOptions. What is the way to go to mark an Invoke() to have a dependency on something that potentially hasn't been created yet?
m
One way to do that would be to do it “in the apply” — for example in TypeScript:
Copy code
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("my-bucket");

bucket.id.apply(async id => {
    const lookedUpBucket = await aws.s3.getBucket({
        bucket: id,
     });

    console.log(lookedUpBucket.arn);
});
However it’s somewhat unusual to do this within the scope of a single program, since after creating the resource, you already have a handle to it by name — e.g., as
bucket
or
bucket.id
. So might be good to hear a bit more about your use case if this doesn’t work for you.
p
In one of our particular use-cases, we are creating an Azure Storage Account. As the keys are not available on the Storage Account object, we then use
ListStorageAccountKeys.InvokeAsync()
to fetch the keys and then store those in a keyvault. The problem is that the InvokeAsync call requires args that has the resource group name as a string (Output<string> not accepted). To solve this we used resourcegroup.GetResourceName() to get the name of the resource group. However, this crashes in the preview. Maybe .Apply() is the trick then instead of GetResourceName? We have a couple of other places in the code where we do InvokeAsync() as well and it would've been really nice to be able to provide dependencies for these methods.