Terraform.io is a helpful tool aimed at moving your infrastructure configuration into code.
Among others, Terraform includes a DigitalOcean (referral link) provider for defining resources (i.e. Droplets, Domains, SSH Keys), which is great for us as some of our infrastructure runs on DigitalOcean (the other main one of course being Amazon’s AWS).
Unfortunately you’ll quickly notice that a
terraform refresh shows no output, and there is no way to import existing infrastructure! Certainly makes it harder to get going with Terraform for now but it looks like this feature is still being worked on.
However with a little bit of JSON-munging we can convince
terraform refresh to find our Droplets. Fortunately all it takes is the Droplet IDs. You can find these by logging into your DO account and looking at the IDs of each Droplet in the list (if you have a lot you might want to consider using the DO API to get this list). Then create your
terraform.tfstate file with a “skeleton” containing the IDs:
terraform refresh should now find each of these resources, and if all goes well you will now see the
.tfstate file update with the attributes fetched by the API.
From here you should be able to
terraform plan as normal :)
Share this post: