Can Pulumi handle configuring a VM it just created...
# general
s
Can Pulumi handle configuring a VM it just created? IE installing apt packages, copying config files into it etc. Or is there a better tool suited for that?
c
Depends on how you do it, technically, sure, you can execute any code you like, including ssh / winrm into a new VM. AWS and Azure also have ways to execute code (user data / Custom Script Extension) when VMs come up. The latter would be the preferred and more managed way.
r
@stale-minister-93676 AWS for example can use the
userData
on an instance to support the
cloud-init
mechanism for instance initialization. Terraform has a resource for userdata customization that I found pretty handy (https://www.terraform.io/docs/providers/template/d/cloudinit_config.html) but you can also craft your own string and set the
userData
field directly from that. In case you're on AWS, here's the docs for cloud-init on ec2: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-cloud-init
s
Thanks guys. I was hoping I could get similar functionality to Ansible but in javascript.
r
that's essentially what I use these
cloud-init
yamls for, so you're in the right space. the string you'd end up setting would be a cloud-init yaml, which then would get run on instance standup. I've been using this for a few months now and been very happy to remove ansible from my instance configurations 😄
s
nice
c
Cloud init and user data are two things though. Former doesn't work on Windows.
r
yeah, good point. I always forget about windows 🙂
b
@stale-minister-93676 there is a way to do this in Pulumi
it shows how to write code to connect to the VM and "provision" it
it's not a built in mechanism to Pulumi, it's just using the power of the language ecosystem you are writing on
h
You can also use Packer to create aws AMI or VM image. This way you can spin up your instances faster if init code is complex and takes time to execute. And that works for Windows, except you have to script init in powershell (although choco works like a charm for installing packages).
👍 1