BLOG

Introduction to Infrastructure as Code (IaC) & Terraform

著者: Ricardo Ruiz Maldonado

     

投稿日: 2022年10月04日  更新日: 2023年08月05日

 
  • IaC

Infrastructure Provisioning

Infrastructure Provisioning is the process of setting up IT infrastructure. Provisioning and configuration are often mistaken however they are not the same thing. To configure, first, we need to provision.

There are many types of "provisioning" but, some of the most important are:

Server provisioning

It is the process required to create and set up a new machine that will work as our server, from the physical hardware to the software configuration, networks, etc.

Network provisioning

Sets up the network that the applications, servers, containers, etc. will use.

Infrastructure as Code (IaC)

Infrastructure provisioning has always been a crucial part of Software Engineering. In the past, provisioning has typically been a manual and physical task. This indicates that for setting up or updating the infrastructure, we needed to buy, install, set up, and provision the new hardware making it difficult to reproduce, very time-consuming, and prone to human error.

With the rise of the popularity of Cloud computing, many things have changed. We don't longer need to build and maintain a physical infrastructure, instead we can set it up quickly using any of the cloud services. The first approach that many people have when using a cloud service is through the UI, and while this is a good idea for getting used to, we can still have inconsistency issues, especially if there's a team in charge of the infrastructure configurations.

One of the main principles of DevOps is to treat infrastructure the same way we treat code. With IaC, we can define our Infrastructure specifications through configuration files that will allow us to:

  • Version control. It doesn't matter if it's git, svn, or any other version control system (VCS). However, using a VCS is always a good practice.
  • Replicate the same environment/infrastructure every time.
  • Make code the single source of truth. - Every infrastructure change must be reflected in the code.
  • Modularize components that can be reutilized - e.g., for the different environments of an application.

IaC approaches

Declarative

The declarative approach specifies the target infrastructure. It has the name of the resources that you need and their properties. This approach focuses on the "what" you want, and the IaC should figure out "how" to achieve it.

This approach also keeps the current state of the infrastructure, which comes in handy when updating or taking down the infrastructure since the IaC tool will attempt to find the best way to apply those changes.

Imperative

The imperative approach focuses on the specific steps or commands required to reach the target infrastructure or configuration. If you don't execute these commands in the correct order, the provisioning will fail. The user must figure out how to apply any new changes.

Some popular IaC tools are:

  • Chef - Imperative
  • Puppet - Declarative
  • Terraform - Declarative

Terraform

Terraform is an IaC tool created by HashiCorp that lets you create and manage your infrastructure through configuration files. You can virtually work with any platform or service that has an API, by using the different Terraform providers. Terraform's documentation is one of its biggest strengths. There you can find all the public providers that the community or HashiCorp have created.

Terraform's configuration language is declarative, and as we have already discussed, this means that it describes the target infrastructure and will delegate the "how" to do it to Terraform and in particular, to the Terraform providers.

The five steps for deploying with Terraform:

  • Scope - Identify your infrastructure requirements and which cloud services you will use.
  • Author - Write your configuration files. Treat them as code. Use a version control system (VCS), test and create modules that can be re-utilized.
  • Initialize - Install the necessary Terraform providers or plugins. Since Terraform uses a declarative approach, it needs to know the current state of your infrastructure (if there's any) by creating a state file.
  • Plan - See what changes terraform will apply by using the state file. This step doesn't change anything and is very useful to detect possible errors or mistakes.
  • Apply - Apply the planned changes to the actual infrastructure.

Kandasearch

We apply IaC and Terraform to provide the best experience to our users when provisioning their solr instances.

References

お見積もり・詳細は KandaSearch チームに
お気軽にお問い合わせください。

お問い合わせ