Hi all! How do you make sure an invocation waits f...
# general
b
Hi all! How do you make sure an invocation waits for a particular resource to be created before it’s executed ? When running pulumi up in an empty stack with this Python code:
devBucketServiceAccount = gcp.storage.get_project_service_account(devManagementProject.project_id)
I get the following error because project hasn’t been created yet:
Copy code
* Error when reading or editing GCS service account not found: googleapi: Error 400: Unknown project id: 'test-dev-management', invalid
Any help would be appreciated!
g
It sounds like you need to set a
depends_on
flag: https://www.pulumi.com/docs/intro/concepts/resources/options/dependson/
b
That’s what I thought at first too but
depends_on
works for resources but not invocations
g
Ah, my apologies; I think I need another cup of tea today. Are you creating the service account directly, or are you using a default one? Generally, if I can create the service account such as with an empty stack that I'm building from scratch, I use an Output instead of the invocation.
b
It’s the default GCP storage service account in order to assign permissions to use a custom KMS key for encryption. It doesn’t seem like there is an output for it on the gcp project module. I use this: https://www.pulumi.com/registry/packages/gcp/api-docs/storage/getprojectserviceaccount/
g
Ah, gotcha. Hm... the direct account should block until the output is available (meaning it should wait until the account is initialized). Let me check with some folks to see if this is a bug.
b
Thank you!
🙌 1
g
Ok, I misunderstood the docs myself. The call only blocks if the account is present as it's waiting for a result, not that it waits until the account initializes. Your best bet would be to wrap it in some logic, sort of like this:
Copy code
for x in range(0, 4):
    try:
        y = devManagementProject.project_id
        devBucketServiceAccount = gcp.storage.get_project_service_account(y)
    except:
        pass
You'll want to give it a spot to fail so you don't get in a loop forever. You could add a sleep() in there, but be aware that it gets a bit wonky because of the async nature of the calls Pulumi makes.
b
It makes sense! Thanks, I’ll try that
g
You're welcome! Let me know how it goes so I can file that one away 😄