https://pulumi.com logo
#aws
Title
# aws
b

bumpy-laptop-30846

04/22/2021, 1:10 PM
Hi, Is there a solution to use
Copy code
const elb =  aws.elb.getLoadBalancer( { name: elbName });
with elbName being an output. Is there a way around? Otherwise I don’t see how to address my use case, which I don’t develop here…
w

witty-candle-66007

04/22/2021, 1:29 PM
I’m not sure I’m following your question. Do you mean
elbName
is an output property of another resource and you want to use it in the
getLoadBalancer
call?
b

bumpy-laptop-30846

04/22/2021, 1:30 PM
yes, that’s actually my question 🙂
w

witty-candle-66007

04/22/2021, 1:30 PM
If so,
.apply()
is your friend: https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply So it’ll be something like
Copy code
const elb = otherResource.elbName.apply(elbName => aws.elb.getLoadBalancer({name: elbName})
b

bumpy-laptop-30846

04/22/2021, 1:31 PM
that’s what I did but I get a side effect
It seems to be linked to this: (from the doc) During some program executions, 
apply
 doesn’t run. For example, it won’t run during a preview, when resource output values may be unknown. Therefore, you should avoid side-effects within the callbacks. For this reason, you should not allocate new resources inside of your callbacks either, as it could lead to 
pulumi preview
 being wrong.
w

witty-candle-66007

04/22/2021, 1:54 PM
Yes, that’s true, but since you are only doing a
get
in this block it shouldn’t matter. That said, what is the other resource from which you are getting the
elbName
. I’m wondering why you need to do the
getLoadBalancer
in this use-case.
b

bumpy-laptop-30846

04/22/2021, 2:01 PM
I get it from an helm ressourceProperty. It’s actually the name of a kubernetes service LB which has the name of the elb
w

witty-candle-66007

04/22/2021, 2:05 PM
Ahh. So, I guess I go back to my original thought that since it’s a
get
function it should be fine to use the
.apply()
logic in this case. Is it actually causing issues for your deployment?
b

bumpy-laptop-30846

04/22/2021, 2:12 PM
yes but the issue might not come from there. I also find strange that
Copy code
aws.route53.getZone( { name: 'xxxx' } )
returns a promise rather than a pulumi output. is it ok to use ‘then’ to get a value as with ‘apply’ in this case?
w

witty-candle-66007

04/22/2021, 2:17 PM
yes
b

bumpy-laptop-30846

04/22/2021, 2:26 PM
thank you for the info!
l

little-cartoon-10569

04/22/2021, 8:29 PM
You might not need to use apply or then in these cases. You can wrap Promises in Outputs (e.g.
const elb =  aws.elb.getLoadBalancer( { name: elbName });
, which allows Pulumi to do its magic lifting thing to access properties (e.g.
const newResource = new YourResource(name, { loadBalancerArn: elb.arn, ... });
).
This only works when you're passing the promise-wrapped-in-an-output to a Pulumi constructor, but that is the most common use case, so it's often helpful.