hi, sorry this is probably such a dumb question.. ...
# general
r
hi, sorry this is probably such a dumb question.. we're just learning and getting started with IaC and Pulumi - so bear with! How do you tell Pulumi to execute some PowerShell script on the creation of, say, a new EC2 instance on AWS?
f
Also new to Pulumi and I am guessing there is probably a better way. And off the top of my head I can think of at least a few ways to achieve what you want here. But probably what I would do to start is to use userData https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html Its documented here in the pulumi docs too. https://www.pulumi.com/docs/tutorials/aws/ec2-webserver/https://www.pulumi.com/docs/tutorials/aws/ec2-webserver/
m
That’s indeed the way to go.
r
thanks. I guess looking over at how Terraform do things, they appear to have something in the form of a provisioner, either "local-exec" or "remote-exec" I don't know if that's more efficient or not, perhaps this is where something like a configuration management tool like Ansible would come into play?
out of interest @fierce-television-51712 - what other ways can you think of approaching this?
f
• The first way I am thinking of is to use immutable images. i.e. you would bake the powershell script into a new AMI image and then start the ec2 instance with that AMI so that when the instance starts, the powershell script runs. • Another way is to use a configuration management tool e.g. rpm, puppet, chef, that runs on startup. These tools would allow you to update the rpm, puppet, or chef code outside of the image and have the ec2 instance configure the powershell script itself at startup and run it. • there are other funky ways you could do it that I wouldnt advise. e.g. retrieving the powershell script from a http server and running it on startup. <- this would be like reinventing the wheel.
r
thanks for the suggestions! will look into these and see what works best for us
f
I would certainly look into the immutable image pattern. It is the basis of the docker platform. The same pattern can be applied to virtual machine instances. ami -> e2 instance docker image -> docker container It is a pretty well proven path to take. But there are horses for courses, so its best to figure out what works for you 🙂
🙌 1
👍 1
p
If you want something more along the way as terraform’s
remote-exec
, you should take a look at https://github.com/pulumi/examples/tree/master/aws-ts-ec2-provisioners
👍 1