Terraform Helper Script
After getting my start using terraform recently, I found myself wanting an easy way to accomplish a couple basics tasks
- 1.) Making main.tf files for multi node infrastructures
- 2.) Creating the other supporting files for a deployment
- 3.) Modifying a main.tf shared with me to be deployed using an env.tfvars file, because, well, its easier,
In order to address these tasks I have built a basic bash script that accomplishes the task above as its three main functions. This is definitely not a “for the everyday user” tool as its a command line tool but its actually pretty easy to use so long as your familiar with launching a script in linux.
You can find the script and its documentation here,
The welcome menu offers easy navigation between the functions
The first function, “install terraform”, does work, though I suggest doing this manually as its not a hard task and this is a relatively untested function.
The second function “Generate a main.tf” offers the ability to create a network of any number of vms and configure those vms each with their own sets of specfications. to include all resources, number of disks, size, mount point, and what output variables to include for each vm. It will output the main.tf to your specified path and so far in testing, these main.tf files are immeadiately deployable.
- The entire process is managed through prompts so that you are not responsible for any formatting.
- There are default values on all prompts, exluding selecting your output variable. you can litterally make a deployable main.tf by pressing enter over and over then selecting 4 output variables from a list that is displayed.
The third function generates the env.tfvars files that are used to deploy the main.tf files generated by function 2.
The fourth function take a main.tf that is not setup to be deployed with a env.tfvars file and modifies it so it is. as an example this can be used to make the examples available on github deployable with your enviroment variables file.
Here are some quick videos of the script and its functions
making a new main.tf and env.tfvars
modifying an exsisting main.tf
this work is one hundred and ten percent open source, modify it, use it, share it, just build with it.