By Chris (Rain) Avila
Apr 3, 2017
Recently, we have been experimenting with Terraform as a method for managing the Jungle Disk environment at a high level. While Ansible is fantastic as a configuration management tool, creating a dynamic inventory can take a fair bit of work without turning to a costly solution like Ansible Tower. Without the proper amount of time to be able to dedicate to maintaining an effective dynamic inventory, I was rather impressed with the simplicity of Terraform. Terraform is single binary that you can use to build and change hosted infrastructure by using simple human-readable config files. When run, terraform loads any files in your current directory with a .tf file extension and check a .tfstatefile to see whether the items defined in your config file(s) exist and if so, make any necessary changes to them (or create them if they don’t exist).
Given that Terraform is a single binary, there are no complex installation instructions. It can be downloaded from Terraform and can be extracted into any directory, though as a best practice I would suggest it be in a directory specifically created for Terraform given that it looks in its current directory for files to load.
In the directory Terraform was extracted to, any .tf file you create will be loaded when Terraform is run. You can find a very basic example of building a server in the Terraform documentation here. For this basic (and not yet fully complete) example of how we plan to use it, we can use Terraform to create a small grouping of 6 with some minor configuration work done to ensure when a resource is spun up, it is spun up with a particular AMI on a particular instance type with particular additional details. While all of this is possible with Ansible, Terraform will remember the instances it creates and all the details about them.
In our case, we already have instances which match these details so while it’s great that Terraform will automatically manage and remember servers it creates itself, how do you add servers that already exist?
Syntax for importing the first signing server from our previous example would be “terraform import aws_instance.signing
If you’re interested in a simple and readable infrastructure management tool, take a look at their list of supported XaaS platforms.