Schedule Meeting


5 benefits of Infrastructure As Code

by | Nov 10, 2020 | Database Automation

Need Help?  Click Here for Expert Support

Infrastructure As Code is a paradigm that consists of describing our infrastructure (servers and their configuration) as code that is understood by automation software like Ansible, Puppet, Terraform, and so on. Automation software can then be used to recreate the infrastructure we described or, more commonly, to fix differences between code current version and the way the infrastructure is now. Which means that, for example, we can upgrade our MariaDB version in the code, run Ansible, and have MariaDB upgraded in the relevant servers.

But what are the benefits of Infrastructure As Code? In this article I will list one of them.

Inverness Castle and Ness Bridge
Inverness Castle and Ness Bridge, Scotland

Deployment speed

How much time do you need to setup a MariaDB replica? Hint: I bet that your first answer is too optimistic. Consider you need to feed the server, setup replication, maybe a job for backups, monitoring, let proxies know about the new server, find out what the hell you did wrong in a previous step, etc.

Automation software will do it in no more than half minute, plus the time needed to import a backup (I never said it’s magic). When you have to setup or modify several servers, automation is precious. Even with 5-10 servers, it makes the difference between a reasonable activity and a miserable life. With 20 servers, it makes the difference between being able to deploy or not.

Avoiding human mistakes

Depending on which tools we use, the code could describe the configuration we want to have or the steps to reach the result we want. But whichever approach we use, deployments can be tested on staging before applying them to production. The software we use will always apply configuration in the same way. It will not forget a variable and will not mistype a command. Automation is much more reliable than humans, when it comes to repetitive tasks.

Testable operations

Applying a series of commands automatically instead of doing it manually is important, but it’s not all. The commands themselves can also be tested. We can run our automation against staging servers and see the results. We can also automate some tests. For example, an Ansible task can make the whole playbook fail if mysqld is not running when it should.

Think declarative, think idempotent

Automation technologies are, in general, declarative. You describe what you want, you don’t write the steps to reach the goal. For example, you state that a certain directory should exist, and specify its owner, group, and mode, but you don’t write the system commands to make it happen. When you setup a new system, the two approaches are more or less equivalent. But when you modify an existing system, the declarative approach is incredibly simpler. You don’t have to check if the directory exists, who its owner is, and so on. Your code will be shorter, quicker to write, easier to understand.

Idempotent means that you can run the same code twice and obtain exactly the same result. This is very important. You can apply your code again to a production system to update something. You state that mysqld should be running? If it’s not, it will be started. If not, nothing will happen. This avoid a lot of problems.

Documenting operations

The code that describes your infrastructure also serves as a form of documentation. If you want to know the Xtrabackup version in your servers, Infrastructure As Code probably allows you to know it by just checking a variable. Even if it’s not so clear because your code is less than optimal, a tool like Ansible allows you to run xtrabackup --version against a group of servers with a simple command. Once you get used to this way of working, connecting to servers via SSH to check their configuration will appear as a waste of time.


Vettabase highly recommends having proper automation in place for your database infrastructure. We discussed the reasons that seem to us most important reasons.

  • Automation saves you plenty of time every day.
  • Automation is more reliable than humans.
  • Automation makes operations testable.
  • You describe your goal, not how to achieve it. You can safely apply your code twice.
  • The code serves as documentation.

Contact Vettabase

Vettabase can help you automating your database infrastructure: database configuration, replicas deployments, backups, and so on. See our Database Automation consulting services.

Federico Razzoli

Did you like this article?

Photo credit

All content in this blog is distributed under the CreativeCommons Attribution-ShareAlike 4.0 International license. You can use it for your needs and even modify it, but please refer to Vettabase and the author of the original post. Read more about the terms and conditions:

About Federico Razzoli
Federico Razzoli is a database professional, with a preference for open source databases, who has been working with DBMSs since year 2000. In the past 20+ years, he served in a number of companies as a DBA, Database Engineer, Database Consultant and Software Developer. In 2016, Federico summarized his extensive experience with MariaDB in the “Mastering MariaDB” book published by Packt. Being an experienced database events speaker, Federico speaks at professional conferences and meetups and conducts database trainings. He is also a supporter and advocate of open source software. As the Director of Vettabase, Federico does business worldwide but prefers to do it from Scotland where he lives.

Recent Posts

How to fix git mistakes

How to fix git mistakes

Code or configuration versioning comes with a potential problem: fixing mistakes can be tricky. Here are some solutions for the most common problems.

How to test database backups

How to test database backups

Testing backups is often considered too expensive. But it is not, if the tests are adequately designed.


Need Help?  Click Here for Expert Support


Submit a Comment

Your email address will not be published. Required fields are marked *