Infrastructure as Code

Infrastructure as code, also known as programmable infrastructure, is a way of building and managing an application’s entire environment through predefined code. It enables developers and administrators to recreate the same environment on multiple physical machines. An environment that can be reproduced is crucial to efficient development, testing, and deployment. As the size and complexity of a service increases, so does the difficulty in reproducing it consistently.

Administrators often rely on scripts to automate this process. Infrastructure as code performs a similar service while also adding automation, version control, true cross-platform support, and other features. Infrastructure as code typically consists of one or more definition files written in a high-level language, which contain instructions that are read and interpreted by a separate tool.

Challenges with Manual Deployments

Infrastructure as code seeks to solve the problem of managing and deploying infrastructure. Existing approaches that often involve manual intervention can make it difficult to keep track of how environments have been configured and how they are currently being managed. For instance, it can be possible to create an environment for a very small application following manual steps in a document, but as the application and infrastructure grows in size and complexity, the chance for human error does as well.

Applications of all sizes can benefit from automation. With larger applications we can quickly find ourselves in situations where multiple machines or environments are using inconsistent configurations for the same application. Tracking changes across the environment and who made them can be nearly impossible. Deploying multiple environments, such as dev, test, and prod in a consistent way becomes error-prone and challenging. It can be impossible to audit and determine who made changes to the environment, and this can impact potential compliance requirements. We can avoid much of that pain through automation.

Infrastructure as Code as a Solution

With infrastructure as code, we can define environments that are easily updatable, consistently reproducible, distributable, version-controlled, and disposable.

Updating the Environment

In an agile development project, application requirements can change rapidly. An environment built for last week’s version might not work for today’s version. Instead of having to manually tear down and rebuild your test environment from scratch, you can simply change how your environment is defined and automatically build a new environment tailored to the latest version of the application.


Image Pets vs. Cattle

The pets and cattle metaphor is commonly used to describe how we should think about servers today—treat them like cattle. They are a part of a herd, almost identical, and when they get sick we replace them with another one instead of nursing them back to health. If any server in the organization is known by name and pain is felt when it’s down, then it’s being treated like a pet.


Maintaining Consistency

Consistency is key when it comes to microservices. When it’s time to deploy, having a way of accurately reproducing an environment on another system greatly reduces the chance of an error. Because infrastructure as code relies on predefined code to create the environment, each instance of the environment is guaranteed to run the same. This also makes the environment easy to share with developers, quality assurance, or operations.

Tracking Changes

Because infrastructure as code relies on definitions instead of actual environments, changes can easily be tracked using a version control system such as Git, Subversion, or Mercurial. Not only does this help keep track of changes to the environment, but it also helps administrators maintain different versions of the environment for different versions of the application.

Removing Old Environments

If an environment is no longer needed, traditionally the programs and services belonging to that environment had to be removed manually. With infrastructure as code, you can define tasks that automate this process. For instance, in Microsoft Azure, you can remove an entire environment by simply deleting resource group. By using a compartmentalized service such as Docker, you can even remove a resource without affecting the host machine.


Image Test-Driven Infrastructure

Infrastructure as code changes the way we need to look at testing. One approach to doing this is through a test-driven infrastructure. Similar to test-driven development, a test-driven infrastructure is designed around a predetermined set of test cases that must pass successfully.


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

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