I am really having some trouble I was hoping someo...
# python
g
I am really having some trouble I was hoping someone would be able to help.  I am trying to feed a Pulumi Python Output to a configuration that expects a string.  For the life of me I cant seem to figure out how to get the output object to a string.  The string I need to feed is to another python module for configuring a SaaS application, but I can imagine I am going to have the same problem if I need to use a pulumi program inline with AWS boto3.  Can someone share a snippet?   This is the only way I have found that somewhat works.  Write to a file and then read it when I need to assign the variable which is horrible
Copy code
# define a function to write an arn to a file
def write_to_file(arn):
    f = open("arn.txt", "a")
    f.write(arn)
    f.close()

json = lb.arn.apply(lambda a: write_to_file(arn=a))
r
You’ll have to set the configuration within the apply… the idea being that whatever that needs to happen can only happen once that resource exists. So “whatever that needs to happen” must happen in the apply.
The string I need to feed is to another python module for configuring a SaaS application, but I can imagine I am going to have the same problem if I need to use a pulumi program inline with AWS boto3.
Or maybe you need a stack output? I can’t quite pinpoint what you mean by this. Can you show what it looks like when the file is being read? I can give you more specific help with a more complete code sample.
g
import pulumi_aws as aws from pulumi import StackReference import strongdm firststack = StackReference(f"smpnet74/pulumi-scaffold/dev") client = strongdm.Client(api_access_key, api_secret_key) gateway = strongdm.Gateway( name="example-gateway009834", listen_address=firststack.get_output("NLB"), )
I am trying to use the output of a stackreference which is a pulumi output object where I need a string. Apply always seems to return an pulumi output object. The only way I can get to the actual string is to write it to a file in the lambda. In this example, firststack is a stack reference. listen_address needs to be a string. How do I lift the value from firststack.get_output("NLB") and use it as a string?
I completely understand if I want to return a pulumi object that I need to make the changes in the apply. But other pip modules I would like to use in my code require strings rather than pulumi objects. How do I lift the string out of the object and use it.
Maybe this just isn't possible but I do it so often in Terraform that I just can't wrap my mind around that it wouldn't be available in Pulumi.
So instead of writing to a file or setting an environment variable, is there any way to get a python output object to a string that can be used for templating and where strings are required?
r
The “lifting” happens within the apply.
Copy code
def create_gateway(listen_address):
    return strongdm.Gateway(
        name="example-gateway009834",
        listen_address=listen_address,
    )

gateway = firststack.get_output("NLB").apply(create_gateway)
is there any way to get a python output object to a string that can be used for templating and where strings are required
yes but the strings or templates must be created within the apply
g
my main problem with apply is that whatever you do there it returns an Output not the actual object one would expect
g
Agreed. You basically have to put everything into a function with the apply, anything you want to do with those values that wont accept a pulumi Output object. Quite a pain.
g
I've had some discussion about this with pulumi dev team here: https://pulumi-community.slack.com/archives/CDE799L1M/p1627543726257500 I want to experiment with
Output[MyType]
in another languages to see how it behaves