https://pulumi.com logo
Title
b

billowy-area-48390

04/07/2022, 2:23 PM
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:
* 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

great-queen-39697

04/07/2022, 3:43 PM
It sounds like you need to set a
depends_on
flag: https://www.pulumi.com/docs/intro/concepts/resources/options/dependson/
b

billowy-area-48390

04/07/2022, 3:50 PM
That’s what I thought at first too but
depends_on
works for resources but not invocations
g

great-queen-39697

04/07/2022, 4:11 PM
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

billowy-area-48390

04/07/2022, 4:32 PM
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

great-queen-39697

04/07/2022, 6:35 PM
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

billowy-area-48390

04/08/2022, 2:16 PM
Thank you!
🙌 1
g

great-queen-39697

04/08/2022, 3:18 PM
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:
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

billowy-area-48390

04/08/2022, 3:22 PM
It makes sense! Thanks, I’ll try that
g

great-queen-39697

04/08/2022, 3:25 PM
You're welcome! Let me know how it goes so I can file that one away 😄