Hello Pulumi team, hope all is well, thanks for th...
# getting-started
s
Hello Pulumi team, hope all is well, thanks for the great product! I'm new to Pulumi and I'm trying to automate my infrastructure. I'm trying the code below but I don't know how to access the values of the outputs of the function below
Copy code
instance = gcp.compute.get_instance_output(name=name, zone=zone, opts=pulumi.InvokeOutputOptions(depends_on=[other_instance]))
I can't get it by using
instance.current_status
, and I can't get it by using
instance.current_status.apply(lambda current_status: current_status)
. In both cases, I'm getting the following error
warning: Calling __str__ on an Output[T] is not supported.
Thank you
l
You can't get it at the "top" level of your program, because outputs are future values, not available until after your program finishes. Instead you can access them inside the apply code; those functions are run in the future, when the values are available.
s
Thank you for your answer, but my problem is still not resolved. Let me show you what I'm trying to do and if you can help me please: I want to check if my instance is terminated or not, something like this:
Copy code
def wait_until_stopped(instance):
    while True:
        returned_instance = gcp.compute.get_instance_output(name=instance.name, zone=instance.zone, opts=pulumi.InvokeOutputOptions(depends_on=[instance]))
        status = returned_instance.current_status.apply(lambda current_status: print(current_status))
        if status == "TERMINATED":
            break
but this doesn't work because status is a future value. An alternative is to use the direct form of the function
get_instance
, but then I can't use
depends_on
with it. How can I still use
depends_on
while also accessing the values at the "top" level of my code?
l
You cannot get future values now. Only in the future. You can run logic in the future, via apply. It is probably worth pointing out that current status of a resource (e.g. is terminated) is not a logical fit for Pulumi. While it can be done, I believe it probably shouldn't be. Pulumi is designed for desired state configuration: express your desired state, run the program, done. If your desired state is "terminated", then Pulumi can do this fine. However, "if current state is terminated" simply doesn't fit that model. You would be better off with a non-Pulumi program using the normal GCP SDK for this. It is easy to mix Pulumi and non-Pulumi programs within a single Go program, via autoamtion-api. That might fit your needs better? Or you might just separate the two tasks you're doing: achieving an initial desired state configuration (using Pulumi) and using/monitoring the built cloud resources (some other app).