Hi, Using GCP and am trying to config some resour...
# python
r
Hi, Using GCP and am trying to config some resources only if I can find a Docker image already built like this:
Copy code
try:
    run_job_infra_image = gcp.artifactregistry.get_docker_image_output(
        location=repository.location,
        repository_id=repository.repository_id,
        image_name=f"run-job-infra-{env_long}")
except Exception as e:
    run_job_infra_image = None

if run_job_infra_image:
   ... build some more stuff
However when I "pulumi up", script raises exception and stops... Any hints on why I cannot catch the exception ? Error log: Exception: invoke of gcpartifactregistry/getDockerImagegetDockerImage failed: invocation of gcpartifactregistry/getDockerImagegetDockerImage returned an error: invoking gcpartifactregistry/getDockerImagegetDockerImage: 1 error occurred: * Requested image was not found.
m
I believe that
gcp.artifactregistry.get_docker_image_output
is executed when the program is executed, but the actual get operation runs when the Pulumi deployment engine is bringing your infrastructure into the desired state. Like all Pulumi Outputs, it's only resolved at runtime.
You can verify this by adding
print
statements in your code, like this:
Copy code
print("Attempting to find Docker image")
try:
    run_job_infra_image = gcp.artifactregistry.get_docker_image_output(
        location=repository.location,
        repository_id=repository.repository_id,
        image_name=f"run-job-infra-{env_long}")
    print("Executed get_docker_image_output()")
except Exception as e:
    run_job_infra_image = None
print("Done with the try/except block")
if run_job_infra_image:
   ... build some more stuff
You should see that all three messages are printed before the Pulumi deployment engine starts working.
According to the documentation,
gcp.artifactregistry.get_docker_image
should give you an awaitable result.
r
Thanks Kilian, then question "how do I await in Pulumi" comes ...
m
I could not find a specific example, but here are the general docs: https://www.pulumi.com/docs/iac/languages-sdks/python/python-blocking-async/
r
cheers