:wave: Folks, I’m new to pulumi. My goal is to ...
# typescript
m
👋 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
What is the type of
instances
? And are you wanting to write the file to your local machine?
m
instances is an array of
new aws.ec2.Instance
Yes, I want to write the file to my local machine
c
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
Thanks @clever-sunset-76585! This worked!
partypus 1