https://pulumi.com logo
#typescript
Title
# typescript
a

acceptable-army-69872

01/10/2020, 6:36 PM
I'm trying to use one instance's privateIp in the user data of another instance. I tried doing something like
Copy code
function getIp (server: aws.ec2.Instance) {
  return pulumi.all([server.privateIp]).apply(([privateIp]) => {
                      return pulumi.interpolate`${privateIp}`;
                  });
}
to get the IP, but it still gives me the calling toString on an output error instead of the value. Thoughts on how to do this?
g

gentle-diamond-70147

01/10/2020, 6:47 PM
You can use
pulumi.interpolate
directly in that case.
Copy code
const userData = pulumi.interpolate`
IP Address: ${instance.publicIp}
Subnet ID: ${vpc.publicSubnetIds[0]}
`;
Without needing .all and .apply
a

acceptable-army-69872

01/10/2020, 7:01 PM
👏 👏 👏 👏
Okay, so here was the wrinkle.
It looks like this doesn't work, but I just stopped doing it with two strings.
Copy code
const str = pulumi.interpolate'config ${inst.privateIp}';

const otherStr = '${str}'
So I stopped using two strings, which is ugly, but since it works, whatever. I'll move on.
s

stocky-spoon-28903

01/12/2020, 7:07 PM
For two strings you can use .all and then .apply