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

millions-thailand-49227

07/15/2022, 5:46 PM
👋 Folks, I’m new to pulumi. My goal is to write out an ssh config file based on an array of instances that I’ve created. Can someone please point me to the correct way of writing this array of Output interpolated strings to a file?
Copy code
export const sshConfigFragments = instances.map((instance) => {
  return pulumi.interpolate`Host ${instance.tagsAll["Name"]}
    HostName ${instance.privateIp}
    User ec2-user
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no
`;
});
c

clever-sunset-76585

07/15/2022, 5:46 PM
What is the type of
instances
? And are you wanting to write the file to your local machine?
m

millions-thailand-49227

07/15/2022, 5:47 PM
instances is an array of
new aws.ec2.Instance
Yes, I want to write the file to my local machine
c

clever-sunset-76585

07/15/2022, 5:59 PM
Something like this should work:
Copy code
pulumi.all(sshConfigFragments).apply(f => fs.writeFileSync("~/.ssh/config", f.join("\n\n")));
🙌 1
You'll have an array of
Output
values that you need to wait on and
pulumi.all
does that. Similar to
Promise.all
. Note that
pulumi
in my snippet is just an import alias for
@pulumi/pulumi
.
...and
fs
is an import alias for Node's native
fs
module.
m

millions-thailand-49227

07/15/2022, 6:49 PM
Thanks @clever-sunset-76585! This worked!
partypus 1
12 Views