In this lecture,
we will get introduced to Infrastructure as Code,
which is commonly known as IAC.
We will also take a look at commonly used IAC tools.
Earlier, we discussed about provisioning
by making use of the management console
of various cloud providers.
The better way to provision cloud infrastructure
is to codify the entire provisioning process.
This way we can write and execute code,
to define, provision, configure, update,
and eventually destroy infrastructure resources.
This is called as Infrastructure as Code or IAC.
With Infrastructure as Code,
you can manage nearly any infrastructure component
as code,
such as databases, networks, storage, or even application configuration.
The code you see here is a shell script.
However, it is not easy to manage it.
It requires programming or development skills
to build and maintain.
There's a lot of logic that you will need to code,
and it is not easily reusable.
That's where tools
like Terraform and Ansible help with code
that is easy to learn, is human readable and maintain.
A large shell script can now be converted
into a simple Terraform configuration file
like this.
With Infrastructure as Code,
we can define infrastructure resources
using simple, human readable high-level language.
Here is another example
where we will be making use of Ansible
to provision three AWS EC2 instances,
making use of a specific AMI.
Although Ansible and Terraform are IAC tools,
they have some key differences in what they are trying to achieve,
and as a result,
they have some very different use cases.
Here, we'll see these differences next.
There are several different tools part
of the Infrastructure as Code family;
Ansible, Terraform, Puppet,
CloudFormation, Packer, SaltStack,
Vagrant, Docker, et cetera.
Although you can possibly make use of any of these tools
to design similar solutions,
they have all been created to address a very specific goal.
With that in mind,
IAC can be broadly classified into three types;
configuration management:
Ansible, Puppet, SaltStack fall into this category.
Tools used for server templating;
Docker, Packer, and Vagrant fall into this category.
Finally, we have infrastructure provisioning tools,
such as Terraform and CloudFormation.
Let's look at these in a bit more detail.
The first type of IAC tool that we are going to take a look at
is configuration management tools.
These include tools
like Ansible, Chef, Puppet, and SaltStack,
and these are commonly used to install and manage software
on existing infrastructure resources
such as servers, databases, networking devices, et cetera.
Unlike the ad-hoc shelf scripts that we saw earlier,
configuration management tools maintain
a consistent and a standard structure of code,
and this makes it easier to manage and update it as needed.
They are also designed to run on multiple remote resources at once.
An Ansible playbook or a role can be checked
into a version control repository.
This allows us to reuse and distribut it as needed.
However,
perhaps the most important feature of a configuration management tool
is that they are idempotent.
This means that you can run the code multiple times
and every time you run it,
it will only make changes that are necessary
to bring the environment into a defined state.
It would leave anything already in place as it is,
without us having to write any additional code.
Next,
let's look at server templating tools.
These are tools
like Docker, Vagrant, and Packer from HashiCorp
that can be used to create
a custom image of a virtual machine or a container.
These images already contain
all the required software and dependencies installed on them,
and for the most part,
this eliminates the need of installing software
after a VM or a container is deployed.
The most common examples for server templated images
are VM images
such as those that are offered on osboxes.org,
custom AMIs in Amazon AWS,
and Docker images on DockerHub and other container registries.
Server templating tools also promote immutable infrastructure
unlike configuration management tools.
This means that,
once the VM or a container is deployed,
it is designed to remain unchanged.
If there are changes to be made to the image,
instead of updating the running instance,
like in the case of configuration management tools
such as Ansible,
we update the image and then re-deploy a new instance
using the updated image.
We have a section on immutable infrastructure
later in this course
where we will look at it in much more detail.
The last type of IAC tool
which is specifically of interest for this course
is provisioning tools.
These tools are used to provision infrastructure components
using a simple declarative code.
These infrastructure components can range from servers
such virtual machines, databases, VPCs, subnets,
security groups, storage,
and just about any services based on the provider we choose.
While CloudFormation is specifically used
to deploy services in AWS,
Terraform is vendor agnostic
and supports provider plugins for almost all major cloud providers.
In the upcoming lecture,
we will see how Terraform helps in provisioning infrastructure.