I'm trying to set up a workflow where I use Terraform to deploy a VM, cloud-init for basic configuration, and then Ansible to install all the necessary content inside the VM. I might even pull the Ansible playbook from a Git repository and run it locally within the VM. Is this a common approach for customizing VM deployments, or is it a bit excessive with all these different technologies involved? I'm pretty comfortable with each of them, but I want to know if combining them this way is sensible or over-engineered.
6 Answers
It's pretty common to use those tools together, but I recommend skipping the reboot and prepping your images with Packer first. The VM can come up ready to bootstrap, with cloud-init launching Ansible (or Chef, if you prefer) to get everything up and running.
What I’ve done before is use Packer to build the VM and handle most of the configurations with Ansible. Then, Terraform deploys the image with custom cloud-init scripts to finalize everything. This way, the startup is much quicker than configuring it all afterwards.
Yes, that’s how we operate! Terraform provisions EC2 instances alongside a userdata script. This script is minimal, just enough to clone our Ansible playbook and kick things off. Ansible then handles all the heavy lifting for server configuration.
I think Ansible might be unnecessary for what you’re aiming to do. Many folks manage to get their VMs configured just fine with init scripts that Terraform can run. The issue with cloud-init is rebooting during installations can be tricky; Ansible really shines there since it can resume post-reboot.
If you’re looking for a general VM deployment process: Packer creates a basic template (like setting up the user and SSH keys), then Terraform handles the deployment. Ansible will configure the VM, and consider initiating it as a resource from Terraform while passing bootstrap variables. Trust me, don’t mess with IPs in Terraform directly; I learned that the hard way!
Using Packer to create customized images and Terraform for provisioning sounds ideal. Ansible should play a role in runtime configuration management for operational tasks.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures