https://pulumi.com logo
Title
r

rough-arm-38844

03/10/2021, 9:48 AM
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

fierce-television-51712

03/10/2021, 9:53 AM
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

microscopic-dress-1605

03/10/2021, 10:17 AM
That’s indeed the way to go.
r

rough-arm-38844

03/10/2021, 10:55 AM
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

fierce-television-51712

03/10/2021, 11:06 AM
• 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

rough-arm-38844

03/10/2021, 11:16 AM
thanks for the suggestions! will look into these and see what works best for us
f

fierce-television-51712

03/10/2021, 11:23 AM
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

prehistoric-nail-50687

03/10/2021, 2:24 PM
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