This is the fifth article in series working on scale and in this article we are going to about how to spawn infrastructure fast by using infrastructure as code and provision them using chef. This article is just one of the way how you can automate infrastructure creation. There can be many simultaneous solutions to this problem. Here we will see Infrastructure Automation with terraform and chef.
Lets first look into these components separately.
Terraform is an open source product from Hashicorp. This enables you to write your infrastructure as a code, which basically is HCL stands for hashicorp configuration language. There are many providers for terraform so you can write config from multiple clouds openstack and many more. The list of providers you can find here.
Chef is generally used for installation of packages, system configurations etc on the machines. This can be used to install basic things that you software will run on. Chef also works on a infrastructure as code theme and uses pure-Ruby, domain-specific language (DSL).
Next thing is how to interface these two things together. For these two to interface we need to know below things.
1. You can pass cloud init script in every virtual machine that spawns. It is most basic thing supported by all the cloud providers.
2. This init script is the first thing that runs when your virtual machine comes up.
3. A chef node register itself using a validation key that is provided by the chef server.
Now using these three information we will interface these two together.
In the terraform code we can specify the cloud init script which will have the validation keys, the chef-server host, the chef-client installations.
Now when the machine comes up. It will trigger the cloud init script. Next thing is the chef-client will get installed and registers itself with the chef-server using the validation key. We will also run the specific role of the machine using chef-client after the registration.
The role then takes care of all the provision and configurations on that machine.
You get your machine with all the basic things installed for your application to run.
Stay tuned for more articles on terraform other tools that will help you work with scale. That it for this article Working on Scale: Infrastructure Automation with terraform and chef.
Feel free to shoot me a question on anything related to infrastructure cloud or devops.