Infrastructure as code

Infrastructure as code refers to the process of creating files along with environment definitions and procedures that are going to be used to provision an environment. The DevOps concept started to use these scripts or files in a repository together with the code so that we can determine what code is going to be deployed in which environment. Using these practices, we can be sure that all servers and environments are consistent.

A typical organization or team will deploy their application in more than one environment, mainly for testing purposes. When we have environments for development, staging, and production, the biggest problem developers face is that each environment is different and requires different properties.

These properties may include the following configurations, among others: 

  • Server names
  • IP addresses and port numbers
  • Server queue connection
  • Database connection
  • Credentials

The modern era of software development suddenly brought us testability, repeatability, and transparency in building infrastructures. One of the key goals nowadays is to recreate or build complete software environments with nothing other than physical server resources within an on-premise or cloud environment.

As a consequence of this, we should be able to create database instances, populate them with initial data from scripts or backup files, and rebuild our source code to create artifacts that can be deployed whenever we want.

There are many tools that we can use to apply the concept of infrastructure as code:

  • For configuration synchronization, we can use Chef, Puppet, or Ansible
  • For containerized servers, we can use Docker to deploy new application versions

Some of the key benefits that we are going to embrace are as follows:

  • Immutable servers, which apply changes by rebuilding servers in our infrastructure instead of modifying the existing servers
  • The testing of changes to the infrastructure, which involves reproducing the environment with files that we can test in different stages of our application and infrastructure

The following diagram shows the main idea behind these two key benefits to recreate environments at each stage:

Immutable infrastructure

An automated process to provision servers gives, us the following benefits:

  • It is possible to recreate any environment or server automatically
  • Configuration files can store credentials or custom configurations that can be different for each environment
  • The environment will always be the same at different stages

In the following section, we are going to create some examples of infrastructure as code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.47.218