Terraform and ansible

For proof of concepts, I need a way to quickly spin up the test droplet with Docker installed.
In this post, I will you show an example to get this done with terraform and ansible.

3 steps:

  • provision new droplet and firewall configuration: 00_create_do_droplet.tf
  • generate local ansible inventory with the newly created droplet IPv4 address: 01-create-inventory.tf
  • run ansible-playbook to setup docker service on the remote host: 02-setup-docker.tf

Demo:

  • firewall configuration includes Cloudflare external IPv4 subnets (from here);

Source code: kariedo/terraform-ansible-docker-example

Before you start you need to adjust your local IP (home_ipv4_addr) and SSH fingerprint (ssh_fingerprint) variables in terraform.tfvars