DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on • Edited on

Sparrowform - Sparrowdo Provision for Terraform Backed Instances

Meet Sparrowform

asciicast

Sparrowform is a tool to provision Terraform instances by running Sparrowdo scenarios. You bootstrap infrastructure by Terraform script and then let Sparrowdo to adjust instances by running configuration tasks against. Here is simple plan how to do this:

Bootstrap infrastructure with Terraform

Say, we have tree aws ec2 instances with corresponding Terraform resources names - example1, example2 and example3. We create instances by a related Terraform scenario bootstrap.tf:

$ nano bootstrap.tf
$ terraform apply
Enter fullscreen mode Exit fullscreen mode

Create some Sparrowdo scenarios:

Now, as we get three ec2 instances up and running, we want to apply some desired configuration to all of them, let's create three Sparrowdo scenarios, one per each instance to describe desired configuration. We should name scenarios files as $terraform-resource-type.$resource-name.sparrowfile.

For simplicity, all we want is to install Nginx server on every ec2 instance, the scenario would be trivial:

$ nano aws_instance.example1.sparrowfile

#!perl6
package-install "nginx";
service-enable "nginx";
service-start "nginx";

$ nano aws_instance.example1.sparrowfile # so on, for other two instances 

Enter fullscreen mode Exit fullscreen mode

Run provision by Sparrowform/Sparrowdo

Now, as we are ready with our Sparrowdo scenarios, let's run them on our freshly Terraform backed instances. We add --ssh_private_key, --ssh_user parameters to Sparrowform launcher so that Sparrowdo knows how to connect to the instances by ssh:

$ sparrowform --bootstrap --ssh_private_key=~/.ssh/aws.pub --ssh_user=ec2-user
Enter fullscreen mode Exit fullscreen mode

What else?

Look at Sparrowform to know more. Last nifty example to make you animated:

# We can avoid creating Sparrowdo scenarios, using Sparrowdo modules as 
# This one liner.
# Let's install Nginx server on all instances:
$ zef install Sparrowdo::Nginx
$ sparrowform --ssh_private_key=~/.ssh/aws.pub --ssh_user=ec2-user --module_run=Nginx
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
spigell profile image
Spigell

Maybe Sparrowdo need a plugin system for extending of functionality like provising through "inventory" of another cms (puppet, chef, ansible, etc)? Do you planning to make the same thing for ansible (sparrowsible, maybe)?