This message was deleted.
# getting-started
s
This message was deleted.
b
@plain-mechanic-14459 I definitely hear you when it comes to outputs. I struggled with them as well. I previously wrote this which you may have come across when googling: https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply
❤️ 1
this definitely works, unfortunately you’re just using the
apply
in the wrong place in your code. To break this down a bit, an Input/Output is a value that isn’t know until after you get the result back from the cloud provider API. Similar to a python List or Dictionary, you have to unpack it before you can use it. In the same way you can’t access a list element without a loop, you can’t use an Input until you’ve resolved the value If you semantically think of
apply
as
resolve_api_call
it starts to make a bit more sense
To use your concrete example:
Copy code
t = Template(open(f"{getcwd()}/modules/aws_asg/user_data.tpl.sh").read())
templated_user_data = t.substitute({
    'gitlab_runner_token' : gitlab_runner_token.apply(lambda v: f"{v}"),
})
In this situation, you’re opening the
.tpl
template, then you’re trying to resolve the gitlab token value, which is the wrong way round. What you need to do, is reolsve the gitlab token value, then open the template. It ends up looking a bit like this:
Copy code
gitlab_runner_token.apply(lambda v: Template(open(f"{getcwd()}/modules/aws_asg/user_data.tpl.sh").read()).substitute.....
so in this case, you’re: • resolving the gitlab_runner_token async value • once it’s resolved, it’s now a plain string and can be used as usual in a template
if you’re still struggling, send me the full code you’re using to provision the token and I can get it working for you
p
Thanks for the in depth explanation and link!! This definitely helps, thanks a lot!
Got it to work! Your blog post explained it very well. How would you tackle having multiple Input secrets that need to be templated into one file?
Would that require the
all()
function?
b
yes you’d use
pulumi.Output.all
🙌 1
@plain-mechanic-14459 I took some of the feedback and rewrote our inputs/outputs page. WOuld you mind rereading and see if this improves things/helps? http://pulumi-hugo-origin-pr-2996-1599ff0f.s3-website.us-west-2.amazonaws.com/docs/concepts/inputs-outputs/
p
@billowy-army-68599 That link doesn't work for me
Was it a temporary deployment? I'm getting a
404 Not Found
b
p
Looks good! @billowy-army-68599
I especially like the 'Common pitfalls' section, but maybe you can make it more clear that the code is faulty other than adding
# NOTE: This example is not correct
? Maybe a big red bar in CSS 😄
❤️ 1