Infrastructure as Code: Automate the Deployment Process of Your Drupal Web App

Infrastructure as Code: Automate the Deployment Process of Your Drupal Web App

Let's face it: managing the infrastructure of a Drupal web app can get quite... cumbersome. So, why not think of it as... code? Infrastructure as code...

Why not automating all those tasks that go into the Drupal deployment workflow by applying proven coding techniques to the way you set up and organize your infrastructure?

Now, just think of the convenience of having a tool that would just turn APIs into declarative configuration files that your team could easily:

  • share
  • edit
  • version
  • review

An IaC tool that would automate all those tasks included in your workflow. One that usually calls for "joggling” with multiple environments and synchronizing code or configuration changes between them:

  • apply a specific modification on the development environment
  • export it to a file to be stored in version control
  • commit code/configuration changes to version control
  • synchronize that file to the live server

And so on...

What if we could leverage this infrastructure as code kind of approach to remove all manual work from the process?

What if the deployment of all code or config changes to your live Drupal app got... automated?

An automated sequence of repeatable, reliable processes...
 

1. The NEED: Disrupt Your Traditional Infrastructure Architecture Strategy

Why should your operations and infrastructure teams change the conventional way of managing Drupal projects' infrastructures?

Let's take this all too common scenario:

You need to develop multiple Drupal web apps for different clients. Therefore, you access AWS any time you start working on a new app project. The result? You end up with 2 Vms needed for running your application and its database. Then things start to get more and more tedious: you'll need (at least) 2 copies of your app's infrastructure for staging and production before you deploy the code for every single client.

And you'll go over all these processes and associated tasks all over again, with every new client that you build a Drupal web app for...

Now, here's managing and maintaining your infrastructure using the IaC approach:

You just run a bit of code and... you're good to go!

No manually handled system administration tasks. No overly complex scripts for running various IT operations.
 

2. What Is Infrastructure as Code More Precisely?

A succinct, yet comprehensive definition would be:

It's a framework that extends and applies the same coding principles directly to your infrastructure — virtual machines, networks, load balancers and so on. 

Think of managing your Drupal web app's infrastructure using a descriptive model. Of storing all your configuration scripts in source control and thus keeping a timely and accurate record of all code changes that various members of your team apply at some point.

“How's it any better than the traditional way of managing the infrastructure architecture?”

Let's see:

  • first of all, there is a lot of manual work involved in carrying out system administration tasks and configuration management operations the old way
  • secondly, the scripts written to automate various tasks are a better alternative to manual work, but they're far from perfect; they vary a lot, from one developer to another, they grow more and more complex as the system configuration itself scales up and they don't guarantee idempotence...

Note: “idempotence” is the principle that ensures the very same result, no matter how many times you might run a script.

Instead of relying on scripts for automating and standardizing every single task in your deployment process, by applying the infrastructure as code approach, you can use modules/functions for that.

You'd be blurring that strict borderline between your Drupal web app and its environment.
 

3. Let's Talk Benefits: Infrastructure as Code Benefits!

Let's talk facts!

How precisely does IaC help you manage and maintain your infrastructure more efficiently? How does it help you streamline the whole software delivery process?

Here are the top benefits of using this approach:
 

3.1. You get full control over the current state of your managed systems

With an idempotent configuration code in your source control repo, you get to manage the whole life cycle of your managed system through the very same scrips.
 

3.2. You cut down on operational costs

Just think about it:

By leveraging the infrastructure as code approach you get to configure and deploy a new IT infrastructure (fully tested and compliant) in no time. With close to zero human intervention!
 

3.3. You skip the tedious “write the docs” step

And that's because the code itself will automatically document the state of the machine. 

Not only that you don't need to write the docs, but you'll always have updated infrastructure documentation!
 

3.4. You can apply proven software development best practices 

… to manage your infrastructure, as well. 

From keeping the code in source control to testing it, to using peer reviews, you get to extend the same key practices from the development world to your IT operations.
 

3.5. Standardized Tasks Ensure Consistency

Since your new infrastructure's creation is coded, the set of instructions are standard and therefore... consistent.
 

3.6. Configuration changes are easier to track and safer to handle

Another benefit of the standardization level that you get when using infrastructure as code:

Since you'd be managing your infrastructure via source control, you'd get a detailed record of every change applied to code.

Now, if we are to sum up the infrastructure as code benefits now:

  • you deliver stable environments much quicker and more reliably (at scale)
  • your team skips all manual configuration work
  • IaC enforces standardization and consistency 
  • your team gets to leverage a unified set of tools and best practices
     

4. Implementing IaC in Drupal: Automate Your Deployment Process

“And how precisely can I leverage infrastructure as code to automate my Drupal deployment workflow?” you might ask yourself.

First, you'll need to pick your framework. Luckily, there are lots of good infrastructure as code tools out there for you to choose from (and the list is constantly growing).

Let's say that you will have opted for Ansible (or maybe Terraform?), since:

  • you get YAML syntax (that is conveniently easy to read)
  • it's agentless
  • it comes with a great ecosystem
  • it's easy to understand and therefore to maintain

And let's assume that you'd need to integrate the Ansible playbooks with your codebase. 

In this case, a Drupal-Ansible setup would:

  • ensure a consistent and repeatable Drupal deployment workflow
  • enable any developer in your team (with the right permissions assigned to) to run the script as many times as needed, with the very same results
  • allow you to spot the precise “culprit” right away when the build fails

Now, here are the necessary steps to take for making this setup work properly:

Divide your operational tasks into 2 main categories:

  1. those running the database updates using Drush
  2. those to be performed for setting up the system itself

The list of “set up” tasks would include:

  • creating a directory for database files to persist
  • … for storing file backups
  • … for storing database backups

While (some of) the tasks focused on set up and deployment would be:

  • cloning the correct code
  • importing config from files
  • clearing cache
  • creating .env file 

The END! 

What do you think now:

Does infrastructure as code stand the chance to become the default standard for automating Drupal deployments?